/*
 * The contents of this file are subject to the Netscape Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/NPL/

 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.

 * The Original Code is Rhino code, released
 * May 6, 1999.

 * The Initial Developer of the Original Code is Netscape
 * Communications Corporation.  Portions created by Netscape are
 * Copyright (C) 1997-1999 Netscape Communications Corporation. All
 * Rights Reserved.

 * Contributor(s): 

 * Alternatively, the contents of this file may be used under the
 * terms of the GNU Public License (the "GPL"), in which case the
 * provisions of the GPL are applicable instead of those above.
 * If you wish to allow use of your version of this file only
 * under the terms of the GPL and not to allow others to use your
 * version of this file under the NPL, indicate your decision by
 * deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL.  If you do not delete
 * the provisions above, a recipient may use your version of this
 * file under either the NPL or the GPL.
 */
/**
 * This class implements the Date native object.
 * See ECMA 15.9.
 */

#ifndef _JS_NATIVE_DATE_H_
#define _JS_NATIVE_DATE_H_

#include "js-scriptableobject.h"
#include "js-functionobject.h"

/* Classes */
class JSNativeDate: public JSScriptableObject {
    protected:
        static  const double            HalfTimeDomain = 8.64e15;
        static  const double            HoursPerDay = 24.0;
        static  const double            MinutesPerHour = 60.0;
        static  const double            SecondsPerMinute = 60.0;
        static  const double            msPerSecond = 1000.0;
        static  const double            MinutesPerDay
                                = (24.0 * 60.0);//(HoursPerDay * MinutesPerHour);
        static  const double            SecondsPerDay
                                = (24.0 * 60.0 * 60.0);//(MinutesPerDay * SecondsPerMinute);
        static  const double            SecondsPerHour
                                = (60.0 * 60.0);//(MinutesPerHour * SecondsPerMinute);
        static  const double            msPerDay
                                = (24.0 * 60.0 * 60.0 * 1000.0);
                                                //(SecondsPerDay * msPerSecond);
        static  const double            msPerHour
                                = (60.0 * 60.0 * 1000.0);//(SecondsPerHour * msPerSecond);
        static  const double            msPerMinute
                                = (60.0 * 1000.0);//(SecondsPerMinute * msPerSecond);
        static  const jsString_t        js_NaN_date_str;
        static  const jsString_t        days[7];
        static  const jsString_t        months[12];
        static  double                  LocalTZA; //This contains not only the time zone difference but also the daylight saving time.
        static  const int               MAXARGS = 7;

        double  date;

    public:
        static  const jsString_t        className;

    protected:
        static  void    finishInit(JSContext *cx, JSScriptable *scope,
                                JSFunctionObject *ctor, JSScriptable *proto);
        static  double  Day(double t);
        static  double  TimeWithinDay(double t);
        static  int     DaysInYear(int y);
        static  double  DayFromYear(double y);
        static  double  TimeFromYear(double y);
        static  int     YearFromTime(double t);
        static  jsBool_t
                        InLeapYear(double t);
        static  int     DayWithinYear(double t);
        static  double  DayFromMonth(int m, jsBool_t leap);
        static  int     MonthFromTime(double t);
        static  int     DateFromTime(double t);
        static  int     WeekDay(double t);
        static  double  Now();
        static  double  DaylightSavingTA(double t);
        static  double  LocalTime(double t);
        static  double  internalUTC(double t);
        static  int     HourFromTime(double t);
        static  int     MinFromTime(double t);
        static  int     SecFromTime(double t);
        static  int     msFromTime(double t);
        static  double  MakeTime(double hour, double min, double sec,
                                double ms);
        static  double  MakeDay(double year, double month, double date);
        static  double  MakeDate(double day, double time);
        static  double  TimeClip(double d);
        static  double  date_msecFromDate(double year, double mon,
                                double mday, double hour, double min,
                                double sec, double msec);
        static  jsBool_t
                        date_regionMatches(jsString_t s1, int s1off,
                                        jsString_t s2, int s2off, int count);
        static  double  date_parseString(jsString_t s);
        static  jsVal_t date_format(JSContext *cx, double t);
        static  JSNativeDate
                        *checkInstance(JSContext *cx, JSScriptable *obj,
                                JSFunction *funObj);
        static  double  makeTime(JSContext *cx, JSScriptable *dateObj,
                                int numArgs, jsVal_t *args, int maxargs,
                                jsBool_t local, JSFunction *funObj);
        static  double  makeDate(JSContext *cx, JSScriptable *dateObj,
                                int numArgs, jsVal_t *args, int maxargs,
                                jsBool_t local, JSFunction *funObj);

