]>
Commit | Line | Data |
---|---|---|
9dae56ea A |
1 | /* |
2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) | |
3 | * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | |
4 | * | |
5 | * This library is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU Lesser General Public | |
7 | * License as published by the Free Software Foundation; either | |
8 | * version 2 of the License, or (at your option) any later version. | |
9 | * | |
10 | * This library is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * Lesser General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU Lesser General Public | |
16 | * License along with this library; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
18 | * USA | |
19 | * | |
20 | */ | |
21 | ||
22 | #include "config.h" | |
23 | #include "DateInstance.h" | |
24 | ||
f9bf01c6 A |
25 | #include "JSGlobalObject.h" |
26 | ||
9dae56ea | 27 | #include <math.h> |
ba379fdc | 28 | #include <wtf/DateMath.h> |
9dae56ea A |
29 | #include <wtf/MathExtras.h> |
30 | ||
ba379fdc A |
31 | using namespace WTF; |
32 | ||
9dae56ea A |
33 | namespace JSC { |
34 | ||
14957cd0 | 35 | const ClassInfo DateInstance::s_info = {"Date", &JSWrapperObject::s_info, 0, 0}; |
9dae56ea | 36 | |
14957cd0 A |
37 | DateInstance::DateInstance(ExecState* exec, Structure* structure) |
38 | : JSWrapperObject(exec->globalData(), structure) | |
9dae56ea | 39 | { |
14957cd0 A |
40 | ASSERT(inherits(&s_info)); |
41 | setInternalValue(exec->globalData(), jsNaN()); | |
9dae56ea A |
42 | } |
43 | ||
14957cd0 A |
44 | DateInstance::DateInstance(ExecState* exec, Structure* structure, double time) |
45 | : JSWrapperObject(exec->globalData(), structure) | |
9dae56ea | 46 | { |
14957cd0 A |
47 | ASSERT(inherits(&s_info)); |
48 | setInternalValue(exec->globalData(), jsNumber(timeClip(time))); | |
9dae56ea A |
49 | } |
50 | ||
f9bf01c6 | 51 | const GregorianDateTime* DateInstance::calculateGregorianDateTime(ExecState* exec) const |
9dae56ea A |
52 | { |
53 | double milli = internalNumber(); | |
54 | if (isnan(milli)) | |
f9bf01c6 A |
55 | return 0; |
56 | ||
57 | if (!m_data) | |
58 | m_data = exec->globalData().dateInstanceCache.add(milli); | |
59 | ||
60 | if (m_data->m_gregorianDateTimeCachedForMS != milli) { | |
61 | msToGregorianDateTime(exec, milli, false, m_data->m_cachedGregorianDateTime); | |
62 | m_data->m_gregorianDateTimeCachedForMS = milli; | |
63 | } | |
64 | return &m_data->m_cachedGregorianDateTime; | |
9dae56ea A |
65 | } |
66 | ||
f9bf01c6 | 67 | const GregorianDateTime* DateInstance::calculateGregorianDateTimeUTC(ExecState* exec) const |
9dae56ea A |
68 | { |
69 | double milli = internalNumber(); | |
70 | if (isnan(milli)) | |
f9bf01c6 | 71 | return 0; |
9dae56ea | 72 | |
f9bf01c6 A |
73 | if (!m_data) |
74 | m_data = exec->globalData().dateInstanceCache.add(milli); | |
9dae56ea | 75 | |
f9bf01c6 A |
76 | if (m_data->m_gregorianDateTimeUTCCachedForMS != milli) { |
77 | msToGregorianDateTime(exec, milli, true, m_data->m_cachedGregorianDateTimeUTC); | |
78 | m_data->m_gregorianDateTimeUTCCachedForMS = milli; | |
79 | } | |
80 | return &m_data->m_cachedGregorianDateTimeUTC; | |
9dae56ea A |
81 | } |
82 | ||
83 | } // namespace JSC |