MCPcopy Create free account
hub / github.com/eggert/tz / time2sub

Function time2sub

localtime.c:2588–2819  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2586}
2587
2588static time_t
2589time2sub(struct tm *const tmp,
2590 struct tm *funcp(struct state const *, time_t const *,
2591 int_fast32_t, struct tm *),
2592 struct state const *sp,
2593 const int_fast32_t offset,
2594 bool *okayp,
2595 bool do_norm_secs)
2596{
2597 register int dir;
2598 register int i, j;
2599 register time_t lo;
2600 register time_t hi;
2601 iinntt y, mday, hour, min, saved_seconds;
2602 time_t newt;
2603 time_t t;
2604 struct tm yourtm, mytm;
2605
2606 *okayp = false;
2607 mktmcpy(&yourtm, tmp);
2608
2609 min = yourtm.tm_min;
2610 if (do_norm_secs) {
2611 min += yourtm.tm_sec / SECSPERMIN;
2612 yourtm.tm_sec %= SECSPERMIN;
2613 if (yourtm.tm_sec < 0) {
2614 yourtm.tm_sec += SECSPERMIN;
2615 min--;
2616 }
2617 }
2618
2619 hour = yourtm.tm_hour;
2620 hour += min / MINSPERHOUR;
2621 yourtm.tm_min = min % MINSPERHOUR;
2622 if (yourtm.tm_min < 0) {
2623 yourtm.tm_min += MINSPERHOUR;
2624 hour--;
2625 }
2626
2627 mday = yourtm.tm_mday;
2628 mday += hour / HOURSPERDAY;
2629 yourtm.tm_hour = hour % HOURSPERDAY;
2630 if (yourtm.tm_hour < 0) {
2631 yourtm.tm_hour += HOURSPERDAY;
2632 mday--;
2633 }
2634
2635 y = yourtm.tm_year;
2636 y += yourtm.tm_mon / MONSPERYEAR;
2637 yourtm.tm_mon %= MONSPERYEAR;
2638 if (yourtm.tm_mon < 0) {
2639 yourtm.tm_mon += MONSPERYEAR;
2640 y--;
2641 }
2642
2643 /*
2644 ** Turn y into an actual year number for now.
2645 ** It is converted back to an offset from TM_YEAR_BASE later.

Callers 1

time2Function · 0.85

Calls 6

mktmcpyFunction · 0.85
tmcompFunction · 0.85
utoff_diffFunction · 0.85
ttunspecifiedFunction · 0.85

Tested by

no test coverage detected