keep obsolete file in samba4 source directory.
[tprouty/samba.git] / source4 / lib / appweb / ejs-2.0 / ejs / classes / ejsDate.c
1 /*
2  *      @file   ejsStndClasses.c
3  *      @brief  EJS support methods
4  */
5 /********************************* Copyright **********************************/
6 /*
7  *      @copy   default
8  *      
9  *      Copyright (c) Mbedthis Software LLC, 2003-2006. All Rights Reserved.
10  *      Copyright (c) Michael O'Brien, 1994-1995. All Rights Reserved.
11  *      
12  *      This software is distributed under commercial and open source licenses.
13  *      You may use the GPL open source license described below or you may acquire 
14  *      a commercial license from Mbedthis Software. You agree to be fully bound 
15  *      by the terms of either license. Consult the LICENSE.TXT distributed with 
16  *      this software for full details.
17  *      
18  *      This software is open source; you can redistribute it and/or modify it 
19  *      under the terms of the GNU General Public License as published by the 
20  *      Free Software Foundation; either version 2 of the License, or (at your 
21  *      option) any later version. See the GNU General Public License for more 
22  *      details at: http://www.mbedthis.com/downloads/gplLicense.html
23  *      
24  *      This program is distributed WITHOUT ANY WARRANTY; without even the 
25  *      implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
26  *      
27  *      This GPL license does NOT permit incorporating this software into 
28  *      proprietary programs. If you are unable to comply with the GPL, you must
29  *      acquire a commercial license to use this software. Commercial licenses 
30  *      for this software and support services are available from Mbedthis 
31  *      Software at http://www.mbedthis.com 
32  *      
33  *      @end
34  */
35 /********************************** Includes **********************************/
36
37 #include        "ejs.h"
38
39 #if BLD_FEATURE_EJS && 0
40
41 /******************************************************************************/
42 /*
43  *      Date constructor
44
45  *
46  *      Date();
47  *      Date(milliseconds);
48  *      Date(dateString);
49  *      Date(year, month, date);
50  *      Date(year, month, date, hour, minute, second);
51  */
52
53 int ejsDateConstructor(Ejs *ep, EjsVar *thisObj, int argc, EjsVar **argv)
54 {
55         return 0;
56 }
57
58 /******************************************************************************/
59
60 static int load(Ejs *ep, EjsVar *thisObj, int argc, EjsVar **argv)
61 {
62         const char      *fileName;
63         XmlState        *parser;
64         Exml            *xp;
65         MprFile         *file;
66
67         if (argc != 1 || !ejsVarIsString(argv[0])) {
68                 ejsError(ep, EJS_ARG_ERROR, "Bad args. Usage: load(fileName);");
69                 return -1;
70         }
71         fileName = argv[0]->string;
72         
73         /* FUTURE -- not romable 
74                 Need rom code in MPR not MprServices
75         */
76         file = mprOpen(ep, fileName, O_RDONLY, 0664);
77         if (file == 0) {
78                 ejsError(ep, EJS_IO_ERROR, "Can't open: %s", fileName);
79                 return -1;
80         }
81
82         xp = initParser(ep, thisObj, fileName);
83         parser = exmlGetParseArg(xp);
84
85         exmlSetInputStream(xp, readFileData, (void*) file);
86
87         if (exmlParse(xp) < 0) {
88                 if (! ejsGotException(ep)) {
89                         ejsError(ep, EJS_IO_ERROR, "Can't parse XML file: %s\nDetails %s", 
90                                 fileName, exmlGetErrorMsg(xp));
91                 }
92                 termParser(xp);
93                 mprClose(file);
94                 return -1;
95         }
96
97         ejsSetReturnValue(ep, parser->nodeStack[0].obj);
98
99         termParser(xp);
100         mprClose(file);
101
102         return 0;
103 }
104
105 /******************************************************************************/
106
107 int ejsDefineDateClass(Ejs *ep)
108 {
109         EjsVar  *dateClass;
110
111         dateClass = ejsDefineClass(ep, "Date", "Object", ejsDateConstructor);
112         if (dateClass == 0) {
113                 return MPR_ERR_CANT_INITIALIZE;
114         }
115
116         ejsDefineCMethod(ep, dateClass, "getDate", xxxProc, EJS_NO_LOCAL);
117
118         /* Returns  "Friday" or 4 ? */
119         ejsDefineCMethod(ep, dateClass, "getDay", xxxProc, EJS_NO_LOCAL);
120
121         ejsDefineCMethod(ep, dateClass, "getMonth", xxxProc, EJS_NO_LOCAL);
122         ejsDefineCMethod(ep, dateClass, "getFullYear", xxxProc, EJS_NO_LOCAL);
123         ejsDefineCMethod(ep, dateClass, "getYear", xxxProc, EJS_NO_LOCAL);
124         ejsDefineCMethod(ep, dateClass, "getHours", xxxProc, EJS_NO_LOCAL);
125         ejsDefineCMethod(ep, dateClass, "getMinutes", xxxProc, EJS_NO_LOCAL);
126         ejsDefineCMethod(ep, dateClass, "getSeconds", xxxProc, EJS_NO_LOCAL);
127         ejsDefineCMethod(ep, dateClass, "getMilliseconds", xxxProc, EJS_NO_LOCAL);
128         ejsDefineCMethod(ep, dateClass, "getTime", xxxProc, EJS_NO_LOCAL);
129         ejsDefineCMethod(ep, dateClass, "getTimeZoneOffset", xxxProc, EJS_NO_LOCAL);
130
131         ejsDefineCMethod(ep, dateClass, "parse", xxxProc, EJS_NO_LOCAL);
132         ejsDefineCMethod(ep, dateClass, "setDate", xxxProc, EJS_NO_LOCAL);
133         ejsDefineCMethod(ep, dateClass, "setMonth", xxxProc, EJS_NO_LOCAL);
134         ejsDefineCMethod(ep, dateClass, "setFullYear", xxxProc, EJS_NO_LOCAL);
135         ejsDefineCMethod(ep, dateClass, "setYear", xxxProc, EJS_NO_LOCAL);
136         ejsDefineCMethod(ep, dateClass, "setMinutes", xxxProc, EJS_NO_LOCAL);
137         ejsDefineCMethod(ep, dateClass, "setSeconds", xxxProc, EJS_NO_LOCAL);
138         ejsDefineCMethod(ep, dateClass, "setMilliseconds", xxxProc, EJS_NO_LOCAL);
139         ejsDefineCMethod(ep, dateClass, "setTime", xxxProc, EJS_NO_LOCAL);
140
141         ejsDefineCMethod(ep, dateClass, "toString", xxxProc, EJS_NO_LOCAL);
142         ejsDefineCMethod(ep, dateClass, "toGMTString", xxxProc, EJS_NO_LOCAL);
143         ejsDefineCMethod(ep, dateClass, "toUTCString", xxxProc, EJS_NO_LOCAL);
144         ejsDefineCMethod(ep, dateClass, "toLocaleString", xxxProc, EJS_NO_LOCAL);
145         ejsDefineCMethod(ep, dateClass, "UTC", xxxProc, EJS_NO_LOCAL);
146         ejsDefineCMethod(ep, dateClass, "valueOf", xxxProc, EJS_NO_LOCAL);
147         /*
148                 UTC: getUTCDate, getUTCDay, getUTCMonth, getUTCFullYear, getUTCHours,
149                         getUTCMinutes, getUTCSeconds, getUTCMilliseconds
150                         setUTCDate, setUTCDay, setUTCMonth, setUTCFullYear, setUTCHours,
151                         setUTCMinutes, setUTCSeconds, setUTCMilliseconds
152          */
153
154         return ejsObjHasErrors(dateClass) ? MPR_ERR_CANT_INITIALIZE : 0;
155 }
156
157 /******************************************************************************/
158 /*
159         Time is since 1970/01/01 GMT
160
161         Normal: Fri Feb 10 2006 05:06:44 GMT-0800 (Pacific Standard Time)
162         UTC: Sat, 11 Feb 2006 05:06:44 GMT
163
164         //      Using without New
165
166         println(Date());
167
168         var myDate = new Date();
169         myDate.setFullYear(2010, 0, 14);
170
171         var today = new Date();
172
173         if (myDate > today) {
174         } else {
175         }
176
177
178          X=Date() should be equivalent to X=(new Date()).toString()
179
180  */
181 /******************************************************************************/
182
183 #else
184 void ejsStndClassesDummy() {}
185
186 /******************************************************************************/
187 #endif /* BLD_FEATURE_EJS */
188
189 /*
190  * Local variables:
191  * tab-width: 4
192  * c-basic-offset: 4
193  * End:
194  * vim:tw=78
195  * vim600: sw=4 ts=4 fdm=marker
196  * vim<600: sw=4 ts=4
197  */