date_object.h
00001 // -*- c-basic-offset: 2 -*- 00002 /* 00003 * This file is part of the KDE libraries 00004 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 */ 00021 00022 #ifndef _DATE_OBJECT_H_ 00023 #define _DATE_OBJECT_H_ 00024 00025 #include "internal.h" 00026 #include "function_object.h" 00027 00028 namespace KJS { 00029 00030 class DateInstanceImp : public ObjectImp { 00031 public: 00032 DateInstanceImp(ObjectImp *proto); 00033 00034 virtual const ClassInfo *classInfo() const { return &info; } 00035 static const ClassInfo info; 00036 }; 00037 00044 class DatePrototypeImp : public DateInstanceImp { 00045 public: 00046 DatePrototypeImp(ExecState *exec, ObjectPrototypeImp *objectProto); 00047 Value get(ExecState *exec, const Identifier &p) const; 00048 virtual const ClassInfo *classInfo() const { return &info; } 00049 static const ClassInfo info; 00050 }; 00051 00058 class DateProtoFuncImp : public InternalFunctionImp { 00059 public: 00060 DateProtoFuncImp(ExecState *exec, int i, int len); 00061 00062 virtual bool implementsCall() const; 00063 virtual Value call(ExecState *exec, Object &thisObj, const List &args); 00064 00065 00066 Completion execute(const List &); 00067 enum { ToString, ToDateString, ToTimeString, ToLocaleString, 00068 ToLocaleDateString, ToLocaleTimeString, ValueOf, GetTime, 00069 GetFullYear, GetMonth, GetDate, GetDay, GetHours, GetMinutes, 00070 GetSeconds, GetMilliSeconds, GetTimezoneOffset, SetTime, 00071 SetMilliSeconds, SetSeconds, SetMinutes, SetHours, SetDate, 00072 SetMonth, SetFullYear, ToUTCString, 00073 // non-normative properties (Appendix B) 00074 GetYear, SetYear, ToGMTString }; 00075 private: 00076 short id; 00077 bool utc; 00078 }; 00079 00085 class DateObjectImp : public InternalFunctionImp { 00086 public: 00087 DateObjectImp(ExecState *exec, 00088 FunctionPrototypeImp *funcProto, 00089 DatePrototypeImp *dateProto); 00090 00091 virtual bool implementsConstruct() const; 00092 virtual Object construct(ExecState *exec, const List &args); 00093 virtual bool implementsCall() const; 00094 virtual Value call(ExecState *exec, Object &thisObj, const List &args); 00095 00096 Completion execute(const List &); 00097 Object construct(const List &); 00098 }; 00099 00106 class DateObjectFuncImp : public InternalFunctionImp { 00107 public: 00108 DateObjectFuncImp(ExecState *exec, FunctionPrototypeImp *funcProto, 00109 int i, int len); 00110 00111 virtual bool implementsCall() const; 00112 virtual Value call(ExecState *exec, Object &thisObj, const List &args); 00113 00114 enum { Parse, UTC }; 00115 private: 00116 int id; 00117 }; 00118 00119 // helper functions 00120 double parseDate(const UString &u); 00121 double KRFCDate_parseDate(const UString &_date); 00122 double timeClip(double t); 00123 double makeTime(struct tm *t, double milli, bool utc); 00124 00125 } // namespace 00126 00127 #endif