2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present 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"
18 #include <folly/portability/SysTime.h>
26 #include "hphp/runtime/base/array-init.h"
27 #include "hphp/runtime/base/datetime.h"
28 #include "hphp/runtime/base/resource-data.h"
29 #include "hphp/runtime/base/type-array.h"
30 #include "hphp/runtime/base/type-string.h"
31 #include "hphp/util/timer.h"
34 ///////////////////////////////////////////////////////////////////////////////
37 int64_t TimeStamp::Current() {
41 double TimeStamp::CurrentSecond() {
42 auto now_ns
= gettime_ns(CLOCK_REALTIME
);
44 std::chrono::duration
<double, std::chrono::seconds::period
>;
45 auto now_double_secs
= DoubleSeconds(std::chrono::nanoseconds(now_ns
));
46 return now_double_secs
.count();
52 s_minuteswest("minuteswest"),
55 Array
TimeStamp::CurrentTime() {
57 gettimeofday(&tp
, nullptr);
59 timelib_time_offset
*offset
=
60 timelib_get_time_zone_info(tp
.tv_sec
, TimeZone::Current()->getTZInfo());
62 auto const ret
= make_darray(
63 s_sec
, (int)tp
.tv_sec
,
64 s_usec
, (int)tp
.tv_usec
,
65 s_minuteswest
, (int)(-offset
->offset
/ 60),
66 s_dsttime
, (int)offset
->is_dst
68 timelib_time_offset_dtor(offset
);
72 String
TimeStamp::CurrentMicroTime() {
74 gettimeofday(&tp
, nullptr);
76 snprintf(ret
, 100, "%.8F %ld", (double)tp
.tv_usec
/ 1000000, tp
.tv_sec
);
77 return String(ret
, CopyString
);
80 int64_t TimeStamp::Get(bool &error
, int hou
, int min
, int sec
, int mon
, int day
,
82 auto dt
= req::make
<DateTime
>(Current());
84 dt
->setTimezone(req::make
<TimeZone
>("UTC"));
86 dt
->set(hou
, min
, sec
, mon
, day
, yea
);
87 return dt
->toTimeStamp(error
);
90 ///////////////////////////////////////////////////////////////////////////////