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

Last change on this file since 20310 was 20203, checked in by kmccullo, 18 years ago

JavaScriptCore:

Reviewed by Geoff.

  • rdar://problem/5045720
  • DST changes in US affect JavaScript date calculations (12975) This fix was to ensure we properly test for the new changes to DST in the US. Also this fixes when we apply DST, now we correctly map most past years to current DST rules. We still have a small issue with years before 1900 or after 2100. rdar://problem/5055038
  • kjs/DateMath.cpp: Fix DST to match spec better. (KJS::getCurrentUTCTime): (KJS::mimimumYearForDST): (KJS::maximumYearForDST): (KJS::equivalentYearForDST): (KJS::getDSTOffset):
  • kjs/DateMath.h: Consolodated common funtionality.
  • kjs/date_object.cpp: Consolodated common functionality. (KJS::formatLocaleDate): (KJS::DateObjectImp::construct):
  • tests/mozilla/ecma/jsref.js: Added functions for finding the correct days when DST starts and ends.
  • tests/mozilla/ecma/shell.js: Added back in the old DST functions for ease of merging with mozilla if needed.
  • tests/mozilla/ecma_2/jsref.js: Added functions for finding the correct days when DST starts and ends.
  • tests/mozilla/ecma_3/Date/shell.js: Added functions for finding the correct days when DST starts and ends.
  • tests/mozilla/expected.html: Updated to show all date tests passing.

LayoutTests:

Reviewed by Geoff.

  • rdar://problem/5045720
  • DST changes in US affect JavaScript date calculations (12975) Changed layout tests to properly check for the new changes to DST in the US. Also these now test that equivalent years return the same results for DST.
  • fast/js/date-DST-time-cusps-expected.txt:
  • fast/js/date-big-setdate-expected.txt:
  • fast/js/resources/date-DST-time-cusps.js:
  • fast/js/resources/date-big-setdate.js:
File size: 4.5 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
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#include <string.h>
46#include <wtf/Noncopyable.h>
47
48namespace KJS {
49
50struct GregorianDateTime;
51
52void msToGregorianDateTime(double, bool outputIsUTC, GregorianDateTime&);
53double gregorianDateTimeToMS(const GregorianDateTime&, double, bool inputIsUTC);
54double getUTCOffset();
55int equivalentYearForDST(int year);
56double getCurrentUTCTime();
57
58const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
59const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
60
61const double hoursPerDay = 24.0;
62const double minutesPerHour = 60.0;
63const double secondsPerHour = 60.0 * 60.0;
64const double secondsPerMinute = 60.0;
65const double msPerSecond = 1000.0;
66const double msPerMinute = 60.0 * 1000.0;
67const double msPerHour = 60.0 * 60.0 * 1000.0;
68const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;
69
70// Intentionally overridding the default tm of the system
71// Not all OS' have the same members of their tm's
72struct GregorianDateTime : Noncopyable {
73 GregorianDateTime()
74 : second(0)
75 , minute(0)
76 , hour(0)
77 , weekDay(0)
78 , monthDay(0)
79 , yearDay(0)
80 , month(0)
81 , year(0)
82 , isDST(0)
83 , utcOffset(0)
84 , timeZone(0)
85 {
86 }
87
88 ~GregorianDateTime()
89 {
90 delete [] timeZone;
91 }
92
93 GregorianDateTime(const tm& inTm)
94 : second(inTm.tm_sec)
95 , minute(inTm.tm_min)
96 , hour(inTm.tm_hour)
97 , weekDay(inTm.tm_wday)
98 , monthDay(inTm.tm_mday)
99 , yearDay(inTm.tm_yday)
100 , month(inTm.tm_mon)
101 , year(inTm.tm_year)
102 , isDST(inTm.tm_isdst)
103 {
104#if !PLATFORM(WIN_OS)
105 utcOffset = static_cast<int>(inTm.tm_gmtoff);
106
107 int inZoneSize = strlen(inTm.tm_zone) + 1;
108 timeZone = new char[inZoneSize];
109 strncpy(timeZone, inTm.tm_zone, inZoneSize);
110#else
111 utcOffset = static_cast<int>(getUTCOffset() / msPerSecond + (isDST ? secondsPerHour : 0));
112 timeZone = 0;
113#endif
114 }
115
116 operator tm() const
117 {
118 tm ret;
119 memset(&ret, 0, sizeof(ret));
120
121 ret.tm_sec = second;
122 ret.tm_min = minute;
123 ret.tm_hour = hour;
124 ret.tm_wday = weekDay;
125 ret.tm_mday = monthDay;
126 ret.tm_yday = yearDay;
127 ret.tm_mon = month;
128 ret.tm_year = year;
129 ret.tm_isdst = isDST;
130
131#if !PLATFORM(WIN_OS)
132 ret.tm_gmtoff = static_cast<long>(utcOffset);
133 ret.tm_zone = timeZone;
134#endif
135
136 return ret;
137 }
138
139 int second;
140 int minute;
141 int hour;
142 int weekDay;
143 int monthDay;
144 int yearDay;
145 int month;
146 int year;
147 int isDST;
148 int utcOffset;
149 char* timeZone;
150};
151
152} //namespace KJS
153
154#endif // DateMath_h
Note: See TracBrowser for help on using the repository browser.