2
* Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3
* Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
5
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
7
* The contents of this file are subject to the Mozilla Public License Version
8
* 1.1 (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
10
* http://www.mozilla.org/MPL/
12
* Software distributed under the License is distributed on an "AS IS" basis,
13
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14
* for the specific language governing rights and limitations under the
17
* The Original Code is Mozilla Communicator client code, released
20
* The Initial Developer of the Original Code is
21
* Netscape Communications Corporation.
22
* Portions created by the Initial Developer are Copyright (C) 1998
23
* the Initial Developer. All Rights Reserved.
27
* Alternatively, the contents of this file may be used under the terms of
28
* either of the GNU General Public License Version 2 or later (the "GPL"),
29
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30
* in which case the provisions of the GPL or the LGPL are applicable instead
31
* of those above. If you wish to allow use of your version of this file only
32
* under the terms of either the GPL or the LGPL, and not to allow others to
33
* use your version of this file under the terms of the MPL, indicate your
34
* decision by deleting the provisions above and replace them with the notice
35
* and other provisions required by the GPL or the LGPL. If you do not delete
36
* the provisions above, a recipient may use your version of this file under
37
* the terms of any one of the MPL, the GPL or the LGPL.
46
#include <wtf/Noncopyable.h>
51
struct GregorianDateTime;
54
void msToGregorianDateTime(double, bool outputIsUTC, GregorianDateTime&);
55
double gregorianDateTimeToMS(const GregorianDateTime&, double, bool inputIsUTC);
56
double getUTCOffset();
57
int equivalentYearForDST(int year);
58
double getCurrentUTCTime();
59
double getCurrentUTCTimeWithMicroseconds();
60
void getLocalTime(const time_t*, tm*);
62
// Not really math related, but this is currently the only shared place to put these.
63
double parseDate(const UString&);
64
double timeClip(double);
65
UString formatDate(const GregorianDateTime&);
66
UString formatDateUTCVariant(const GregorianDateTime&);
67
UString formatTime(const GregorianDateTime&, bool inputIsUTC);
70
const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
71
const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
73
const double hoursPerDay = 24.0;
74
const double minutesPerHour = 60.0;
75
const double secondsPerHour = 60.0 * 60.0;
76
const double secondsPerMinute = 60.0;
77
const double msPerSecond = 1000.0;
78
const double msPerMinute = 60.0 * 1000.0;
79
const double msPerHour = 60.0 * 60.0 * 1000.0;
80
const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;
82
// Intentionally overridding the default tm of the system
83
// Tee members of tm differ on various operating systems.
84
struct GregorianDateTime : Noncopyable {
105
GregorianDateTime(const tm& inTm)
106
: second(inTm.tm_sec)
107
, minute(inTm.tm_min)
109
, weekDay(inTm.tm_wday)
110
, monthDay(inTm.tm_mday)
111
, yearDay(inTm.tm_yday)
114
, isDST(inTm.tm_isdst)
116
#if !PLATFORM(WIN_OS) && !PLATFORM(SOLARIS) && !COMPILER(RVCT)
117
utcOffset = static_cast<int>(inTm.tm_gmtoff);
119
int inZoneSize = strlen(inTm.tm_zone) + 1;
120
timeZone = new char[inZoneSize];
121
strncpy(timeZone, inTm.tm_zone, inZoneSize);
123
utcOffset = static_cast<int>(getUTCOffset() / msPerSecond + (isDST ? secondsPerHour : 0));
131
memset(&ret, 0, sizeof(ret));
136
ret.tm_wday = weekDay;
137
ret.tm_mday = monthDay;
138
ret.tm_yday = yearDay;
141
ret.tm_isdst = isDST;
143
#if !PLATFORM(WIN_OS) && !PLATFORM(SOLARIS) && !COMPILER(RVCT)
144
ret.tm_gmtoff = static_cast<long>(utcOffset);
145
ret.tm_zone = timeZone;
151
void copyFrom(const GregorianDateTime& rhs)
156
weekDay = rhs.weekDay;
157
monthDay = rhs.monthDay;
158
yearDay = rhs.yearDay;
162
utcOffset = rhs.utcOffset;
164
int inZoneSize = strlen(rhs.timeZone) + 1;
165
timeZone = new char[inZoneSize];
166
strncpy(timeZone, rhs.timeZone, inZoneSize);
184
static inline int gmtoffset(const GregorianDateTime& t)