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

Last change on this file since 33930 was 33930, checked in by [email protected], 17 years ago

Make the profiler use higher than millisecond resolution time-stamps.

Reviewed by Kevin McCullough.

  • kjs/DateMath.cpp:

(KJS::getCurrentUTCTime): Call getCurrentUTCTimeWithMicroseconds and
floor the result.
(KJS::getCurrentUTCTimeWithMicroseconds): Copied from the previous
implementation of getCurrentUTCTime without the floor call.

  • kjs/DateMath.h: Addded getCurrentUTCTimeWithMicroseconds.
  • profiler/ProfileNode.cpp:

(KJS::ProfileNode::ProfileNode): Use getCurrentUTCTimeWithMicroseconds.

  • Property svn:eol-style set to native
File size: 5.2 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 initDateMath();
53void msToGregorianDateTime(double, bool outputIsUTC, GregorianDateTime&);
54double gregorianDateTimeToMS(const GregorianDateTime&, double, bool inputIsUTC);
55double getUTCOffset();
56int equivalentYearForDST(int year);
57double getCurrentUTCTime();
58double getCurrentUTCTimeWithMicroseconds();
59void getLocalTime(const time_t*, tm*);
60
61
62const char * const weekdayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
63const char * const monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
64
65const double hoursPerDay = 24.0;
66const double minutesPerHour = 60.0;
67const double secondsPerHour = 60.0 * 60.0;
68const double secondsPerMinute = 60.0;
69const double msPerSecond = 1000.0;
70const double msPerMinute = 60.0 * 1000.0;
71const double msPerHour = 60.0 * 60.0 * 1000.0;
72const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;
73
74// Intentionally overridding the default tm of the system
75// Tee members of tm differ on various operating systems.
76struct GregorianDateTime : Noncopyable {
77 GregorianDateTime()
78 : second(0)
79 , minute(0)
80 , hour(0)
81 , weekDay(0)
82 , monthDay(0)
83 , yearDay(0)
84 , month(0)
85 , year(0)
86 , isDST(0)
87 , utcOffset(0)
88 , timeZone(0)
89 {
90 }
91
92 ~GregorianDateTime()
93 {
94 delete [] timeZone;
95 }
96
97 GregorianDateTime(const tm& inTm)
98 : second(inTm.tm_sec)
99 , minute(inTm.tm_min)
100 , hour(inTm.tm_hour)
101 , weekDay(inTm.tm_wday)
102 , monthDay(inTm.tm_mday)
103 , yearDay(inTm.tm_yday)
104 , month(inTm.tm_mon)
105 , year(inTm.tm_year)
106 , isDST(inTm.tm_isdst)
107 {
108#if !PLATFORM(WIN_OS) && !PLATFORM(SOLARIS)
109 utcOffset = static_cast<int>(inTm.tm_gmtoff);
110
111 int inZoneSize = strlen(inTm.tm_zone) + 1;
112 timeZone = new char[inZoneSize];
113 strncpy(timeZone, inTm.tm_zone, inZoneSize);
114#else
115 utcOffset = static_cast<int>(getUTCOffset() / msPerSecond + (isDST ? secondsPerHour : 0));
116 timeZone = 0;
117#endif
118 }
119
120 operator tm() const
121 {
122 tm ret;
123 memset(&ret, 0, sizeof(ret));
124
125 ret.tm_sec = second;
126 ret.tm_min = minute;
127 ret.tm_hour = hour;
128 ret.tm_wday = weekDay;
129 ret.tm_mday = monthDay;
130 ret.tm_yday = yearDay;
131 ret.tm_mon = month;
132 ret.tm_year = year;
133 ret.tm_isdst = isDST;
134
135#if !PLATFORM(WIN_OS) && !PLATFORM(SOLARIS)
136 ret.tm_gmtoff = static_cast<long>(utcOffset);
137 ret.tm_zone = timeZone;
138#endif
139
140 return ret;
141 }
142
143 void copyFrom(const GregorianDateTime& rhs)
144 {
145 second = rhs.second;
146 minute = rhs.minute;
147 hour = rhs.hour;
148 weekDay = rhs.weekDay;
149 monthDay = rhs.monthDay;
150 yearDay = rhs.yearDay;
151 month = rhs.month;
152 year = rhs.year;
153 isDST = rhs.isDST;
154 utcOffset = rhs.utcOffset;
155 if (rhs.timeZone) {
156 int inZoneSize = strlen(rhs.timeZone) + 1;
157 timeZone = new char[inZoneSize];
158 strncpy(timeZone, rhs.timeZone, inZoneSize);
159 } else
160 timeZone = 0;
161 }
162
163 int second;
164 int minute;
165 int hour;
166 int weekDay;
167 int monthDay;
168 int yearDay;
169 int month;
170 int year;
171 int isDST;
172 int utcOffset;
173 char* timeZone;
174};
175
176} //namespace KJS
177
178#endif // DateMath_h
Note: See TracBrowser for help on using the repository browser.