]> git.saurik.com Git - apple/javascriptcore.git/blob - runtime/JSDateMath.h
JavaScriptCore-1097.3.tar.gz
[apple/javascriptcore.git] / runtime / JSDateMath.h
1 /*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Google Inc. All rights reserved.
5 * Copyright (C) 2010 Research In Motion Limited. All rights reserved.
6 *
7 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
8 *
9 * The contents of this file are subject to the Mozilla Public License Version
10 * 1.1 (the "License"); you may not use this file except in compliance with
11 * the License. You may obtain a copy of the License at
12 * http://www.mozilla.org/MPL/
13 *
14 * Software distributed under the License is distributed on an "AS IS" basis,
15 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
16 * for the specific language governing rights and limitations under the
17 * License.
18 *
19 * The Original Code is Mozilla Communicator client code, released
20 * March 31, 1998.
21 *
22 * The Initial Developer of the Original Code is
23 * Netscape Communications Corporation.
24 * Portions created by the Initial Developer are Copyright (C) 1998
25 * the Initial Developer. All Rights Reserved.
26 *
27 * Contributor(s):
28 *
29 * Alternatively, the contents of this file may be used under the terms of
30 * either of the GNU General Public License Version 2 or later (the "GPL"),
31 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 * in which case the provisions of the GPL or the LGPL are applicable instead
33 * of those above. If you wish to allow use of your version of this file only
34 * under the terms of either the GPL or the LGPL, and not to allow others to
35 * use your version of this file under the terms of the MPL, indicate your
36 * decision by deleting the provisions above and replace them with the notice
37 * and other provisions required by the GPL or the LGPL. If you do not delete
38 * the provisions above, a recipient may use your version of this file under
39 * the terms of any one of the MPL, the GPL or the LGPL.
40 *
41 */
42
43 #ifndef JSDateMath_h
44 #define JSDateMath_h
45
46 #include <wtf/DateMath.h>
47
48 namespace JSC {
49
50 class ExecState;
51 struct GregorianDateTime;
52
53 void msToGregorianDateTime(ExecState*, double, bool outputIsUTC, GregorianDateTime&);
54 double gregorianDateTimeToMS(ExecState*, const GregorianDateTime&, double, bool inputIsUTC);
55 double getUTCOffset(ExecState*);
56 double parseDateFromNullTerminatedCharacters(ExecState*, const char* dateString);
57
58 // Intentionally overridding the default tm of the system.
59 // The members of tm differ on various operating systems.
60 struct GregorianDateTime {
61 WTF_MAKE_NONCOPYABLE(GregorianDateTime);
62 public:
63 GregorianDateTime()
64 : second(0)
65 , minute(0)
66 , hour(0)
67 , weekDay(0)
68 , monthDay(0)
69 , yearDay(0)
70 , month(0)
71 , year(0)
72 , isDST(0)
73 , utcOffset(0)
74 {
75 }
76
77 operator tm() const
78 {
79 tm ret;
80 memset(&ret, 0, sizeof(ret));
81
82 ret.tm_sec = second;
83 ret.tm_min = minute;
84 ret.tm_hour = hour;
85 ret.tm_wday = weekDay;
86 ret.tm_mday = monthDay;
87 ret.tm_yday = yearDay;
88 ret.tm_mon = month;
89 ret.tm_year = year;
90 ret.tm_isdst = isDST;
91
92 #if HAVE(TM_GMTOFF)
93 ret.tm_gmtoff = static_cast<long>(utcOffset);
94 #endif
95 #if HAVE(TM_ZONE)
96 ret.tm_zone = timeZone.get();
97 #endif
98
99 return ret;
100 }
101
102 void copyFrom(const GregorianDateTime& rhs)
103 {
104 second = rhs.second;
105 minute = rhs.minute;
106 hour = rhs.hour;
107 weekDay = rhs.weekDay;
108 monthDay = rhs.monthDay;
109 yearDay = rhs.yearDay;
110 month = rhs.month;
111 year = rhs.year;
112 isDST = rhs.isDST;
113 utcOffset = rhs.utcOffset;
114 if (rhs.timeZone) {
115 int inZoneSize = strlen(rhs.timeZone.get()) + 1;
116 timeZone = adoptArrayPtr(new char[inZoneSize]);
117 strncpy(timeZone.get(), rhs.timeZone.get(), inZoneSize);
118 } else
119 timeZone = nullptr;
120 }
121
122 int second;
123 int minute;
124 int hour;
125 int weekDay;
126 int monthDay;
127 int yearDay;
128 int month;
129 int year;
130 int isDST;
131 int utcOffset;
132 OwnArrayPtr<char> timeZone;
133 };
134
135 static inline int gmtoffset(const GregorianDateTime& t)
136 {
137 return t.utcOffset;
138 }
139
140 } // namespace JSC
141
142 #endif // JSDateMath_h