        /* JS methods */
        static  jsVal_t jsConstructor(JSContext *cx, int numArgs,
                                jsVal_t *args, JSFunction *ctorObj,
                                jsBool_t inNewExpr);
        static  jsVal_t jsFunction_setMilliseconds(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setUTCMilliseconds(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setSeconds(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setUTCSeconds(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setMinutes(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setUTCMinutes(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setHours(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setUTCHours(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setDate(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setUTCDate(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setMonth(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setUTCMonth(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setFullYear(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsFunction_setUTCFullYear(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);
        static  jsVal_t jsStaticFunction_UTC(JSContext *cx,
                                JSScriptable *thisObj, int numArgs,
                                jsVal_t *args, JSFunction *funObj);

    public:
        static  void    classInitialize();
        static  void    defineClass(JSContext *cx, JSScriptable *scope);

        /* JS methods */
        static  jsVal_t jsStaticFunction_parse(JSContext *cx, jsString_t s);

        JSNativeDate();

        /* JS methods */
        jsVal_t jsFunction_toString(JSContext *cx);
        jsVal_t jsFunction_toLocaleString(JSContext *cx);
        jsVal_t jsFunction_toUTCString(JSContext *cx);
        jsVal_t jsFunction_valueOf(JSContext *cx);
        jsVal_t jsFunction_getTime(JSContext *cx);
        jsVal_t jsFunction_getYear(JSContext *cx);
        jsVal_t jsFunction_getFullYear(JSContext *cx);
        jsVal_t jsFunction_getUTCFullYear(JSContext *cx);
        jsVal_t jsFunction_getMonth(JSContext *cx);
        jsVal_t jsFunction_getUTCMonth(JSContext *cx);
        jsVal_t jsFunction_getDate(JSContext *cx);
        jsVal_t jsFunction_getUTCDate(JSContext *cx);
        jsVal_t jsFunction_getDay(JSContext *cx);
        jsVal_t jsFunction_getUTCDay(JSContext *cx);
        jsVal_t jsFunction_getHours(JSContext *cx);
        jsVal_t jsFunction_getUTCHours(JSContext *cx);
        jsVal_t jsFunction_getMinutes(JSContext *cx);
        jsVal_t jsFunction_getUTCMinutes(JSContext *cx);
        jsVal_t jsFunction_getSeconds(JSContext *cx);
        jsVal_t jsFunction_getUTCSeconds(JSContext *cx);
        jsVal_t jsFunction_getMilliseconds(JSContext *cx);
        jsVal_t jsFunction_getUTCMilliseconds(JSContext *cx);
        jsVal_t jsFunction_getTimezoneOffset(JSContext *cx);
        jsVal_t jsFunction_setTime(JSContext *cx, double time);
        jsVal_t jsFunction_setYear(JSContext *cx, double year);

        /* Instanceof method */
        jsBool_t
                isInstanceOf(const jsString_t className);

        /* scriptable methods */
        jsString_t
                getClassName(JSContext *cx);
        jsVal_t getDefaultValue(JSContext *cx, jsType_t typeHint);
};

#endif /* _JS_NATIVE_DATE_H_ */
