2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 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 +----------------------------------------------------------------------+
16 #include "hphp/runtime/base/timestamp.h"
23 #include "hphp/runtime/base/complex-types.h"
24 #include "hphp/runtime/base/datetime.h"
25 #include "hphp/runtime/base/array-init.h"
28 ///////////////////////////////////////////////////////////////////////////////
31 int64_t TimeStamp::Current() {
35 double TimeStamp::CurrentSecond() {
37 gettimeofday(&tp
, nullptr);
38 return (double)tp
.tv_sec
+ (double)tp
.tv_usec
/ 1000000;
44 s_minuteswest("minuteswest"),
47 Array
TimeStamp::CurrentTime() {
49 gettimeofday(&tp
, nullptr);
51 timelib_time_offset
*offset
=
52 timelib_get_time_zone_info(tp
.tv_sec
, TimeZone::Current()->get());
55 ret
.set(s_sec
, (int)tp
.tv_sec
);
56 ret
.set(s_usec
, (int)tp
.tv_usec
);
57 ret
.set(s_minuteswest
, (int)(-offset
->offset
/ 60));
58 ret
.set(s_dsttime
, (int)offset
->is_dst
);
60 timelib_time_offset_dtor(offset
);
64 String
TimeStamp::CurrentMicroTime() {
66 gettimeofday(&tp
, nullptr);
68 snprintf(ret
, 100, "%.8F %ld", (double)tp
.tv_usec
/ 1000000, tp
.tv_sec
);
69 return String(ret
, CopyString
);
72 int64_t TimeStamp::Get(bool &error
, int hou
, int min
, int sec
, int mon
, int day
,
74 DateTime
dt(Current());
76 dt
.setTimezone(SmartResource
<TimeZone
>(NEWOBJ(TimeZone
)("UTC")));
78 dt
.set(hou
, min
, sec
, mon
, day
, yea
);
79 return dt
.toTimeStamp(error
);
82 ///////////////////////////////////////////////////////////////////////////////