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"
27 #include <wtf/MathExtras.h>
31 struct DateInstance::Cache
{
32 double m_gregorianDateTimeCachedForMS
;
33 GregorianDateTime m_cachedGregorianDateTime
;
34 double m_gregorianDateTimeUTCCachedForMS
;
35 GregorianDateTime m_cachedGregorianDateTimeUTC
;
38 const ClassInfo
DateInstance::info
= {"Date", 0, 0, 0};
40 DateInstance::DateInstance(PassRefPtr
<Structure
> structure
)
41 : JSWrapperObject(structure
)
46 DateInstance::~DateInstance()
51 void DateInstance::msToGregorianDateTime(double milli
, bool outputIsUTC
, GregorianDateTime
& t
) const
55 m_cache
->m_gregorianDateTimeCachedForMS
= NaN
;
56 m_cache
->m_gregorianDateTimeUTCCachedForMS
= NaN
;
60 if (m_cache
->m_gregorianDateTimeUTCCachedForMS
!= milli
) {
61 JSC::msToGregorianDateTime(milli
, true, m_cache
->m_cachedGregorianDateTimeUTC
);
62 m_cache
->m_gregorianDateTimeUTCCachedForMS
= milli
;
64 t
.copyFrom(m_cache
->m_cachedGregorianDateTimeUTC
);
66 if (m_cache
->m_gregorianDateTimeCachedForMS
!= milli
) {
67 JSC::msToGregorianDateTime(milli
, false, m_cache
->m_cachedGregorianDateTime
);
68 m_cache
->m_gregorianDateTimeCachedForMS
= milli
;
70 t
.copyFrom(m_cache
->m_cachedGregorianDateTime
);
74 bool DateInstance::getTime(GregorianDateTime
& t
, int& offset
) const
76 double milli
= internalNumber();
80 msToGregorianDateTime(milli
, false, t
);
81 offset
= gmtoffset(t
);
85 bool DateInstance::getUTCTime(GregorianDateTime
& t
) const
87 double milli
= internalNumber();
91 msToGregorianDateTime(milli
, true, t
);
95 bool DateInstance::getTime(double& milli
, int& offset
) const
97 milli
= internalNumber();
102 msToGregorianDateTime(milli
, false, t
);
103 offset
= gmtoffset(t
);
107 bool DateInstance::getUTCTime(double& milli
) const
109 milli
= internalNumber();