9edc07112b
When object support was first added to HHVM, a class named "Instance" was introduced (deriving from ObjectData) to represent instances of user defined classes. Since then, things have evolved and HPHPc and HPHPi have been retired, and now there really is no needed to have ObjectData and Instance be separate classes anymore. As a first step towards merging ObjectData and Instance together, this diff puts their definitions in the same .h file and puts their implementations in the same .cpp file. A few small changes were necessary to fix issues with cyclical includes: (1) Repo/emitter related parts of class.cpp and class.h were moved to class-emit.cpp and class-emit.h; (2) the contents of "vm/core_types.h" was moved to "base/types.h"; and (3) a few functions that didn't appear to be hot were moved from .h files and the corresponding .cpp files.
80 linhas
2.6 KiB
C++
80 linhas
2.6 KiB
C++
/*
|
|
+----------------------------------------------------------------------+
|
|
| HipHop for PHP |
|
|
+----------------------------------------------------------------------+
|
|
| Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
|
|
+----------------------------------------------------------------------+
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
| available through the world-wide-web at the following url: |
|
|
| http://www.php.net/license/3_01.txt |
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
+----------------------------------------------------------------------+
|
|
*/
|
|
|
|
#include "hphp/runtime/base/time/timestamp.h"
|
|
#include "hphp/runtime/base/complex_types.h"
|
|
#include "hphp/runtime/base/time/datetime.h"
|
|
#include "hphp/runtime/base/array/array_init.h"
|
|
#include <timelib.h>
|
|
|
|
namespace HPHP {
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// creation
|
|
|
|
int64_t TimeStamp::Current() {
|
|
return time(0);
|
|
}
|
|
|
|
double TimeStamp::CurrentSecond() {
|
|
struct timeval tp;
|
|
gettimeofday(&tp, nullptr);
|
|
return (double)tp.tv_sec + (double)tp.tv_usec / 1000000;
|
|
}
|
|
|
|
const StaticString
|
|
s_sec("sec"),
|
|
s_usec("usec"),
|
|
s_minuteswest("minuteswest"),
|
|
s_dsttime("dsttime");
|
|
|
|
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();
|
|
}
|
|
|
|
String TimeStamp::CurrentMicroTime() {
|
|
struct timeval tp;
|
|
gettimeofday(&tp, nullptr);
|
|
char ret[100];
|
|
snprintf(ret, 100, "%.8F %ld", (double)tp.tv_usec / 1000000, tp.tv_sec);
|
|
return String(ret, CopyString);
|
|
}
|
|
|
|
int64_t TimeStamp::Get(bool &error, int hou, int min, int sec, int mon, int day,
|
|
int yea, bool gmt) {
|
|
DateTime dt(Current());
|
|
if (gmt) {
|
|
dt.setTimezone(SmartObject<TimeZone>(NEWOBJ(TimeZone)("UTC")));
|
|
}
|
|
dt.set(hou, min, sec, mon, day, yea);
|
|
return dt.toTimeStamp(error);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
}
|