98 u32 year, month, hours, minutes, seconds, nanoseconds;
99 u32 days_in_year, days_in_month, day_of_month;
100 u32 days_since_epoch;
106 days_since_epoch = 0;
111 days_since_epoch += days_in_year;
112 now = now - ((
f64) days_in_year) * 86400.0;
117 days_since_epoch -= days_in_year;
118 now += ((
f64) days_in_year) * 86400;
129 days_since_epoch += days_in_month;
130 now = now - ((
f64) days_in_month) * 86400.0;
135 days_since_epoch -= days_in_month;
136 now += ((
f64) days_in_month) * 86400;
152 day_name_index = days_since_epoch % 7;
154 hours = (
u32) (now / (3600.0));
155 now -= (
f64) (hours * 3600);
157 minutes = (
u32) (now / 60.0);
158 now -= (
f64) (minutes * 60);
160 seconds = (
u32) (now);
161 now -= (
f64) (seconds);
163 nanoseconds = (
f64) (now * 1e9);
167 cp->
day = day_of_month;
180 u32 year, days_in_year, month, days_in_month;
184 while (year < cp->year)
187 now += ((
f64) days_in_year) * 86400.0;
193 while (month < cp->month)
199 now += ((
f64) days_in_month) * 86400.0;
203 now += ((
f64) cp->
day - 1) * 86400.0;
204 now += ((
f64) cp->
hour) * 3600.0;
227 start_time -= 86400.0;
245 return ((
f64)
i) * 86400.0;
254 f64 now = va_arg (*args,
f64);
259 s =
format (s,
"%s, %u %s %u %u:%02u:%02u",
272 u32 start_hour, start_minute, start_second;
273 u32 end_hour, end_minute, end_second;
275 start_hour = start_minute = start_second
276 = end_hour = end_minute = end_second = 0;
278 if (
unformat (input,
"%u:%u:%u - %u:%u:%u",
279 &start_hour, &start_minute, &start_second,
280 &end_hour, &end_minute, &end_second))
282 else if (
unformat (input,
"%u:%u - %u:%u",
283 &start_hour, &start_minute, &end_hour, &end_minute))
285 else if (
unformat (input,
"%u - %u", &start_hour, &end_hour))
292 cp->
hour = start_hour;
293 cp->
minute = start_minute;
294 cp->
second = start_second;
313 int day_range_match = 0;
314 int time_range_match = 0;
315 f64 range_start_time_offset;
316 f64 range_end_time_offset;
318 u8 *start_day = 0, *end_day = 0;
325 &&
unformat (input,
"%s - %s", &start_day, &end_day))
327 range_start_time_offset
333 time_range_match = 0;
335 else if (!day_range_match &&
unformat (input,
"%s", &start_day))
337 range_start_time_offset
339 range_end_time_offset = range_start_time_offset + 86399.0;
343 time_range_match = 0;
345 else if (day_range_match &&
349 for (now = range_start_time_offset; now <= range_end_time_offset;
354 new_rp->
end = now + tmp->
end;
357 time_range_match = 1;
359 else if (time_range_match)
369 if (time_range_match)
386 f64 second_sunday_march_2am;
387 f64 first_sunday_november_2am;
429 second_sunday_march_2am += 86400.0;
437 second_sunday_march_2am += 86400.0;
441 second_sunday_march_2am -= 86400.0;
454 first_sunday_november_2am += 86400.0;
uword unformat_clib_timebase_range_vector(unformat_input_t *input, va_list *args)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
clib_timebase_daylight_time_t
f64 clib_timebase_offset_from_sunday(u8 *day)
f64 clib_timebase_components_to_time(clib_timebase_component_t *cp)
static f64 unix_time_now(void)
void clib_timebase_time_to_components(f64 now, clib_timebase_component_t *cp)
clib_timebase_daylight_time_t daylight_time_type
static const char * day_names_calendar_order[]
u8 * format_clib_timebase_time(u8 *s, va_list *args)
void clib_time_init(clib_time_t *c)
static const char * month_short_names[]
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
f64 clib_timebase_find_sunday_midnight(f64 start_time)
void clib_timebase_init(clib_timebase_t *tb, i32 timezone_offset_in_hours, clib_timebase_daylight_time_t daylight_type)
uword unformat_clib_timebase_range_hms(unformat_input_t *input, va_list *args)
static int clib_timebase_is_leap_year(u32 year)
static const char * day_names_epoch_order[]
static const u32 days_per_month[]
f64 clib_timebase_summer_offset(clib_timebase_t *tb, f64 now)