Exemplo n.º 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);
}
Exemplo n.º 2
0
bool DateInterval::setInterval(const String& date_interval) {
  timelib_rel_time *di = nullptr;
  timelib_error_container *errors = nullptr;

#ifdef TIMELIB_HAVE_INTERVAL
  timelib_time *start = nullptr, *end = nullptr;
  int r = 0;

  timelib_strtointerval((char*)date_interval.data(), date_interval.size(),
                        &start, &end, &di, &r, &errors);
#else
  throw_not_implemented("timelib too old");
#endif

  int error_count  = errors->error_count;
  DateTime::setLastErrors(errors);
  if (error_count > 0) {
    timelib_rel_time_dtor(di);
    return false;
  } else {
#ifdef TIMELIB_HAVE_INTERVAL
    if (UNLIKELY(!di && start && end)) {
      timelib_update_ts(start, nullptr);
      timelib_update_ts(end, nullptr);
      di = timelib_diff(start, end);
    }
#endif
    m_di = DateIntervalPtr(di, dateinterval_deleter());
    return true;
  }
}
Exemplo n.º 3
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);
}