source: webkit/trunk/JavaScriptCore/kjs/DateMath.h@ 17031

Last change on this file since 17031 was 17031, checked in by kmccullo, 19 years ago

Reviewed by Adam, Geoff, Darin.

Fixed displaying the UTC offset and time zone string, as well as renamed the GregorianDateTime structure and clean up.

  • ChangeLog:
  • kjs/DateMath.cpp: (KJS::getUTCOffset): (KJS::getDSTOffsetSimple): (KJS::gregorianDateTimeToMS): (KJS::msToGregorianDateTime):
  • kjs/DateMath.h: (KJS::GregorianDateTime::GregorianDateTime): (KJS::GregorianDateTime::~GregorianDateTime): (KJS::GregorianDateTime::toTM):
  • kjs/date_object.cpp: (KJS::gmtoffset): (KJS::formatDate): (KJS::formatDateUTCVariant): (KJS::formatTime): (KJS::fillStructuresUsingTimeArgs): (KJS::fillStructuresUsingDateArgs): (KJS::DateInstance::getTime): (KJS::DateInstance::getUTCTime): (KJS::DateProtoFunc::callAsFunction): (KJS::DateObjectImp::construct): (KJS::DateObjectImp::callAsFunction): (KJS::DateObjectFuncImp::callAsFunction): (KJS::parseDate):
  • kjs/date_object.h:
File size: 4.3 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2006 Apple Computer
4 *
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 *
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/
11 *
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
15 * License.
16 *
17 * The Original Code is Mozilla Communicator client code, released
18 * March 31, 1998.
19 *
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.
24 *
25 * Contributor(s):
26 *
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.
38 *
39 */
40
41#ifndef DateMath_h
42#define DateMath_h
43
44#include <time.h>
45
46namespace KJS {
47
48// Intentionally overridding the default tm of the system
49// Not all OS' have the same members of their tm's
50struct GregorianDateTime {
51 GregorianDateTime()
52 {
53 second = 0;
54 minute = 0;
55 hour = 0;
56 weekDay = 0;
57 monthDay = 0;
58 yearDay = 0;
59 month = 0;
60 year = 0;
61 isDST = 0;
62 utcOffset = 0;
63 timeZone = NULL;
64 }
65
66 ~GregorianDateTime()
67 {
68 if (timeZone)
69 delete timeZone;
70 }
71
72 GregorianDateTime(const tm& inTm)
73 : second(inTm.tm_sec)
74 , minute(inTm.tm_min)
75 , hour(inTm.tm_hour)
76 , weekDay(inTm.tm_wday)
77 , monthDay(inTm.tm_mday)
78 , yearDay(inTm.tm_yday)
79 , month(inTm.tm_mon)
80 , year(inTm.tm_year)
81 , isDST(inTm.tm_isdst)
82 {
83#if !PLATFORM(WIN_OS)
84 utcOffset = static_cast<int>(inTm.tm_gmtoff);
85
86 int inZoneSize = strlen(inTm.tm_zone) + 1;
87 timeZone = new char[inZoneSize];
88 strncpy(timeZone, inTm.tm_zone, inZoneSize);
89#else
90 utcOffset = 0;
91 timeZone = NULL;
92#endif
93 }
94
95 tm toTM() const
96 {
97 tm ret;
98 memset(&ret, 0, sizeof(ret));
99
100 ret.tm_sec = second;
101 ret.tm_min = minute;
102 ret.tm_hour = hour;
103 ret.tm_wday = weekDay;
104 ret.tm_mday = monthDay;
105 ret.tm_yday = yearDay;
106 ret.tm_mon = month;
107 ret.tm_year = year;
108 ret.tm_isdst = isDST;
109
110#if !PLATFORM(WIN_OS)
111 ret.tm_gmtoff = static_cast<long>(utcOffset);
112 ret.tm_zone = timeZone;
113#endif
114
115 return ret;
116 }
117
118 int second;
119 int minute;
120 int hour;
121 int weekDay;
122 int monthDay;
123 int yearDay;
124 int month;
125 int year;
126 int isDST;
127 int utcOffset;
128 char* timeZone;
129};
130
131// Constants //
132
133const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
134const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
135
136const double hoursPerDay = 24.0;
137const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;
138const double minutesPerHour = 60.0;
139const double secondsPerMinute = 60.0;
140const double msPerSecond = 1000.0;
141const double msPerMinute = 60.0 * 1000.0;
142const double msPerHour = 60.0 * 60.0 * 1000.0;
143
144// Exported Functions //
145void msToGregorianDateTime(double, bool outputIsUTC, struct GregorianDateTime&);
146double gregorianDateTimeToMS(const GregorianDateTime&, double, bool inputIsUTC);
147double getUTCOffset();
148
149} //namespace KJS
150
151#endif // DateMath_h
Note: See TracBrowser for help on using the repository browser.