コード例 #1
0
ファイル: tm2unixtime.c プロジェクト: ArPharazon/hiphop-php
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
ファイル: timezone.cpp プロジェクト: Debug-Orz/hhvm
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
ファイル: timezone.cpp プロジェクト: Debug-Orz/hhvm
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
ファイル: timestamp.cpp プロジェクト: facebook/hhvm
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
ファイル: timestamp.cpp プロジェクト: beride/hiphop-php
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;
}
コード例 #9
0
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
ファイル: microtime.c プロジェクト: browniebraun/php-src
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);
	}
}