1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQml module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39#ifndef QV4DATEOBJECT_P_H
40#define QV4DATEOBJECT_P_H
41
42//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists purely as an
47// implementation detail. This header file may change from version to
48// version without notice, or even be removed.
49//
50// We mean it.
51//
52
53#include "qv4object_p.h"
54#include "qv4functionobject_p.h"
55#include <QtCore/private/qnumeric_p.h>
56
57QT_BEGIN_NAMESPACE
58
59class QDateTime;
60
61namespace QV4 {
62
63namespace Heap {
64
65struct DateObject : Object {
66 void init()
67 {
68 Object::init();
69 date = qt_qnan();
70 }
71
72 void init(const Value &date)
73 {
74 Object::init();
75 this->date = date.toNumber();
76 }
77 void init(const QDateTime &date);
78 void init(const QTime &time);
79
80 double date;
81};
82
83
84struct DateCtor : FunctionObject {
85 void init(QV4::ExecutionContext *scope);
86};
87
88}
89
90struct DateObject: Object {
91 V4_OBJECT2(DateObject, Object)
92 Q_MANAGED_TYPE(DateObject)
93 V4_PROTOTYPE(datePrototype)
94
95
96 double date() const { return d()->date; }
97 void setDate(double date) { d()->date = date; }
98
99 Q_QML_PRIVATE_EXPORT QDateTime toQDateTime() const;
100};
101
102template<>
103inline const DateObject *Value::as() const {
104 return isManaged() && m()->internalClass->vtable->type == Managed::Type_DateObject ? static_cast<const DateObject *>(this) : nullptr;
105}
106
107struct DateCtor: FunctionObject
108{
109 V4_OBJECT2(DateCtor, FunctionObject)
110
111 static ReturnedValue virtualCallAsConstructor(const FunctionObject *, const Value *argv, int argc, const Value *);
112 static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int);
113};
114
115struct DatePrototype: Object
116{
117 V4_PROTOTYPE(objectPrototype)
118
119 void init(ExecutionEngine *engine, Object *ctor);
120
121 static double getThisDate(ExecutionEngine *v4, const Value *thisObject);
122
123 static ReturnedValue method_parse(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
124 static ReturnedValue method_UTC(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
125 static ReturnedValue method_now(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
126
127 static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
128 static ReturnedValue method_toDateString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
129 static ReturnedValue method_toTimeString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
130 static ReturnedValue method_toLocaleString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
131 static ReturnedValue method_toLocaleDateString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
132 static ReturnedValue method_toLocaleTimeString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
133 static ReturnedValue method_valueOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
134 static ReturnedValue method_getTime(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
135 static ReturnedValue method_getYear(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
136 static ReturnedValue method_getFullYear(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
137 static ReturnedValue method_getUTCFullYear(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
138 static ReturnedValue method_getMonth(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
139 static ReturnedValue method_getUTCMonth(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
140 static ReturnedValue method_getDate(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
141 static ReturnedValue method_getUTCDate(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
142 static ReturnedValue method_getDay(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
143 static ReturnedValue method_getUTCDay(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
144 static ReturnedValue method_getHours(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
145 static ReturnedValue method_getUTCHours(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
146 static ReturnedValue method_getMinutes(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
147 static ReturnedValue method_getUTCMinutes(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
148 static ReturnedValue method_getSeconds(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
149 static ReturnedValue method_getUTCSeconds(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
150 static ReturnedValue method_getMilliseconds(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
151 static ReturnedValue method_getUTCMilliseconds(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
152 static ReturnedValue method_getTimezoneOffset(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
153 static ReturnedValue method_setTime(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
154 static ReturnedValue method_setMilliseconds(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
155 static ReturnedValue method_setUTCMilliseconds(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
156 static ReturnedValue method_setSeconds(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
157 static ReturnedValue method_setUTCSeconds(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
158 static ReturnedValue method_setMinutes(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
159 static ReturnedValue method_setUTCMinutes(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
160 static ReturnedValue method_setHours(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
161 static ReturnedValue method_setUTCHours(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
162 static ReturnedValue method_setDate(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
163 static ReturnedValue method_setUTCDate(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
164 static ReturnedValue method_setMonth(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
165 static ReturnedValue method_setUTCMonth(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
166 static ReturnedValue method_setYear(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
167 static ReturnedValue method_setFullYear(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
168 static ReturnedValue method_setUTCFullYear(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
169 static ReturnedValue method_toUTCString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
170 static ReturnedValue method_toISOString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
171 static ReturnedValue method_toJSON(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
172 static ReturnedValue method_symbolToPrimitive(const FunctionObject *f, const Value *thisObject, const Value *, int);
173
174 static void timezoneUpdated(ExecutionEngine *e);
175};
176
177}
178
179QT_END_NAMESPACE
180
181#endif // QV4ECMAOBJECTS_P_H
182

source code of qtdeclarative/src/qml/jsruntime/qv4dateobject_p.h