• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DateMath_h
44 #define DateMath_h
45 
46 #include <stdint.h>
47 #include <string.h>
48 #include "wtf/text/WTFString.h"
49 #include "wtf/WTFExport.h"
50 
51 namespace WTF {
52 
53 WTF_EXPORT void initializeDates();
54 
55 // Not really math related, but this is currently the only shared place to put these.
56 WTF_EXPORT double parseDateFromNullTerminatedCharacters(const char* dateString);
57 // dayOfWeek: [0, 6] 0 being Monday, day: [1, 31], month: [0, 11], year: ex: 2011, hours: [0, 23], minutes: [0, 59], seconds: [0, 59], utcOffset: [-720,720].
58 WTF_EXPORT String makeRFC2822DateString(unsigned dayOfWeek, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned minutes, unsigned seconds, int utcOffset);
59 
60 const char weekdayName[7][4] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
61 const char monthName[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
62 const char* const monthFullName[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
63 
64 const double minutesPerHour = 60.0;
65 const double secondsPerMinute = 60.0;
66 const double msPerSecond = 1000.0;
67 const double msPerMinute = 60.0 * 1000.0;
68 const double msPerHour = 60.0 * 60.0 * 1000.0;
69 const double msPerDay = 24.0 * 60.0 * 60.0 * 1000.0;
70 
71 WTF_EXPORT bool isLeapYear(int year);
72 
73 // Returns the number of days from 1970-01-01 to the specified date.
74 WTF_EXPORT double dateToDaysFrom1970(int year, int month, int day);
75 WTF_EXPORT int msToYear(double ms);
76 WTF_EXPORT int dayInYear(int year, int month, int day);
77 WTF_EXPORT int dayInYear(double ms, int year);
78 WTF_EXPORT int monthFromDayInYear(int dayInYear, bool leapYear);
79 WTF_EXPORT int dayInMonthFromDayInYear(int dayInYear, bool leapYear);
80 
81 // Returns offset milliseconds for UTC and DST.
82 WTF_EXPORT int32_t calculateUTCOffset();
83 WTF_EXPORT double calculateDSTOffset(double ms, double utcOffset);
84 
85 } // namespace WTF
86 
87 using WTF::isLeapYear;
88 using WTF::dateToDaysFrom1970;
89 using WTF::dayInMonthFromDayInYear;
90 using WTF::dayInYear;
91 using WTF::minutesPerHour;
92 using WTF::monthFromDayInYear;
93 using WTF::msPerDay;
94 using WTF::msPerHour;
95 using WTF::msPerMinute;
96 using WTF::msPerSecond;
97 using WTF::msToYear;
98 using WTF::secondsPerMinute;
99 using WTF::parseDateFromNullTerminatedCharacters;
100 using WTF::makeRFC2822DateString;
101 using WTF::calculateUTCOffset;
102 using WTF::calculateDSTOffset;
103 
104 #endif // DateMath_h
105