2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010- Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/time/timestamp.h"
18 #include "hphp/runtime/base/complex_types.h"
19 #include "hphp/runtime/base/time/datetime.h"
23 ///////////////////////////////////////////////////////////////////////////////
26 int64_t TimeStamp::Current() {
30 double TimeStamp::CurrentSecond() {
32 gettimeofday(&tp
, nullptr);
33 return (double)tp
.tv_sec
+ (double)tp
.tv_usec
/ 1000000;
36 static const StaticString
s_sec("sec");
37 static const StaticString
s_usec("usec");
38 static const StaticString
s_minuteswest("minuteswest");
39 static const StaticString
s_dsttime("dsttime");
41 Array
TimeStamp::CurrentTime() {
43 gettimeofday(&tp
, nullptr);
45 timelib_time_offset
*offset
=
46 timelib_get_time_zone_info(tp
.tv_sec
, TimeZone::Current()->get());
49 ret
.set(s_sec
, (int)tp
.tv_sec
);
50 ret
.set(s_usec
, (int)tp
.tv_usec
);
51 ret
.set(s_minuteswest
, (int)(-offset
->offset
/ 60));
52 ret
.set(s_dsttime
, (int)offset
->is_dst
);
54 timelib_time_offset_dtor(offset
);
58 String
TimeStamp::CurrentMicroTime() {
60 gettimeofday(&tp
, nullptr);
62 snprintf(ret
, 100, "%.8F %ld", (double)tp
.tv_usec
/ 1000000, tp
.tv_sec
);
63 return String(ret
, CopyString
);
66 int64_t TimeStamp::Get(bool &error
, int hou
, int min
, int sec
, int mon
, int day
,
68 DateTime
dt(Current());
70 dt
.setTimezone(SmartObject
<TimeZone
>(NEWOBJ(TimeZone
)("UTC")));
72 dt
.set(hou
, min
, sec
, mon
, day
, yea
);
73 return dt
.toTimeStamp(error
);
76 ///////////////////////////////////////////////////////////////////////////////