time64 gnc_mktime (struct tm* time) { GDateTime *gdt; time64 secs; normalize_struct_tm (time); gdt = gnc_g_date_time_new_local (time->tm_year + 1900, time->tm_mon, time->tm_mday, time->tm_hour, time->tm_min, (gdouble)(time->tm_sec)); if (gdt == NULL) { g_warning("Invalid time passed to gnc_mktime"); return -1; } time->tm_mon = time->tm_mon > 0 ? time->tm_mon - 1 : 11; // Watch out: struct tm has wday=0..6 with Sunday=0, but GDateTime has wday=1..7 with Sunday=7. time->tm_wday = g_date_time_get_day_of_week (gdt) % 7; time->tm_yday = g_date_time_get_day_of_year (gdt); time->tm_isdst = g_date_time_is_daylight_savings (gdt); #ifdef HAVE_STRUCT_TM_GMTOFF time->tm_gmtoff = g_date_time_get_utc_offset (gdt) / G_TIME_SPAN_SECOND; #endif secs = g_date_time_to_unix (gdt); g_date_time_unref (gdt); return secs; }
time64 gnc_timegm (struct tm* time) { try { normalize_struct_tm(time); GncDateTime gncdt(*time); *time = static_cast<struct tm>(gncdt); time->tm_sec -= gncdt.offset(); normalize_struct_tm(time); #ifdef HAVE_STRUcT_TM_GMTOFF time->tm_gmtoff = 0; #endif return static_cast<time64>(gncdt) - gncdt.offset(); } catch(std::invalid_argument) { return 0; } }
time64 gnc_timegm (struct tm* time) { try { normalize_struct_tm(time); return static_cast<time64>(GncDateTime(*time)); } catch(std::invalid_argument) { return 0; } }
time64 gnc_mktime (struct tm* time) { try { normalize_struct_tm (time); GncDateTime gncdt(*time); return static_cast<time64>(gncdt) - gncdt.offset(); } catch(std::invalid_argument) { return 0; } }
time64 gnc_timegm (struct tm* time) { GDateTime *gdt; time64 secs; normalize_struct_tm (time); gdt = g_date_time_new_utc (time->tm_year + 1900, time->tm_mon, time->tm_mday, time->tm_hour, time->tm_min, (gdouble)(time->tm_sec)); time->tm_mon = time->tm_mon > 0 ? time->tm_mon - 1 : 11; // Watch out: struct tm has wday=0..6 with Sunday=0, but GDateTime has wday=1..7 with Sunday=7. time->tm_wday = g_date_time_get_day_of_week (gdt) % 7; time->tm_yday = g_date_time_get_day_of_year (gdt); time->tm_isdst = g_date_time_is_daylight_savings (gdt); secs = g_date_time_to_unix (gdt); g_date_time_unref (gdt); return secs; }