2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
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.
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.
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
23 #include "DateInstance.h"
25 #include "JSDateMath.h"
26 #include "JSGlobalObject.h"
27 #include "JSCInlines.h"
29 #include <wtf/MathExtras.h>
35 const ClassInfo
DateInstance::s_info
= {"Date", &JSWrapperObject::s_info
, 0, CREATE_METHOD_TABLE(DateInstance
)};
37 DateInstance::DateInstance(VM
& vm
, Structure
* structure
)
38 : JSWrapperObject(vm
, structure
)
42 void DateInstance::finishCreation(VM
& vm
)
44 Base::finishCreation(vm
);
45 ASSERT(inherits(info()));
46 setInternalValue(vm
, jsNaN());
49 void DateInstance::finishCreation(VM
& vm
, double time
)
51 Base::finishCreation(vm
);
52 ASSERT(inherits(info()));
53 setInternalValue(vm
, jsNumber(timeClip(time
)));
56 void DateInstance::destroy(JSCell
* cell
)
58 static_cast<DateInstance
*>(cell
)->DateInstance::~DateInstance();
61 const GregorianDateTime
* DateInstance::calculateGregorianDateTime(ExecState
* exec
) const
63 double milli
= internalNumber();
64 if (std::isnan(milli
))
69 m_data
= vm
.dateInstanceCache
.add(milli
);
71 if (m_data
->m_gregorianDateTimeCachedForMS
!= milli
) {
72 msToGregorianDateTime(vm
, milli
, WTF::LocalTime
, m_data
->m_cachedGregorianDateTime
);
73 m_data
->m_gregorianDateTimeCachedForMS
= milli
;
75 return &m_data
->m_cachedGregorianDateTime
;
78 const GregorianDateTime
* DateInstance::calculateGregorianDateTimeUTC(ExecState
* exec
) const
80 double milli
= internalNumber();
81 if (std::isnan(milli
))
86 m_data
= vm
.dateInstanceCache
.add(milli
);
88 if (m_data
->m_gregorianDateTimeUTCCachedForMS
!= milli
) {
89 msToGregorianDateTime(vm
, milli
, WTF::UTCTime
, m_data
->m_cachedGregorianDateTimeUTC
);
90 m_data
->m_gregorianDateTimeUTCCachedForMS
= milli
;
92 return &m_data
->m_cachedGregorianDateTimeUTC
;