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 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_DATEINTERVAL_H_
18 #define incl_HPHP_DATEINTERVAL_H_
20 #include "hphp/runtime/base/type-resource.h"
21 #include "hphp/runtime/base/type-string.h"
22 #include "hphp/util/alloc.h"
32 ///////////////////////////////////////////////////////////////////////////////
33 typedef std::shared_ptr
<timelib_rel_time
> DateIntervalPtr
;
36 * Handles all date interval related functions.
38 struct DateInterval
: SweepableResourceData
{
39 DECLARE_RESOURCE_ALLOCATION(DateInterval
);
40 static const StaticString
& classnameof() {
41 static const StaticString
result("DateInterval");
44 const String
& o_getClassNameHook() const override
{ return classnameof(); }
47 explicit DateInterval(const String
& date_interval
, bool date_string
= false);
48 explicit DateInterval(timelib_rel_time
*di
);
50 int64_t getYears() const { return m_di
->y
; }
51 int64_t getMonths() const { return m_di
->m
; }
52 int64_t getDays() const { return m_di
->d
; }
53 int64_t getHours() const { return m_di
->h
; }
54 int64_t getMinutes() const { return m_di
->i
; }
55 int64_t getSeconds() const { return m_di
->s
; }
56 bool isInverted() const { return m_di
->invert
; }
57 bool haveTotalDays() const { return m_di
->days
!= -99999; }
58 int64_t getTotalDays() const { return m_di
->days
; }
60 void setYears(int64_t value
) { if (isValid()) m_di
->y
= value
; }
61 void setMonths(int64_t value
) { if (isValid()) m_di
->m
= value
; }
62 void setDays(int64_t value
) { if (isValid()) m_di
->d
= value
; }
63 void setHours(int64_t value
) { if (isValid()) m_di
->h
= value
; }
64 void setMinutes(int64_t value
) { if (isValid()) m_di
->i
= value
; }
65 void setSeconds(int64_t value
) { if (isValid()) m_di
->s
= value
; }
66 void setInverted(bool value
) {
67 if (isValid()) m_di
->invert
= value
;
69 void setTotalDays(int64_t value
) {
70 if (isValid()) m_di
->days
= value
;
73 String
format(const String
& format_spec
);
75 bool isValid() const { return get(); }
76 req::ptr
<DateInterval
> cloneDateInterval() const;
79 friend struct DateTime
;
81 timelib_rel_time
*get() const { return m_di
.get(); }
84 void setDateString(const String
& date_string
);
85 void setInterval(const String
& date_interval
);
86 struct dateinterval_deleter
{
87 void operator()(timelib_rel_time
*di
) {
89 timelib_rel_time_dtor(di
);
97 ///////////////////////////////////////////////////////////////////////////////
100 #endif // incl_HPHP_DATEINTERVAL_H_