Example #1
0
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);
}
Example #2
0
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);
}
Example #3
0
int main(void)
{
	timelib_sll res;
	timelib_time time;

	time = timelib_strtotime("10 Feb 2005 06:07:03 PM CET"); /* 1108055223 */
	printf ("%04d-%02d-%02d %02d:%02d:%02d.%-5d %+04d %1d",
		time.y, time.m, time.d, time.h, time.i, time.s, time.f, time.z, time.dst);
	if (time.have_relative) {
		printf ("%3dY %3dM %3dD / %3dH %3dM %3dS", 
			time.relative.y, time.relative.m, time.relative.d, time.relative.h, time.relative.i, time.relative.s);
	}
	if (time.have_weekday_relative) {
		printf (" / %d", time.relative.weekday);
	}
	res = time2unixtime(&time);
	printf("%Ld\n", res);

	return 0;
}
Example #4
0
bool DateInterval::setDateString(CStrRef date_string) {
  timelib_time *time;
  timelib_rel_time *di;
  timelib_error_container *errors = NULL;

  time = timelib_strtotime((char*)date_string.data(), date_string.size(),
                           &errors, TimeZone::GetDatabase());
  int error_count = errors->error_count;
  DateTime::setLastErrors(errors);

  if (error_count > 0) {
    timelib_time_dtor(time);
    return false;
  } else {
    di = timelib_rel_time_clone(&(time->relative));
    timelib_time_dtor(time);
    m_di = DateIntervalPtr(di, dateinterval_deleter());
    return true;
  }
}
Example #5
0
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;
}
Example #6
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);
}