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"
26 #include <wtf/DateMath.h>
27 #include <wtf/MathExtras.h>
33 struct DateInstance::Cache
{
34 double m_gregorianDateTimeCachedForMS
;
35 GregorianDateTime m_cachedGregorianDateTime
;
36 double m_gregorianDateTimeUTCCachedForMS
;
37 GregorianDateTime m_cachedGregorianDateTimeUTC
;
40 const ClassInfo
DateInstance::info
= {"Date", 0, 0, 0};
42 DateInstance::DateInstance(PassRefPtr
<Structure
> structure
)
43 : JSWrapperObject(structure
)
48 DateInstance::~DateInstance()
53 void DateInstance::msToGregorianDateTime(double milli
, bool outputIsUTC
, GregorianDateTime
& t
) const
57 m_cache
->m_gregorianDateTimeCachedForMS
= NaN
;
58 m_cache
->m_gregorianDateTimeUTCCachedForMS
= NaN
;
62 if (m_cache
->m_gregorianDateTimeUTCCachedForMS
!= milli
) {
63 WTF::msToGregorianDateTime(milli
, true, m_cache
->m_cachedGregorianDateTimeUTC
);
64 m_cache
->m_gregorianDateTimeUTCCachedForMS
= milli
;
66 t
.copyFrom(m_cache
->m_cachedGregorianDateTimeUTC
);
68 if (m_cache
->m_gregorianDateTimeCachedForMS
!= milli
) {
69 WTF::msToGregorianDateTime(milli
, false, m_cache
->m_cachedGregorianDateTime
);
70 m_cache
->m_gregorianDateTimeCachedForMS
= milli
;
72 t
.copyFrom(m_cache
->m_cachedGregorianDateTime
);
76 bool DateInstance::getTime(GregorianDateTime
& t
, int& offset
) const
78 double milli
= internalNumber();
82 msToGregorianDateTime(milli
, false, t
);
83 offset
= gmtoffset(t
);
87 bool DateInstance::getUTCTime(GregorianDateTime
& t
) const
89 double milli
= internalNumber();
93 msToGregorianDateTime(milli
, true, t
);
97 bool DateInstance::getTime(double& milli
, int& offset
) const
99 milli
= internalNumber();
104 msToGregorianDateTime(milli
, false, t
);
105 offset
= gmtoffset(t
);
109 bool DateInstance::getUTCTime(double& milli
) const
111 milli
= internalNumber();