1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
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 USA
18 *
19 */
20
21#ifndef DATE_OBJECT_H
22#define DATE_OBJECT_H
23
24#include "function.h"
25#include "JSWrapperObject.h"
26
27struct tm;
28
29namespace KJS {
30
31 class FunctionPrototype;
32 class ObjectPrototype;
33
34 class DateInstance : public JSWrapperObject {
35 public:
36 DateInstance(JSObject *proto);
37
38 bool getTime(tm &t, int &gmtoffset) const;
39 bool getUTCTime(tm &t) const;
40 bool getTime(double &ms, int &gmtoffset) const;
41 bool getUTCTime(double &ms) const;
42
43 virtual const ClassInfo *classInfo() const { return &info; }
44 static const ClassInfo info;
45
46 virtual JSObject* valueClone(Interpreter* targetCtx) const;
47 };
48
49 /**
50 * @internal
51 *
52 * The initial value of Date.prototype (and thus all objects created
53 * with the Date constructor
54 */
55 class DatePrototype : public DateInstance {
56 public:
57 DatePrototype(ExecState *, ObjectPrototype *);
58 using KJS::JSObject::getOwnPropertySlot;
59 virtual bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot&);
60 virtual const ClassInfo *classInfo() const { return &info; }
61 static const ClassInfo info;
62 };
63
64 /**
65 * @internal
66 *
67 * Class to implement all methods that are properties of the
68 * Date.prototype object
69 */
70 class DateProtoFunc : public InternalFunctionImp {
71 public:
72 DateProtoFunc(ExecState *, int i, int len, const Identifier& date);
73
74 virtual JSValue *callAsFunction(ExecState *, JSObject *thisObj, const List &args);
75
76 enum { ToString, ToDateString, ToTimeString, ToLocaleString,
77 ToLocaleDateString, ToLocaleTimeString, ValueOf, GetTime,
78 GetFullYear, GetMonth, GetDate, GetDay, GetHours, GetMinutes,
79 GetSeconds, GetMilliSeconds, GetTimezoneOffset, SetTime,
80 SetMilliSeconds, SetSeconds, SetMinutes, SetHours, SetDate,
81 SetMonth, SetFullYear, ToUTCString, ToISOString, ToJSON,
82 // non-normative properties (Appendix B)
83 GetYear, SetYear, ToGMTString };
84 private:
85 short id;
86 bool utc;
87 };
88
89 /**
90 * @internal
91 *
92 * The initial value of the global variable's "Date" property
93 */
94 class DateObjectImp : public InternalFunctionImp {
95 using InternalFunctionImp::construct;
96 public:
97 DateObjectImp(ExecState *, FunctionPrototype *, DatePrototype *);
98
99 virtual bool implementsConstruct() const;
100 virtual JSObject *construct(ExecState *, const List &args);
101 virtual JSValue *callAsFunction(ExecState *, JSObject *thisObj, const List &args);
102
103 Completion execute(const List &);
104 JSObject *construct(const List &);
105 };
106
107} // namespace
108
109#endif
110