5 // Cesar Lopez Nataren (cesar@ciencias.unam.mx)
7 // (C) Cesar Lopez Nataren
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Globalization;
34 namespace Microsoft.JScript {
36 public class DatePrototype : DateObject
38 internal DatePrototype ()
43 internal static DatePrototype Proto = new DatePrototype ();
45 public static DateConstructor constructor {
46 get { return DateConstructor.Ctr; }
49 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getDate)]
50 public static double getDate (object thisObj)
52 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
54 DateObject date = (DateObject) thisObj;
57 if (Double.IsNaN (val))
60 return DateConstructor.DateFromTime (DateConstructor.LocalTime (val));
63 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getDay)]
64 public static double getDay (object thisObj)
66 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
68 DateObject date = (DateObject) thisObj;
71 if (Double.IsNaN (val))
74 return DateConstructor.WeekDay (DateConstructor.LocalTime (val));
77 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getFullYear)]
78 public static double getFullYear (object thisObj)
80 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
82 DateObject date = (DateObject) thisObj;
85 if (Double.IsNaN (val))
88 return DateConstructor.YearFromTime (DateConstructor.LocalTime (val));
91 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getHours)]
92 public static double getHours (object thisObj)
94 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
96 DateObject date = (DateObject) thisObj;
99 if (Double.IsNaN (val))
102 return DateConstructor.HourFromTime (DateConstructor.LocalTime (val));
105 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getMilliseconds)]
106 public static double getMilliseconds (object thisObj)
108 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
110 DateObject date = (DateObject) thisObj;
111 double val = date.ms;
113 if (Double.IsNaN (val))
116 return DateConstructor.msFromTime (DateConstructor.LocalTime (val));
119 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getMinutes)]
120 public static double getMinutes (object thisObj)
122 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
124 DateObject date = (DateObject) thisObj;
125 double val = date.ms;
127 if (Double.IsNaN (val))
130 return DateConstructor.MinFromTime (DateConstructor.LocalTime (val));
133 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getMonth)]
134 public static double getMonth (object thisObj)
136 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
138 DateObject date = (DateObject) thisObj;
139 double val = date.ms;
141 if (Double.IsNaN (val))
144 return DateConstructor.MonthFromTime (DateConstructor.LocalTime (val));
147 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getSeconds)]
148 public static double getSeconds (object thisObj)
150 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
152 DateObject date = (DateObject) thisObj;
153 double val = date.ms;
155 if (Double.IsNaN (val))
158 return DateConstructor.SecFromTime (DateConstructor.LocalTime (val));
161 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getTime)]
162 public static double getTime (object thisObj)
164 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
165 DateObject date = (DateObject) thisObj;
169 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getTimezoneOffset)]
170 public static double getTimezoneOffset (object thisObj)
172 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
174 DateObject date = (DateObject) thisObj;
175 double val = date.ms;
177 if (Double.IsNaN (val))
180 return (val - DateConstructor.LocalTime (val)) / DateConstructor.MS_PER_MINUTE;
183 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getUTCDate)]
184 public static double getUTCDate (object thisObj)
186 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
188 DateObject date = (DateObject) thisObj;
189 double val = date.ms;
191 if (Double.IsNaN (val))
194 return DateConstructor.DateFromTime (val);
197 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getUTCDay)]
198 public static double getUTCDay (object thisObj)
200 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
202 DateObject date = (DateObject) thisObj;
203 double val = date.ms;
205 if (Double.IsNaN (val))
208 return DateConstructor.WeekDay (val);
211 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getUTCFullYear)]
212 public static double getUTCFullYear (object thisObj)
214 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
216 DateObject date = (DateObject) thisObj;
217 double val = date.ms;
219 if (Double.IsNaN (val))
222 return DateConstructor.YearFromTime (val);
225 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getUTCHours)]
226 public static double getUTCHours (object thisObj)
228 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
230 DateObject date = (DateObject) thisObj;
231 double val = date.ms;
233 if (Double.IsNaN (val))
236 return DateConstructor.HourFromTime (val);
239 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getUTCMilliseconds)]
240 public static double getUTCMilliseconds (object thisObj)
242 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
244 DateObject date = (DateObject) thisObj;
245 double val = date.ms;
247 if (Double.IsNaN (val))
250 return DateConstructor.msFromTime (val);
253 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getUTCMinutes)]
254 public static double getUTCMinutes (object thisObj)
256 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
258 DateObject date = (DateObject) thisObj;
259 double val = date.ms;
261 if (Double.IsNaN (val))
264 return DateConstructor.MinFromTime (val);
267 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getUTCMonth)]
268 public static double getUTCMonth (object thisObj)
270 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
272 DateObject date = (DateObject) thisObj;
273 double val = date.ms;
275 if (Double.IsNaN (val))
278 return DateConstructor.MonthFromTime (val);
281 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getUTCSeconds)]
282 public static double getUTCSeconds (object thisObj)
284 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
286 DateObject date = (DateObject) thisObj;
287 double val = date.ms;
289 if (Double.IsNaN (val))
292 return DateConstructor.SecFromTime (val);
295 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getVarDate)]
296 public static object getVarDate (object thisObj)
299 // FIXME: This seems to handle the most simple
300 // cases, but surely we need to do more
301 // to comply with Microsoft's implementation.
307 // Note: This method is obsolete, but users might
308 // accidently use it instead of getFullYear(). The
309 // standard says to return the year - 1900 (likely for
310 // compatibility), but in this case not confusing the
311 // user's expectations is more important than not
312 // breaking obsolete code.
314 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_getYear)]
315 public static double getYear (object thisObj)
317 return getFullYear (thisObj);
320 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setDate)]
321 public static double setDate (object thisObj, double ddate)
323 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
324 DateObject date = (DateObject) thisObj;
325 double t = DateConstructor.LocalTime (date.ms);
326 double day = DateConstructor.MakeDay ((double) DateConstructor.YearFromTime (t),
327 (double) DateConstructor.MonthFromTime (t), ddate);
328 double new_val = DateConstructor.ToUTC (DateConstructor.MakeDate (day, t % DateConstructor.MS_PER_DAY));
329 date.ms = DateConstructor.TimeClip (new_val);
333 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setFullYear)]
334 public static double setFullYear (object thisObj, double dyear,
335 object month, object date)
337 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
338 DateObject dt = (DateObject) thisObj;
339 double t = DateConstructor.LocalTime (dt.ms);
340 if (Double.IsNaN (t))
345 new_month = DateConstructor.MonthFromTime (t);
347 new_month = Convert.ToNumber (month);
351 new_date = DateConstructor.DateFromTime (t);
353 new_date = Convert.ToNumber (date);
355 double day = DateConstructor.MakeDay (dyear, new_month, new_date);
356 double new_val = DateConstructor.ToUTC (DateConstructor.MakeDate (day, t % DateConstructor.MS_PER_DAY));
357 dt.ms = DateConstructor.TimeClip (new_val);
361 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setHours)]
362 public static double setHours (object thisObj, double dhour, object min,
363 object sec, object msec)
365 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
366 DateObject date = (DateObject) thisObj;
367 double t = DateConstructor.LocalTime (date.ms);
371 new_min = DateConstructor.MinFromTime (t);
373 new_min = Convert.ToNumber (min);
377 new_sec = DateConstructor.SecFromTime (t);
379 new_sec = Convert.ToNumber (sec);
383 new_ms = DateConstructor.msFromTime (t);
385 new_ms = Convert.ToNumber (msec);
387 double time = DateConstructor.MakeTime (dhour, new_min, new_sec, new_ms);
388 double day = Math.Floor (t / DateConstructor.MS_PER_DAY);
389 double new_val = DateConstructor.ToUTC (DateConstructor.MakeDate (day, time));
390 date.ms = DateConstructor.TimeClip (new_val);
394 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setMinutes)]
395 public static double setMinutes (object thisObj, double dmin,
396 object sec, object msec)
398 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
399 DateObject date = (DateObject) thisObj;
400 double t = DateConstructor.LocalTime (date.ms);
404 new_sec = DateConstructor.SecFromTime (t);
406 new_sec = Convert.ToNumber (sec);
410 new_ms = DateConstructor.msFromTime (t);
412 new_ms = Convert.ToNumber (msec);
414 double time = DateConstructor.MakeTime (DateConstructor.HourFromTime (t), dmin, new_sec, new_ms);
415 double day = Math.Floor (t / DateConstructor.MS_PER_DAY);
416 double new_val = DateConstructor.ToUTC (DateConstructor.MakeDate (day, time));
417 date.ms = DateConstructor.TimeClip (new_val);
421 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setMilliseconds)]
422 public static double setMilliseconds (object thisObj, double dmsec)
424 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
425 DateObject date = (DateObject) thisObj;
426 double t = DateConstructor.LocalTime (date.ms);
427 double time = DateConstructor.MakeTime (DateConstructor.HourFromTime (t), DateConstructor.MinFromTime (t),
428 DateConstructor.SecFromTime (t), dmsec);
429 double day = Math.Floor (t / DateConstructor.MS_PER_DAY);
430 double new_val = DateConstructor.ToUTC (DateConstructor.MakeDate (day, time));
431 date.ms = DateConstructor.TimeClip (new_val);
435 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setMonth)]
436 public static double setMonth (object thisObj, double dmonth,
439 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
440 DateObject dt = (DateObject) thisObj;
441 double t = DateConstructor.LocalTime (dt.ms);
445 new_date = DateConstructor.DateFromTime (t);
447 new_date = Convert.ToNumber (date);
449 double day = DateConstructor.MakeDay ((double) DateConstructor.YearFromTime (t),
451 double new_val = DateConstructor.ToUTC (DateConstructor.MakeDate (day, t % DateConstructor.MS_PER_DAY));
452 dt.ms = DateConstructor.TimeClip (new_val);
456 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject,
457 JSBuiltin.Date_setSeconds)]
458 public static double setSeconds (object thisObj, double dsec, object msec)
460 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
461 DateObject date = (DateObject) thisObj;
462 double t = DateConstructor.LocalTime (date.ms);
466 new_ms = DateConstructor.msFromTime (t);
468 new_ms = Convert.ToNumber (msec);
470 double time = DateConstructor.MakeTime (DateConstructor.HourFromTime (t), DateConstructor.MinFromTime (t),
472 double day = Math.Floor (t / DateConstructor.MS_PER_DAY);
473 double new_val = DateConstructor.ToUTC (DateConstructor.MakeDate (day, time));
474 date.ms = DateConstructor.TimeClip (new_val);
478 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setTime)]
479 public static double setTime (object thisObj, double time)
481 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
482 DateObject date = (DateObject) thisObj;
483 date.ms = DateConstructor.TimeClip (time);
487 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setUTCDate)]
488 public static double setUTCDate (object thisObj, double ddate)
490 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
491 DateObject date = (DateObject) thisObj;
493 double day = DateConstructor.MakeDay ((double) DateConstructor.YearFromTime (t),
494 (double) DateConstructor.MonthFromTime (t), ddate);
495 double new_val = DateConstructor.MakeDate (day, t % DateConstructor.MS_PER_DAY);
496 date.ms = DateConstructor.TimeClip (new_val);
500 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setUTCFullYear)]
501 public static double setUTCFullYear (object thisObj, double dyear,
502 object month, object date)
504 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
505 DateObject dt = (DateObject) thisObj;
507 if (Double.IsNaN (t))
512 new_month = DateConstructor.MonthFromTime (t);
514 new_month = Convert.ToNumber (month);
518 new_date = DateConstructor.DateFromTime (t);
520 new_date = Convert.ToNumber (date);
522 double day = DateConstructor.MakeDay (dyear, new_month, new_date);
523 double new_val = DateConstructor.MakeDate (day, t % DateConstructor.MS_PER_DAY);
524 dt.ms = DateConstructor.TimeClip (new_val);
528 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setUTCHours)]
529 public static double setUTCHours (object thisObj, double dhour,
530 object min, object sec, object msec)
532 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
533 DateObject date = (DateObject) thisObj;
538 new_min = DateConstructor.MinFromTime (t);
540 new_min = Convert.ToNumber (min);
544 new_sec = DateConstructor.SecFromTime (t);
546 new_sec = Convert.ToNumber (sec);
550 new_ms = DateConstructor.msFromTime (t);
552 new_ms = Convert.ToNumber (msec);
554 double time = DateConstructor.MakeTime (dhour, new_min, new_sec, new_ms);
555 double day = Math.Floor (t / DateConstructor.MS_PER_DAY);
556 double new_val = DateConstructor.MakeDate (day, time);
557 date.ms = DateConstructor.TimeClip (new_val);
561 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setUTCMinutes)]
562 public static double setUTCMinutes (object thisObj, double dmin,
563 object sec, object msec)
565 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
566 DateObject date = (DateObject) thisObj;
571 new_sec = DateConstructor.SecFromTime (t);
573 new_sec = Convert.ToNumber (sec);
577 new_ms = DateConstructor.msFromTime (t);
579 new_ms = Convert.ToNumber (msec);
581 double time = DateConstructor.MakeTime (DateConstructor.HourFromTime (t), dmin, new_sec, new_ms);
582 double day = Math.Floor (t / DateConstructor.MS_PER_DAY);
583 double new_val = DateConstructor.MakeDate (day, time);
584 date.ms = DateConstructor.TimeClip (new_val);
588 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setUTCMilliseconds)]
589 public static double setUTCMilliseconds (object thisObj, double msec)
591 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
592 DateObject date = (DateObject) thisObj;
594 double time = DateConstructor.MakeTime (DateConstructor.HourFromTime (t), DateConstructor.MinFromTime (t),
595 DateConstructor.SecFromTime (t), msec);
596 double day = Math.Floor (t / DateConstructor.MS_PER_DAY);
597 double new_val = DateConstructor.MakeDate (day, time);
598 date.ms = DateConstructor.TimeClip (new_val);
602 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setUTCMonth)]
603 public static double setUTCMonth (object thisObj, double dmonth, object date)
605 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
606 DateObject dt = (DateObject) thisObj;
611 new_date = DateConstructor.DateFromTime (t);
613 new_date = Convert.ToNumber (date);
615 double day = DateConstructor.MakeDay ((double) DateConstructor.YearFromTime (t),
617 double new_val = DateConstructor.MakeDate (day, t % DateConstructor.MS_PER_DAY);
618 dt.ms = DateConstructor.TimeClip (new_val);
622 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setUTCSeconds)]
623 public static double setUTCSeconds (object thisObj, double dsec, object msec)
625 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
626 DateObject date = (DateObject) thisObj;
631 new_ms = DateConstructor.msFromTime (t);
633 new_ms = Convert.ToNumber (msec);
635 double time = DateConstructor.MakeTime (DateConstructor.HourFromTime (t), DateConstructor.MinFromTime (t),
637 double day = Math.Floor (t / DateConstructor.MS_PER_DAY);
638 double new_val = DateConstructor.MakeDate (day, time);
639 date.ms = DateConstructor.TimeClip (new_val);
643 /* Note: See Note for GetYear() for an explanation why we do not emulate obsolete behavior here. */
644 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_setYear)]
645 public static double setYear (object thisObj, double dyear)
647 return setFullYear (thisObj, dyear, null, null);
650 internal const string InvalidDateString = "Invalid Date";
652 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_toDateString)]
653 public static string toDateString (object thisObj)
655 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
657 DateObject date_obj = (DateObject) thisObj;
658 double val = date_obj.ms;
659 double lv = DateConstructor.LocalTime (val);
660 int year = DateConstructor.YearFromTime (lv);
661 int month = DateConstructor.MonthFromTime (lv);
662 int date = DateConstructor.DateFromTime (lv);
666 dt = new DateTime (year, month + 1, date);
667 } catch (ArgumentOutOfRangeException) {
668 return InvalidDateString;
671 return dt.ToString ("ddd MMM d yyyy", CultureInfo.InvariantCulture);
674 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_toGMTString)]
675 public static string toGMTString (object thisObj)
677 return toUTCString (thisObj);
680 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_toLocaleDateString)]
681 public static string toLocaleDateString (object thisObj)
683 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
685 DateObject date_obj = (DateObject) thisObj;
686 double val = date_obj.ms;
687 double lv = DateConstructor.LocalTime (val);
688 int year = DateConstructor.YearFromTime (lv);
689 int month = DateConstructor.MonthFromTime (lv);
690 int date = DateConstructor.DateFromTime (lv);
694 dt = new DateTime (year, month + 1, date);
695 } catch (ArgumentOutOfRangeException) {
696 return InvalidDateString;
699 return dt.ToString ("D");
702 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_toLocaleString)]
703 public static string toLocaleString (object thisObj)
705 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
707 DateObject date_obj = (DateObject) thisObj;
708 double val = date_obj.ms;
709 double lv = DateConstructor.LocalTime (val);
710 int year = DateConstructor.YearFromTime (lv);
711 int month = DateConstructor.MonthFromTime (lv);
712 int date = DateConstructor.DateFromTime (lv);
713 int hour = DateConstructor.HourFromTime (lv);
714 int min = DateConstructor.MinFromTime (lv);
715 int sec = DateConstructor.SecFromTime (lv);
719 dt = new DateTime (year, month + 1, date, hour, min, sec);
720 } catch (ArgumentOutOfRangeException) {
721 return InvalidDateString;
724 return dt.ToString ("F");
727 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_toLocaleTimeString)]
728 public static string toLocaleTimeString (object thisObj)
730 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
732 DateObject date_obj = (DateObject) thisObj;
733 double val = date_obj.ms;
734 double lv = DateConstructor.LocalTime (val);
735 int year = DateConstructor.YearFromTime (lv);
736 int month = DateConstructor.MonthFromTime (lv);
737 int date = DateConstructor.DateFromTime (lv);
738 int hour = DateConstructor.HourFromTime (lv);
739 int min = DateConstructor.MinFromTime (lv);
740 int sec = DateConstructor.SecFromTime (lv);
744 dt = new DateTime (year, month + 1, date, hour, min, sec);
745 } catch (ArgumentOutOfRangeException) {
746 return InvalidDateString;
749 return dt.ToString ("T");
752 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_toString)]
753 public static string toString (object thisObj)
755 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
756 string date_str = toDateString (thisObj);
757 if (date_str == InvalidDateString)
760 return date_str.Insert (date_str.LastIndexOf (' '), " " + toTimeString (thisObj));
763 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_toTimeString)]
764 public static string toTimeString (object thisObj)
766 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
768 DateObject date_obj = (DateObject) thisObj;
769 double val = date_obj.ms;
770 double lv = DateConstructor.LocalTime (val);
771 int hour = DateConstructor.HourFromTime (lv);
772 int min = DateConstructor.MinFromTime (lv);
773 int sec = DateConstructor.SecFromTime (lv);
774 double off = getTimezoneOffset (thisObj);
776 return String.Format (@"{0:00}:{1:00}:{2:00} UTC{3:\+0;\-0;\+0}", hour, min, sec, -off / 60);
779 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_toUTCString)]
780 public static string toUTCString (object thisObj)
782 SemanticAnalyser.assert_type (thisObj, typeof (DateObject));
784 DateObject date_obj = (DateObject) thisObj;
785 double val = date_obj.ms;
786 int year = DateConstructor.YearFromTime (val);
787 int month = DateConstructor.MonthFromTime (val);
788 int date = DateConstructor.DateFromTime (val);
789 int hour = DateConstructor.HourFromTime (val);
790 int min = DateConstructor.MinFromTime (val);
791 int sec = DateConstructor.SecFromTime (val);
795 dt = new DateTime (year, month + 1, date);
796 } catch (ArgumentOutOfRangeException) {
797 return InvalidDateString;
800 string date_string = dt.ToString ("ddd, d MMM yyyy ", CultureInfo.InvariantCulture);
801 string time_string = String.Format (@"{0:00}:{1:00}:{2:00} UTC", hour, min, sec);
803 return date_string + time_string;
806 [JSFunctionAttribute (JSFunctionAttributeEnum.HasThisObject, JSBuiltin.Date_valueOf)]
807 public static double valueOf (object thisObj)
809 return getTime (thisObj);