source: webkit/trunk/JavaScriptCore/runtime/DateInstance.cpp@ 44711

Last change on this file since 44711 was 44513, checked in by Dimitri Glazkov, 16 years ago

2009-06-08 Dimitri Glazkov <Dimitri Glazkov>

Unreviewed, fix my previous fix.

  • runtime/DateInstance.cpp: (JSC::DateInstance::msToGregorianDateTime): Use WTF namespace qualifier to

disambiguate func signatures.

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
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
25#include <math.h>
26#include <wtf/DateMath.h>
27#include <wtf/MathExtras.h>
28
29using namespace WTF;
30
31namespace JSC {
32
33struct DateInstance::Cache {
34 double m_gregorianDateTimeCachedForMS;
35 GregorianDateTime m_cachedGregorianDateTime;
36 double m_gregorianDateTimeUTCCachedForMS;
37 GregorianDateTime m_cachedGregorianDateTimeUTC;
38};
39
40const ClassInfo DateInstance::info = {"Date", 0, 0, 0};
41
42DateInstance::DateInstance(PassRefPtr<Structure> structure)
43 : JSWrapperObject(structure)
44 , m_cache(0)
45{
46}
47
48DateInstance::~DateInstance()
49{
50 delete m_cache;
51}
52
53void DateInstance::msToGregorianDateTime(double milli, bool outputIsUTC, GregorianDateTime& t) const
54{
55 if (!m_cache) {
56 m_cache = new Cache;
57 m_cache->m_gregorianDateTimeCachedForMS = NaN;
58 m_cache->m_gregorianDateTimeUTCCachedForMS = NaN;
59 }
60
61 if (outputIsUTC) {
62 if (m_cache->m_gregorianDateTimeUTCCachedForMS != milli) {
63 WTF::msToGregorianDateTime(milli, true, m_cache->m_cachedGregorianDateTimeUTC);
64 m_cache->m_gregorianDateTimeUTCCachedForMS = milli;
65 }
66 t.copyFrom(m_cache->m_cachedGregorianDateTimeUTC);
67 } else {
68 if (m_cache->m_gregorianDateTimeCachedForMS != milli) {
69 WTF::msToGregorianDateTime(milli, false, m_cache->m_cachedGregorianDateTime);
70 m_cache->m_gregorianDateTimeCachedForMS = milli;
71 }
72 t.copyFrom(m_cache->m_cachedGregorianDateTime);
73 }
74}
75
76bool DateInstance::getTime(GregorianDateTime& t, int& offset) const
77{
78 double milli = internalNumber();
79 if (isnan(milli))
80 return false;
81
82 msToGregorianDateTime(milli, false, t);
83 offset = gmtoffset(t);
84 return true;
85}
86
87bool DateInstance::getUTCTime(GregorianDateTime& t) const
88{
89 double milli = internalNumber();
90 if (isnan(milli))
91 return false;
92
93 msToGregorianDateTime(milli, true, t);
94 return true;
95}
96
97bool DateInstance::getTime(double& milli, int& offset) const
98{
99 milli = internalNumber();
100 if (isnan(milli))
101 return false;
102
103 GregorianDateTime t;
104 msToGregorianDateTime(milli, false, t);
105 offset = gmtoffset(t);
106 return true;
107}
108
109bool DateInstance::getUTCTime(double& milli) const
110{
111 milli = internalNumber();
112 if (isnan(milli))
113 return false;
114
115 return true;
116}
117
118} // namespace JSC
Note: See TracBrowser for help on using the repository browser.