]>
Commit | Line | Data |
---|---|---|
ba379fdc A |
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 | * | |
6 | * The Original Code is Mozilla Communicator client code, released | |
7 | * March 31, 1998. | |
8 | * | |
9 | * The Initial Developer of the Original Code is | |
10 | * Netscape Communications Corporation. | |
11 | * Portions created by the Initial Developer are Copyright (C) 1998 | |
12 | * the Initial Developer. All Rights Reserved. | |
13 | * | |
14 | * This library is free software; you can redistribute it and/or | |
15 | * modify it under the terms of the GNU Lesser General Public | |
16 | * License as published by the Free Software Foundation; either | |
17 | * version 2.1 of the License, or (at your option) any later version. | |
18 | * | |
19 | * This library is distributed in the hope that it will be useful, | |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
22 | * Lesser General Public License for more details. | |
23 | * | |
24 | * You should have received a copy of the GNU Lesser General Public | |
25 | * License along with this library; if not, write to the Free Software | |
26 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
27 | * | |
28 | * Alternatively, the contents of this file may be used under the terms | |
29 | * of either the Mozilla Public License Version 1.1, found at | |
30 | * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public | |
31 | * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html | |
32 | * (the "GPL"), in which case the provisions of the MPL or the GPL are | |
33 | * applicable instead of those above. If you wish to allow use of your | |
34 | * version of this file only under the terms of one of those two | |
35 | * licenses (the MPL or the GPL) and not to allow others to use your | |
36 | * version of this file under the LGPL, indicate your decision by | |
37 | * deletingthe provisions above and replace them with the notice and | |
38 | * other provisions required by the MPL or the GPL, as the case may be. | |
39 | * If you do not delete the provisions above, a recipient may use your | |
40 | * version of this file under any of the LGPL, the MPL or the GPL. | |
41 | */ | |
42 | ||
43 | #include "config.h" | |
44 | #include "DateConversion.h" | |
45 | ||
f9bf01c6 | 46 | #include "CallFrame.h" |
6fe7ccc8 | 47 | #include "JSDateMath.h" |
14957cd0 A |
48 | #include "JSObject.h" |
49 | #include "ScopeChain.h" | |
ba379fdc | 50 | #include "UString.h" |
ba379fdc | 51 | #include <wtf/StringExtras.h> |
14957cd0 | 52 | #include <wtf/text/CString.h> |
ba379fdc A |
53 | |
54 | using namespace WTF; | |
55 | ||
56 | namespace JSC { | |
57 | ||
f9bf01c6 | 58 | double parseDate(ExecState* exec, const UString &date) |
ba379fdc | 59 | { |
f9bf01c6 A |
60 | if (date == exec->globalData().cachedDateString) |
61 | return exec->globalData().cachedDateStringValue; | |
14957cd0 A |
62 | double value = parseES5DateFromNullTerminatedCharacters(date.utf8().data()); |
63 | if (isnan(value)) | |
64 | value = parseDateFromNullTerminatedCharacters(exec, date.utf8().data()); | |
f9bf01c6 A |
65 | exec->globalData().cachedDateString = date; |
66 | exec->globalData().cachedDateStringValue = value; | |
67 | return value; | |
ba379fdc A |
68 | } |
69 | ||
f9bf01c6 | 70 | void formatDate(const GregorianDateTime &t, DateConversionBuffer& buffer) |
ba379fdc | 71 | { |
f9bf01c6 | 72 | snprintf(buffer, DateConversionBufferSize, "%s %s %02d %04d", |
ba379fdc A |
73 | weekdayName[(t.weekDay + 6) % 7], |
74 | monthName[t.month], t.monthDay, t.year + 1900); | |
ba379fdc A |
75 | } |
76 | ||
f9bf01c6 | 77 | void formatDateUTCVariant(const GregorianDateTime &t, DateConversionBuffer& buffer) |
ba379fdc | 78 | { |
f9bf01c6 | 79 | snprintf(buffer, DateConversionBufferSize, "%s, %02d %s %04d", |
ba379fdc A |
80 | weekdayName[(t.weekDay + 6) % 7], |
81 | t.monthDay, monthName[t.month], t.year + 1900); | |
ba379fdc A |
82 | } |
83 | ||
f9bf01c6 | 84 | void formatTime(const GregorianDateTime &t, DateConversionBuffer& buffer) |
ba379fdc | 85 | { |
f9bf01c6 A |
86 | int offset = abs(gmtoffset(t)); |
87 | char timeZoneName[70]; | |
88 | struct tm gtm = t; | |
89 | strftime(timeZoneName, sizeof(timeZoneName), "%Z", >m); | |
ba379fdc | 90 | |
f9bf01c6 A |
91 | if (timeZoneName[0]) { |
92 | snprintf(buffer, DateConversionBufferSize, "%02d:%02d:%02d GMT%c%02d%02d (%s)", | |
93 | t.hour, t.minute, t.second, | |
94 | gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60, timeZoneName); | |
95 | } else { | |
96 | snprintf(buffer, DateConversionBufferSize, "%02d:%02d:%02d GMT%c%02d%02d", | |
97 | t.hour, t.minute, t.second, | |
98 | gmtoffset(t) < 0 ? '-' : '+', offset / (60*60), (offset / 60) % 60); | |
ba379fdc | 99 | } |
f9bf01c6 A |
100 | } |
101 | ||
102 | void formatTimeUTC(const GregorianDateTime &t, DateConversionBuffer& buffer) | |
103 | { | |
104 | snprintf(buffer, DateConversionBufferSize, "%02d:%02d:%02d GMT", t.hour, t.minute, t.second); | |
ba379fdc A |
105 | } |
106 | ||
107 | } // namespace JSC |