61 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
70 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
78 const char *
__WDay[] = {
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"BAD"};
102 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul", \
103 "Aug",
"Sep",
"Oct",
"Nov",
"Dec",
"BAD" 116 if(i >= 0 && i <= 11)
137 if((year & 3) || year == 1900 || year == 2100)
189 value = ( year + year/4 - year/100 + year/400 );
190 value += ( 6 * (month+1) / 10 + (month * 2));
213 return(
IS_Leap(year) ? 366 : 365);
239 if( month == 1 &&
IS_Leap(year))
269 memset(t,0,
sizeof(
tm_t));
271 if(epoch >= 0xFFFD5D00UL)
276 if(epoch >= 0xFFFEAE80UL)
278 epoch -= 0xFFFEAE80UL;
316 while(days > 0 && month < 12)
319 if( month == 1 &&
IS_Leap(year))
330 return(save - offset);
373 snprintf(buf,32,
"%s %s %2d %02d:%02d:%02d %4d",
508 if(
is_dst(epoch - offset))
564 printf(
"tm2epoch %4d,%2d,%2d, %02d:%02d:%02d\n",
569 if (year < EPOCH_YEAR || year > 2106)
572 printf(
"tm2epoch year out of range: %4d\n", year);
577 if(mon >= 12 || mon < 0)
580 printf(
"tm2epoch mon out of range: %4d\n", mon);
588 printf(
"tm2epoch mday out of range: %4d\n", mday);
593 if(hour >= 24 || hour < 0)
596 printf(
"tm2epoch hour out of range: %4d\n", hour);
601 if(min >= 60|| min < 0)
604 printf(
"tm2epoch min out of range: %4d\n", min);
609 if(sec >= 60 || sec < 0)
612 printf(
"tm2epoch sec out of range: %4d\n", sec);
753 printf(
"%10lu - epoch-1\n",epoch);
758 if(normalize_to_timezone)
771 printf(
"%10lu - epoch-2\n",epoch);
780 printf(
"%10lu - epoch-3\n",epoch);
906 printf(
"Enter date YYYY MM DD HH:MM:SS >");
928 sscanf(buf,
"%d %d %d %d:%d:%d",
957 if(*buf && (*buf ==
' ' || *buf ==
':'))
962 if(*buf && (*buf ==
' ' || *buf ==
':'))
1006 printf(
"rtc force init failed\n");
1055 offset -= (60UL * 60UL);
1086 dst_epoch += offset;
1096 if( ((t.
tm_wday + days) % 7) == dayno)
1098 if( (--weekno) == 0)
1102 dst_epoch += 86400
L;
1125 if(dst.
epoch >= epoch)
1127 if((dst.
epoch - epoch) < 86400
L)
1132 if((epoch - dst.
epoch) < 86400
L)
1151 if( epoch >= dst.
start && epoch <= dst.
end)
1188 printf(
"rtc uninitilized\n");
1189 printf(
"attempting rtc init\n");
1192 printf(
"rtc force init failed\n");
1203 printf(
"rtc read errorafter init\n");
1208 #endif // RTC_SUPPORT 1210 printf(
"use setdate command to change time\n");
1237 printf(
"rtc seconds: %lu\n",seconds);
1240 printf(
"rtc_read:%d, day:%d,mon:%d,hour:%d,min:%d,sec:%d, wday:%d\n",
1252 printf(
"RTC read failed\n");
1254 #endif // RTC_SUPPORT 1258 printf(
"clk seconds: %lu\n",seconds);
MEMSPACE void display_clock()
Display system time and optionally RTC time.
tz_t __tzone
System Time Zone.
dst_t dst
DST start and stop in GMT epoch.
MEMSPACE char * asctime_r(tm_t *t, char *buf)
Convert tm_t *t structure into POSIX asctime() ASCII string *buf.
MEMSPACE int is_dst(time_t epoch)
Test GMT epoch time to see if DST applies in a local timezone.
MEMSPACE void initialize_clock(int minwest)
initialize system time - if we have an RTC use it
MEMSPACE time_t mktime(tm_t *t)
convert tm_t structure to time_t local time epoch
MEMSPACE time_t normalize(tm_t *t, int normalize_to_timezone)
Normalize POSIX tm_t *t struct and convert to epoch time Note: does not deal with DST - by design...
Master include file for project Includes all project includes and defines here.
Common Linux/POSIX time functions.
MEMSPACE uint8_t rtc_read(tm_t *t)
Read DS1307 RTC into POSIX struct tm * structure.
MEMSPACE void set_dst(time_t epoch)
Set DST start and end time for the given epoch year.
static MEMSPACE int Days_Per_Year(int year)
Find number of days in a given year.
static MEMSPACE int IS_Leap(int year)
Check if a year is a leap year.
MEMSPACE char * fgets(char *str, int size, FILE *stream)
get a string from stdin See fdevopen() sets stream->put get for TTY devices
MEMSPACE int finddayofweek(int year, int month, int day)
return day of week for givenn day, month, year
MEMSPACE int setdate_r(char *buf)
Set date and time from string in this format "YYYY MM DD HH:MM:SS".
MEMSPACE char * tm_mon_to_ascii(int i)
Get string Short name of Month from month number.
MEMSPACE void print_dst_gmt()
print start/stop for DST as GMT for this year
time_t end
Start of local DST in GMT.
MEMSPACE time_t timegm(tm_t *t)
Convert tm_t structure as GMT time into GMT seconds since 1900. All calculactions are in GMT regardle...
#define snprintf(s, size, format, args...)
MEMSPACE time_t time(time_t *t)
Return second from epoch - POSIX function.
volatile ts_t __clock
System Clock Time.
const char * __WDay[]
Short Name of each Day in a week.
MEMSPACE int Days_Per_Month(int month, int year)
days in a month
uint32_t time_t
type of EPOCH result.
MEMSPACE int clock_settime(clockid_t clk_id, const struct timespec *ts)
Set system clock using seconds and nonoseconds - POSIX function.
MEMSPACE uint16_t sum(char *name)
sum of a file with 16bit hex and integer results
MEMSPACE char * ctime_gm(time_t *tp)
GMT version of POSIX ctime().
MEMSPACE tm_t * localtime(time_t *tp)
Convert POSIX epoch time_t *tp into POSIX tm_t *result.
MEMSPACE uint8_t rtc_init(int force, time_t seconds)
Initialize DS1307 rtc if not initialied - or if forced.
time_t epoch
End of local DST in GMT.
MEMSPACE int gettimezone(tz_t *tz)
Get current timezone in struct timezone *tz - POSIX function.
MEMSPACE char * asctime(tm_t *t)
Convert tm_t *t structure into POSIX asctime() ASCII string.
Math IO functions, and verious conversion code with floating point support.
MEMSPACE tm_t * gmtime(time_t *tp)
Convert epoch GMT time_t *tp into POSIX static tm_t *t.
MEMSPACE void print_dst()
print start/stop for DST as localtime for this year
MEMSPACE long strtol(const char *nptr, char **endptr, int base)
Convert ASCII string to number in a given base.
static MEMSPACE time_t tm2epoch(tm_t *t)
Converts tm_t structure as GMT time into GMT epoch since 1900.
#define stdin
define stdin, stdout and stderr
MEMSPACE int settimezone(tz_t *tz)
Set current timezone with struct timezone *tz - POSIX function.
MEMSPACE int setdate(void)
Set date and time by prompting user.
int sscanf(const char *strp, const char *fmt,...)
MEMSPACE char * ctime_r(time_t *t, char *buf)
Convert local time_t *t epoch time into POSIX asctime() ASCII string *buf.
MEMSPACE tm_t * gmtime_r(time_t *t, tm_t *result)
Convert epoch GMT time_t *tp into POSIX tm_t *result.
MEMSPACE int gettimeofday(tv_t *tv, tz_t *tz)
Get current time struct timeval *tv and struct timezone *tz - POSIX function. We assume a GMT hardwar...
MEMSPACE time_t find_dst(int dst, time_t epoch, int year, int month, int weekno, int dayno, int hour)
Calculate GMT seconds of DST transition given LOCAL time start / end time and DST flag...
MEMSPACE int printf(const char *format,...)
const char * __Month[]
Short Name or each Month in a year.
MEMSPACE tm_t * localtime_r(time_t *t, tm_t *result)
Convert POSIX epoch time_t *tp into POSIX tm_t *result expressed as local time using timezone and DST...
MEMSPACE int settimeofday(tv_t *tv, tz_t *tz)
Set current time struct timeval *tv and struct timezone *tz - POSIX function. We assume a GMT hardwar...
MEMSPACE char * ctime(time_t *tp)
Convert local time_t *t epoch time into POSIX asctime() string buf[].
MEMSPACE time_t time_to_tm(time_t epoch, int32_t offset, tm_t *t)
Converts epoch ( seconds from 1 Jan EPOCH_YEAR UTC), offset seconds, to UNIX tm *t.
static const uint16_t __days[]
days in each month.
static const uint16_t __days_sum[]
accumulated days to the start of a month in a year.
MEMSPACE void clock_set(uint32_t seconds, uint32_t us)
Set system clock with seconds and microseconds.
MEMSPACE char * tm_wday_to_ascii(int i)
Get string Short name of day from day number.
MEMSPACE int clock_gettime(clockid_t clk_id, struct timespec *ts)
Generic clock_gettime() function WITHOUT high resolution.
static MEMSPACE int Leap_Days_Since_1900(int year)
Number of leap days since 1900 to the BEGINNING of the year.