示例#1
0
static timelib_sll do_adjust_timezone(timelib_time *tz, timelib_tzinfo *tzi)
{
	switch (tz->zone_type) {
		case TIMELIB_ZONETYPE_OFFSET:

			tz->is_localtime = 1;
			return tz->z * 60;
			break;

		case TIMELIB_ZONETYPE_ABBR: {
			timelib_sll tmp;

			tz->is_localtime = 1;
			tmp = tz->z;
			tmp -= tz->dst * 60;
			tmp *= 60;
			return tmp;
			}
			break;

		case TIMELIB_ZONETYPE_ID:
			tzi = tz->tz_info;
			/* Break intentionally missing */

		default:
			/* No timezone in struct, fallback to reference if possible */
			if (tzi) {
				timelib_time_offset *before, *after;
				timelib_sll          tmp;
				int                  in_transistion;
				
				tz->is_localtime = 1;
				before = timelib_get_time_zone_info(tz->sse, tzi);
				after = timelib_get_time_zone_info(tz->sse - before->offset, tzi);
				timelib_set_timezone(tz, tzi);

				in_transistion = (
					((tz->sse - after->offset) >= (after->transistion_time + (before->offset - after->offset))) &&
					((tz->sse - after->offset) < after->transistion_time)
				);
				
				if ((before->offset != after->offset) && !in_transistion) {
					tmp = -after->offset;
				} else {
					tmp = -tz->z;
				}
				timelib_time_offset_dtor(before);
				timelib_time_offset_dtor(after);
				
				return tmp;
			}
	}
	return 0;
}
示例#2
0
bool TimeZone::dst(int64_t timestamp) const {
  if (!m_tzi) return false;

  timelib_time_offset *offset =
    timelib_get_time_zone_info(timestamp, m_tzi);
  bool ret = offset->is_dst;
  timelib_time_offset_dtor(offset);
  return ret;
}
示例#3
0
int TimeZone::offset(int64_t timestamp) const {
  if (!m_tzi) return 0;

  timelib_time_offset *offset =
    timelib_get_time_zone_info(timestamp, m_tzi);
  int ret = offset->offset;
  timelib_time_offset_dtor(offset);
  return ret;
}
示例#4
0
文件: issues.cpp 项目: cmb69/timelib
/* 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);
}
示例#5
0
文件: issues.cpp 项目: cmb69/timelib
/* 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);
}
示例#6
0
文件: timestamp.cpp 项目: 1mr3yn/hhvm
Array TimeStamp::CurrentTime() {
  struct timeval tp;
  gettimeofday(&tp, nullptr);

  timelib_time_offset *offset =
    timelib_get_time_zone_info(tp.tv_sec, TimeZone::Current()->get());

  ArrayInit ret(4);
  ret.set(s_sec, (int)tp.tv_sec);
  ret.set(s_usec, (int)tp.tv_usec);
  ret.set(s_minuteswest, (int)(-offset->offset / 60));
  ret.set(s_dsttime, (int)offset->is_dst);

  timelib_time_offset_dtor(offset);
  return ret.create();
}
示例#7
0
Array TimeStamp::CurrentTime() {
  struct timeval tp;
  gettimeofday(&tp, nullptr);

  timelib_time_offset *offset =
    timelib_get_time_zone_info(tp.tv_sec, TimeZone::Current()->getTZInfo());

  auto const ret = make_map_array(
    s_sec, (int)tp.tv_sec,
    s_usec, (int)tp.tv_usec,
    s_minuteswest, (int)(-offset->offset / 60),
    s_dsttime, (int)offset->is_dst
  );
  timelib_time_offset_dtor(offset);
  return ret;
}
示例#8
0
Array TimeStamp::CurrentTime() {
  struct timeval tp;
  gettimeofday(&tp, nullptr);

  timelib_time_offset *offset =
    timelib_get_time_zone_info(tp.tv_sec, TimeZone::Current()->get());

  Array ret;
  ret.set("sec", (int)tp.tv_sec);
  ret.set("usec", (int)tp.tv_usec);
  ret.set("minuteswest", (int)(-offset->offset / 60));
  ret.set("dsttime", (int)offset->is_dst);

  timelib_time_offset_dtor(offset);
  return ret;
}
timelib_sll timelib_get_current_offset(timelib_time *t)
{
	timelib_time_offset *gmt_offset;
	timelib_sll retval;

	switch (t->zone_type) {
		case TIMELIB_ZONETYPE_ABBR:
		case TIMELIB_ZONETYPE_OFFSET:
			return (t->z + t->dst) * -60;

		case TIMELIB_ZONETYPE_ID:
			gmt_offset = timelib_get_time_zone_info(t->sse, t->tz_info);
			retval = gmt_offset->offset;
			timelib_time_offset_dtor(gmt_offset);
			return retval;

		default:
			return 0;
	}
}
示例#10
0
static void _php_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
{
	zend_bool get_as_float = 0;
	struct timeval tp = {0};
	struct timezone tz = {0};

	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &get_as_float) == FAILURE) {
		return;
	}

	if (gettimeofday(&tp, &tz)) {
		RETURN_FALSE;
	}

	if (get_as_float) {
		RETURN_DOUBLE((double)(tp.tv_sec + tp.tv_usec / MICRO_IN_SEC));
	}

	if (mode) {
		timelib_time_offset *offset;

		offset = timelib_get_time_zone_info(tp.tv_sec, get_timezone_info(TSRMLS_C));
				
		array_init(return_value);
		add_ascii_assoc_long(return_value, "sec", tp.tv_sec);
		add_ascii_assoc_long(return_value, "usec", tp.tv_usec);

		add_ascii_assoc_long(return_value, "minuteswest", -offset->offset / SEC_IN_MIN);
		add_ascii_assoc_long(return_value, "dsttime", offset->is_dst);

		timelib_time_offset_dtor(offset);
	} else {
		char ret[100];

		snprintf(ret, 100, "%.8F %ld", tp.tv_usec / MICRO_IN_SEC, tp.tv_sec);
		RETURN_ASCII_STRING(ret, ZSTR_DUPLICATE);
	}
}