]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/DateInstance.cpp
JavaScriptCore-1097.13.tar.gz
[apple/javascriptcore.git] / runtime / DateInstance.cpp
CommitLineData
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
6fe7ccc8 25#include "JSDateMath.h"
f9bf01c6
A
26#include "JSGlobalObject.h"
27
9dae56ea
A
28#include <math.h>
29#include <wtf/MathExtras.h>
30
ba379fdc
A
31using namespace WTF;
32
9dae56ea
A
33namespace JSC {
34
6fe7ccc8 35const ClassInfo DateInstance::s_info = {"Date", &JSWrapperObject::s_info, 0, 0, CREATE_METHOD_TABLE(DateInstance)};
9dae56ea 36
14957cd0
A
37DateInstance::DateInstance(ExecState* exec, Structure* structure)
38 : JSWrapperObject(exec->globalData(), structure)
9dae56ea 39{
6fe7ccc8
A
40}
41
42void DateInstance::finishCreation(JSGlobalData& globalData)
43{
44 Base::finishCreation(globalData);
14957cd0 45 ASSERT(inherits(&s_info));
6fe7ccc8 46 setInternalValue(globalData, jsNaN());
9dae56ea
A
47}
48
6fe7ccc8 49void DateInstance::finishCreation(JSGlobalData& globalData, double time)
9dae56ea 50{
6fe7ccc8 51 Base::finishCreation(globalData);
14957cd0 52 ASSERT(inherits(&s_info));
6fe7ccc8
A
53 setInternalValue(globalData, jsNumber(timeClip(time)));
54}
55
56void DateInstance::destroy(JSCell* cell)
57{
58 jsCast<DateInstance*>(cell)->DateInstance::~DateInstance();
9dae56ea
A
59}
60
f9bf01c6 61const GregorianDateTime* DateInstance::calculateGregorianDateTime(ExecState* exec) const
9dae56ea
A
62{
63 double milli = internalNumber();
64 if (isnan(milli))
f9bf01c6
A
65 return 0;
66
67 if (!m_data)
68 m_data = exec->globalData().dateInstanceCache.add(milli);
69
70 if (m_data->m_gregorianDateTimeCachedForMS != milli) {
71 msToGregorianDateTime(exec, milli, false, m_data->m_cachedGregorianDateTime);
72 m_data->m_gregorianDateTimeCachedForMS = milli;
73 }
74 return &m_data->m_cachedGregorianDateTime;
9dae56ea
A
75}
76
f9bf01c6 77const GregorianDateTime* DateInstance::calculateGregorianDateTimeUTC(ExecState* exec) const
9dae56ea
A
78{
79 double milli = internalNumber();
80 if (isnan(milli))
f9bf01c6 81 return 0;
9dae56ea 82
f9bf01c6
A
83 if (!m_data)
84 m_data = exec->globalData().dateInstanceCache.add(milli);
9dae56ea 85
f9bf01c6
A
86 if (m_data->m_gregorianDateTimeUTCCachedForMS != milli) {
87 msToGregorianDateTime(exec, milli, true, m_data->m_cachedGregorianDateTimeUTC);
88 m_data->m_gregorianDateTimeUTCCachedForMS = milli;
89 }
90 return &m_data->m_cachedGregorianDateTimeUTC;
9dae56ea
A
91}
92
93} // namespace JSC