TEST(issues, issue0051_test2) { char str1[] = "2018-11-22 13:27:52"; char str2[] = "2018-11-22 13:27:52.089635"; timelib_time *t1 = timelib_strtotime(str1, sizeof(str1), NULL, timelib_builtin_db(), timelib_parse_tzfile); timelib_time *t2 = timelib_strtotime(str2, sizeof(str2), NULL, timelib_builtin_db(), timelib_parse_tzfile); int dummy_error; timelib_tzinfo *tzi; timelib_rel_time *diff; tzi = timelib_parse_tzfile((char*) "UTC", timelib_builtin_db(), &dummy_error); timelib_update_ts(t1, tzi); timelib_update_ts(t2, tzi); diff = timelib_diff(t1, t2); LONGS_EQUAL(0, diff->s); LONGS_EQUAL(89635, diff->us); LONGS_EQUAL(0, diff->invert); timelib_time_dtor(t1); timelib_time_dtor(t2); timelib_rel_time_dtor(diff); timelib_tzinfo_dtor(tzi); }
timelib_tzinfo* TimeZone::GetTimeZoneInfoRaw(char* name, const timelib_tzdb* db) { auto const it = s_tzCache->find(name); if (it != s_tzCache->end()) { return it->second; } auto tzi = timelib_parse_tzfile(name, db); if (!tzi) { char* tzid = timelib_timezone_id_from_abbr(name, -1, 0); if (tzid) { tzi = timelib_parse_tzfile(tzid, db); } } if (tzi) { auto key = strdup(name); auto result = s_tzCache->insert(TimeZoneCacheEntry(key, tzi)); if (!result.second) { // The cache should never fill up since tzinfos are finite. always_assert(result.first != s_tzCache->end()); // A collision occurred, so we don't need our strdup'ed key. free(key); timelib_tzinfo_dtor(tzi); tzi = result.first->second; } } return tzi; }
TEST(issues, issue0050_test2) { char str1[] = "2018-10-11 20:59:06.237419"; char str2[] = "2018-10-11 20:59:06.914653"; timelib_time *t1 = timelib_strtotime(str1, sizeof(str1), NULL, timelib_builtin_db(), timelib_parse_tzfile); timelib_time *t2 = timelib_strtotime(str2, sizeof(str2), NULL, timelib_builtin_db(), timelib_parse_tzfile); int dummy_error; timelib_tzinfo *tzi; timelib_rel_time *diff; tzi = timelib_parse_tzfile((char*) "UTC", timelib_builtin_db(), &dummy_error); timelib_update_ts(t1, tzi); timelib_update_ts(t2, tzi); diff = timelib_diff(t1, t2); LONGS_EQUAL(0, diff->s); LONGS_EQUAL(677234, diff->us); timelib_time_dtor(t1); timelib_time_dtor(t2); timelib_rel_time_dtor(diff); timelib_tzinfo_dtor(tzi); }
/* Test for no transitions */ TEST(issues, issue0065_test1) { int dummy_error; timelib_tzinfo *tzi; timelib_time_offset *offset; tzi = timelib_parse_tzfile((char*) "Etc/Gmt+5", timelib_builtin_db(), &dummy_error); offset = timelib_get_time_zone_info(-1822500432, tzi); LONGS_EQUAL(INT64_MIN, offset->transition_time); timelib_time_offset_dtor(offset); timelib_tzinfo_dtor(tzi); }
TEST(issues, issue0053_test3) { int dummy_error; timelib_tzinfo *tzi; timelib_sll ts = -1822500432; timelib_time *t = timelib_time_ctor(); tzi = timelib_parse_tzfile((char*) "America/Belize", timelib_builtin_db(), &dummy_error); t->tz_info = tzi; t->zone_type = TIMELIB_ZONETYPE_ID; timelib_unixtime2local(t, ts); LONGS_EQUAL(-21600, t->z); timelib_time_dtor(t); timelib_tzinfo_dtor(tzi); }
/* Test for offset from time before first transition */ TEST(issues, issue0065_test2) { int dummy_error; timelib_tzinfo *tzi; timelib_time_offset *offset; tzi = timelib_parse_tzfile((char*) "Europe/London", timelib_builtin_db(), &dummy_error); offset = timelib_get_time_zone_info(-3852662326, tzi); LONGS_EQUAL(INT64_MIN, offset->transition_time); timelib_time_offset_dtor(offset); offset = timelib_get_time_zone_info(-3852662325, tzi); LONGS_EQUAL(-3852662325, offset->transition_time); timelib_time_offset_dtor(offset); timelib_tzinfo_dtor(tzi); }
int main(int argc, char *argv[]) { timelib_time *t; timelib_sll rise, set, transit; int rs, h, m, s; double h_rise, h_set; if (argc != 4) { printf("Usage: ./test-astro time longitude latitude\n ./test-astro \"2005-10-17 00:00:00\" 9.627 59.186\n"); return -1; } t = timelib_strtotime(argv[1] /*"2005-10-17 00:00:00"*/, strlen(argv[1]), NULL, timelib_builtin_db(), timelib_parse_tzfile); timelib_dump_date(t, 1); rs = timelib_astro_rise_set_altitude(t, atof(argv[2]) /*9.627*/, atof(argv[3]) /*59.186*/, 0, 0, &h_rise, &h_set, &rise, &set, &transit); switch (rs) { case 0: break; case +1: printf( "Sun always above horizon\n"); break; case -1: printf( "Sun always below horizon\n"); break; } timelib_unixtime2local(t, rise); timelib_dump_date(t, 1); timelib_decimal_hour_to_hms(h_rise, &h, &m, &s); timelib_unixtime2local(t, set); timelib_dump_date(t, 1); timelib_decimal_hour_to_hms(h_set, &h, &m, &s); if (t->tz_info) { timelib_tzinfo_dtor(t->tz_info); } timelib_time_dtor(t); return 0; }
TEST(issues, issue0035_test2) { int dummy_error; timelib_tzinfo *tzi; char str[] = "2017-12-31 23:59:59.999999 +2 microsecond"; timelib_time *t = timelib_strtotime(str, sizeof(str), NULL, timelib_builtin_db(), timelib_parse_tzfile); tzi = timelib_parse_tzfile((char*) "UTC", timelib_builtin_db(), &dummy_error); timelib_update_ts(t, tzi); LONGS_EQUAL(2018, t->y); LONGS_EQUAL(1, t->m); LONGS_EQUAL(1, t->d); LONGS_EQUAL(0, t->h); LONGS_EQUAL(0, t->i); LONGS_EQUAL(0, t->s); LONGS_EQUAL(1, t->us); timelib_time_dtor(t); timelib_tzinfo_dtor(tzi); }
TEST(issues, issue0053_test1) { int dummy_error; timelib_tzinfo *tzi; timelib_sll ts = -61626506832; timelib_time *t = timelib_time_ctor(); tzi = timelib_parse_tzfile((char*) "America/Belize", timelib_builtin_db(), &dummy_error); t->tz_info = tzi; t->zone_type = TIMELIB_ZONETYPE_ID; timelib_unixtime2local(t, ts); LONGS_EQUAL(17, t->y); LONGS_EQUAL(2, t->m); LONGS_EQUAL(18, t->d); LONGS_EQUAL(0, t->h); LONGS_EQUAL(0, t->i); LONGS_EQUAL(0, t->s); LONGS_EQUAL(-21168, t->z); timelib_time_dtor(t); timelib_tzinfo_dtor(tzi); }