1/*
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
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 "JSGlobalObject.h"
26
27#include <wtf/DateMath.h>
28#include <wtf/MathExtras.h>
29
30using namespace WTF;
31
32namespace JSC {
33
34const ClassInfo DateInstance::info = {.className: "Date", .parentClass: 0, .staticPropHashTable: 0, .classPropHashTableGetterFunction: 0};
35
36DateInstance::DateInstance(ExecState* exec, NonNullPassRefPtr<Structure> structure)
37 : JSWrapperObject(structure)
38{
39 setInternalValue(jsNaN(exec));
40}
41
42DateInstance::DateInstance(ExecState* exec, double time)
43 : JSWrapperObject(exec->lexicalGlobalObject()->dateStructure())
44{
45 setInternalValue(jsNumber(exec, d: timeClip(time)));
46}
47
48const GregorianDateTime* DateInstance::calculateGregorianDateTime(ExecState* exec) const
49{
50 double milli = internalNumber();
51 if (std::isnan(x: milli))
52 return 0;
53
54 if (!m_data)
55 m_data = exec->globalData().dateInstanceCache.add(d: milli);
56
57 if (m_data->m_gregorianDateTimeCachedForMS != milli) {
58 msToGregorianDateTime(exec, milli, outputIsUTC: false, m_data->m_cachedGregorianDateTime);
59 m_data->m_gregorianDateTimeCachedForMS = milli;
60 }
61 return &m_data->m_cachedGregorianDateTime;
62}
63
64const GregorianDateTime* DateInstance::calculateGregorianDateTimeUTC(ExecState* exec) const
65{
66 double milli = internalNumber();
67 if (std::isnan(x: milli))
68 return 0;
69
70 if (!m_data)
71 m_data = exec->globalData().dateInstanceCache.add(d: milli);
72
73 if (m_data->m_gregorianDateTimeUTCCachedForMS != milli) {
74 msToGregorianDateTime(exec, milli, outputIsUTC: true, m_data->m_cachedGregorianDateTimeUTC);
75 m_data->m_gregorianDateTimeUTCCachedForMS = milli;
76 }
77 return &m_data->m_cachedGregorianDateTimeUTC;
78}
79
80} // namespace JSC
81

source code of qtscript/src/3rdparty/javascriptcore/JavaScriptCore/runtime/DateInstance.cpp