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

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

JavaScriptCore:

2009-06-08 Dimitri Glazkov <Dimitri Glazkov>

Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=26238
Move most of runtime/DateMath functions to wtf/DateMath, and split off conversion-related
helpers to DateConversion.

  • AllInOneFile.cpp: Changed DateMath->DateConversion.
  • GNUmakefile.am: Ditto and added DateMath.
  • JavaScriptCore.exp: Ditto.
  • JavaScriptCore.pri: Ditto.
  • JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj: Ditto.
  • JavaScriptCore.vcproj/WTF/WTF.vcproj: Added DateMath.
  • JavaScriptCore.xcodeproj/project.pbxproj: Ditto.
  • JavaScriptCoreSources.bkl: Ditto.
  • pcre/pcre_exec.cpp: Changed to use DateMath.
  • profiler/ProfileNode.cpp: (JSC::getCount): Changed to use DateConversion.
  • runtime/DateConstructor.cpp: Ditto.
  • runtime/DateConversion.cpp: Copied from JavaScriptCore/runtime/DateMath.cpp. (JSC::parseDate): Refactored to use null-terminated characters as input.
  • runtime/DateConversion.h: Copied from JavaScriptCore/runtime/DateMath.h.
  • runtime/DateInstance.cpp: Changed to use wtf/DateMath.
  • runtime/DateInstance.h: Ditto.
  • runtime/DateMath.cpp: Removed.
  • runtime/DateMath.h: Removed.
  • runtime/DatePrototype.cpp: Ditto.
  • runtime/InitializeThreading.cpp: Ditto.
  • wtf/DateMath.cpp: Copied from JavaScriptCore/runtime/DateMath.cpp.
  • wtf/DateMath.h: Copied from JavaScriptCore/runtime/DateMath.h.

WebCore:

2009-06-08 Dimitri Glazkov <Dimitri Glazkov>

Reviewed by Eric Seidel.

https://bugs.webkit.org/show_bug.cgi?id=26238
Add parseDate helper to HTTPParsers, which uses WTF::parseDateFromNullTerminatedCharacters.

  • ForwardingHeaders/runtime/DateMath.h: Removed.
  • ForwardingHeaders/wtf/DateMath.h: Copied from WebCore/ForwardingHeaders/runtime/DateMath.h.
  • platform/network/HTTPParsers.cpp: (WebCore::parseDate): Added.
  • platform/network/HTTPParsers.h:
  • platform/network/ResourceResponseBase.cpp: (WebCore::parseDateValueInHeader): Changed to use the new helper.
  • 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
29namespace JSC {
30
31struct DateInstance::Cache {
32 double m_gregorianDateTimeCachedForMS;
33 GregorianDateTime m_cachedGregorianDateTime;
34 double m_gregorianDateTimeUTCCachedForMS;
35 GregorianDateTime m_cachedGregorianDateTimeUTC;
36};
37
38const ClassInfo DateInstance::info = {"Date", 0, 0, 0};
39
40DateInstance::DateInstance(PassRefPtr<Structure> structure)
41 : JSWrapperObject(structure)
42 , m_cache(0)
43{
44}
45
46DateInstance::~DateInstance()
47{
48 delete m_cache;
49}
50
51void DateInstance::msToGregorianDateTime(double milli, bool outputIsUTC, GregorianDateTime& t) const
52{
53 if (!m_cache) {
54 m_cache = new Cache;
55 m_cache->m_gregorianDateTimeCachedForMS = NaN;
56 m_cache->m_gregorianDateTimeUTCCachedForMS = NaN;
57 }
58
59 if (outputIsUTC) {
60 if (m_cache->m_gregorianDateTimeUTCCachedForMS != milli) {
61 WTF::msToGregorianDateTime(milli, true, m_cache->m_cachedGregorianDateTimeUTC);
62 m_cache->m_gregorianDateTimeUTCCachedForMS = milli;
63 }
64 t.copyFrom(m_cache->m_cachedGregorianDateTimeUTC);
65 } else {
66 if (m_cache->m_gregorianDateTimeCachedForMS != milli) {
67 WTF::msToGregorianDateTime(milli, false, m_cache->m_cachedGregorianDateTime);
68 m_cache->m_gregorianDateTimeCachedForMS = milli;
69 }
70 t.copyFrom(m_cache->m_cachedGregorianDateTime);
71 }
72}
73
74bool DateInstance::getTime(GregorianDateTime& t, int& offset) const
75{
76 double milli = internalNumber();
77 if (isnan(milli))
78 return false;
79
80 msToGregorianDateTime(milli, false, t);
81 offset = gmtoffset(t);
82 return true;
83}
84
85bool DateInstance::getUTCTime(GregorianDateTime& t) const
86{
87 double milli = internalNumber();
88 if (isnan(milli))
89 return false;
90
91 msToGregorianDateTime(milli, true, t);
92 return true;
93}
94
95bool DateInstance::getTime(double& milli, int& offset) const
96{
97 milli = internalNumber();
98 if (isnan(milli))
99 return false;
100
101 GregorianDateTime t;
102 msToGregorianDateTime(milli, false, t);
103 offset = gmtoffset(t);
104 return true;
105}
106
107bool DateInstance::getUTCTime(double& milli) const
108{
109 milli = internalNumber();
110 if (isnan(milli))
111 return false;
112
113 return true;
114}
115
116} // namespace JSC
Note: See TracBrowser for help on using the repository browser.