75 static int extractDate(
const char *tz,
struct tm *current,
char *s)
77 static const int startdays[] = {
78 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
80 static const int molengths[] = {
81 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
84 int month, week, weekday, hour=2;
85 int jan1wday, wday, mday;
89 printf(
"tz2timezone: Unsupported date type, need 'M' format\n");
94 if (sscanf(tz,
"%d.%d.%d/%d", &month, &week, &weekday, &hour) < 3)
97 if (month == 0 || month>12 ||
98 week < 1 || week > 5 ||
99 weekday < 0 || weekday > 6 ||
100 hour < 0 || hour > 23)
107 jan1wday = (7 + current->tm_wday - (current->tm_yday % 7)) % 7;
114 wday = (jan1wday + startdays[month-1] +
115 ((month > 2 && (current->tm_year % 4 == 0)) ? 1 : 0)) % 7;
119 mday = 1 + ((7 + weekday - wday) % 7);
123 mday += 7 * (week - 1);
124 if (mday > molengths[month-1])
130 sprintf(s,
"%02d%02d%02d", month, mday, hour);
136 static const char *getTime(
const char *s,
int *time)
142 if (!isdigit((
int) s[0]))
145 if (!isdigit((
int) s[1])) {
150 if (isdigit((
int) s[1])) {
151 *time = 10 * (s[0] -
'0') + (s[1] -
'0');
160 const char *tz = getenv(
"TZ");
167 char start[10], stop[10];
168 int hours = 0, minutes = 0, sign = 1;
187 if ((!tz) || (strlen(tz) < 3))
196 while ((i <
sizeof(zone) - 1) && isalpha((
int) *tz)) {
211 else if (*tz ==
'+') {
216 if (!isdigit((
int) *tz))
220 tz = getTime(tz, &hours);
226 if (!isdigit((
int) *++tz))
230 tz = getTime(tz, &minutes);
237 tz = getTime(tz + 1, &seconds);
242 if (isalpha((
int) *tz)) {
245 while ((i <
sizeof(zone) - 1) && isalpha((
int) *tz)) {
251 minutes += hours * 60;
255 tz = strchr(tz,
',');
258 sprintf(timezone,
"TIMEZONE=%s::%d", zone, minutes);
261 if (extractDate(tz, ¤t, start) != OK)
264 tz = strchr(tz + 1,
',');
267 if (extractDate(tz, ¤t, stop) != OK)
271 sprintf(timezone,
"TIMEZONE=%s::%d:%s:%s", zone, minutes, start, stop);
int epicsStdCall epicsTimeGetCurrent(epicsTimeStamp *pDest)
Get current time into *pDest.
EPICS time stamp, for use from C code.
EPICS time-stamps (epicsTimeStamp), epicsTime C++ class and C functions for handling wall-clock times...
LIBCOM_API int epicsStdCall epicsTimeToTM(struct tm *pDest, unsigned long *pNSecDest, const epicsTimeStamp *pSrc)
Convert epicsTimeStamp to struct tm in local time zone.