src/jdk/nashorn/internal/objects/NativeDate.java

Print this page




 502     /**
 503      * ECMA 15.9.5.25 Date.prototype.getUTCMilliseconds ( )
 504      *
 505      * @param self self reference
 506      * @return UTC milliseconds
 507      */
 508     @Function(attributes = Attribute.NOT_ENUMERABLE)
 509     public static Object getUTCMilliseconds(final Object self) {
 510         return getUTCField(self, MILLISECOND);
 511     }
 512 
 513     /**
 514      * ECMA 15.9.5.26 Date.prototype.getTimezoneOffset ( )
 515      *
 516      * @param self self reference
 517      * @return time zone offset or NaN if N/A
 518      */
 519     @Function(attributes = Attribute.NOT_ENUMERABLE)
 520     public static Object getTimezoneOffset(final Object self) {
 521         final NativeDate nd = getNativeDate(self);
 522         if (nd != null) {
 523             final long msec = (long) nd.getTime();
 524             return - nd.getTimeZone().getOffset(msec) / msPerMinute;
 525         }
 526         return Double.NaN;
 527     }
 528 
 529     /**
 530      * ECMA 15.9.5.27 Date.prototype.setTime (time)
 531      *
 532      * @param self self reference
 533      * @param time time
 534      * @return time
 535      */
 536     @Function(attributes = Attribute.NOT_ENUMERABLE)
 537     public static Object setTime(final Object self, final Object time) {
 538         final double     num = timeClip(JSType.toNumber(time));
 539         final NativeDate nd  = getNativeDate(self);

 540         nd.setTime(num);
 541         return num;
 542     }
 543 
 544     /**
 545      * ECMA 15.9.5.28 Date.prototype.setMilliseconds (ms)
 546      *
 547      * @param self self reference
 548      * @param args milliseconds
 549      * @return time
 550      */
 551     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
 552     public static Object setMilliseconds(final Object self, final Object... args) {
 553         final NativeDate nd = getNativeDate(self);
 554         if (nd.isValidDate()) {
 555             setFields(nd, MILLISECOND, args, true);
 556         }
 557         return nd.getTime();
 558     }
 559 
 560     /**
 561      * ECMA 15.9.5.29 Date.prototype.setUTCMilliseconds (ms)
 562      *
 563      * @param self self reference
 564      * @param args utc milliseconds
 565      * @return time
 566      */
 567     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
 568     public static Object setUTCMilliseconds(final Object self, final Object... args) {
 569         final NativeDate nd = getNativeDate(self);
 570         if (nd.isValidDate()) {
 571             setFields(nd, MILLISECOND, args, false);
 572         }
 573         return nd.getTime();
 574     }
 575 
 576     /**
 577      * ECMA 15.9.5.30 Date.prototype.setSeconds (sec [, ms ] )
 578      *
 579      * @param self self reference
 580      * @param args seconds (milliseconds optional second argument)
 581      * @return time
 582      */
 583     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
 584     public static Object setSeconds(final Object self, final Object... args) {
 585         final NativeDate nd = getNativeDate(self);
 586         if (nd.isValidDate()) {
 587             setFields(nd, SECOND, args, true);
 588         }
 589         return nd.getTime();
 590     }
 591 
 592     /**
 593      * ECMA 15.9.5.31 Date.prototype.setUTCSeconds (sec [, ms ] )
 594      *
 595      * @param self self reference
 596      * @param args UTC seconds (milliseconds optional second argument)
 597      * @return time
 598      */
 599     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
 600     public static Object setUTCSeconds(final Object self, final Object... args) {
 601         final NativeDate nd = getNativeDate(self);
 602         if (nd.isValidDate()) {
 603             setFields(nd, SECOND, args, false);
 604         }
 605         return nd.getTime();
 606     }
 607 
 608     /**
 609      * ECMA 15.9.5.32 Date.prototype.setMinutes (min [, sec [, ms ] ] )
 610      *
 611      * @param self self reference
 612      * @param args minutes (seconds and milliseconds are optional second and third arguments)
 613      * @return time
 614      */
 615     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
 616     public static Object setMinutes(final Object self, final Object... args) {
 617         final NativeDate nd = getNativeDate(self);
 618         if (nd.isValidDate()) {
 619             setFields(nd, MINUTE, args, true);
 620         }
 621         return nd.getTime();
 622     }
 623 
 624     /**
 625      * ECMA 15.9.5.33 Date.prototype.setUTCMinutes (min [, sec [, ms ] ] )
 626      *
 627      * @param self self reference
 628      * @param args minutes (seconds and milliseconds are optional second and third arguments)
 629      * @return time
 630      */
 631     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
 632     public static Object setUTCMinutes(final Object self, final Object... args) {
 633         final NativeDate nd = getNativeDate(self);
 634         if (nd.isValidDate()) {
 635             setFields(nd, MINUTE, args, false);
 636         }
 637         return nd.getTime();
 638     }
 639 
 640     /**
 641      * ECMA 15.9.5.34 Date.prototype.setHours (hour [, min [, sec [, ms ] ] ] )
 642      *
 643      * @param self self reference
 644      * @param args hour (optional arguments after are minutes, seconds, milliseconds)
 645      * @return time
 646      */
 647     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4)
 648     public static Object setHours(final Object self, final Object... args) {
 649         final NativeDate nd = getNativeDate(self);
 650         if (nd.isValidDate()) {
 651             setFields(nd, HOUR, args, true);
 652         }
 653         return nd.getTime();
 654     }
 655 
 656     /**
 657      * ECMA 15.9.5.35 Date.prototype.setUTCHours (hour [, min [, sec [, ms ] ] ] )
 658      *
 659      * @param self self reference
 660      * @param args hour (optional arguments after are minutes, seconds, milliseconds)
 661      * @return time
 662      */
 663     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4)
 664     public static Object setUTCHours(final Object self, final Object... args) {
 665         final NativeDate nd = getNativeDate(self);
 666         if (nd.isValidDate()) {
 667             setFields(nd, HOUR, args, false);
 668         }
 669         return nd.getTime();
 670     }
 671 
 672     /**
 673      * ECMA 15.9.5.36 Date.prototype.setDate (date)
 674      *
 675      * @param self self reference
 676      * @param args date
 677      * @return time
 678      */
 679     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
 680     public static Object setDate(final Object self, final Object... args) {
 681         final NativeDate nd = getNativeDate(self);
 682         if (nd.isValidDate()) {
 683             setFields(nd, DAY, args, true);
 684         }
 685         return nd.getTime();
 686     }
 687 
 688     /**
 689      * ECMA 15.9.5.37 Date.prototype.setUTCDate (date)
 690      *
 691      * @param self self reference
 692      * @param args UTC date
 693      * @return time
 694      */
 695     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
 696     public static Object setUTCDate(final Object self, final Object... args) {
 697         final NativeDate nd = getNativeDate(self);
 698         if (nd.isValidDate()) {
 699             setFields(nd, DAY, args, false);
 700         }
 701         return nd.getTime();
 702     }
 703 
 704     /**
 705      * ECMA 15.9.5.38 Date.prototype.setMonth (month [, date ] )
 706      *
 707      * @param self self reference
 708      * @param args month (optional second argument is date)
 709      * @return time
 710      */
 711     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
 712     public static Object setMonth(final Object self, final Object... args) {
 713         final NativeDate nd = getNativeDate(self);
 714         if (nd.isValidDate()) {
 715             setFields(nd, MONTH, args, true);
 716         }
 717         return nd.getTime();
 718     }
 719 
 720     /**
 721      * ECMA 15.9.5.39 Date.prototype.setUTCMonth (month [, date ] )
 722      *
 723      * @param self self reference
 724      * @param args UTC month (optional second argument is date)
 725      * @return time
 726      */
 727     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
 728     public static Object setUTCMonth(final Object self, final Object... args) {
 729         final NativeDate nd = ensureNativeDate(self);
 730         if (nd.isValidDate()) {
 731             setFields(nd, MONTH, args, false);
 732         }
 733         return nd.getTime();
 734     }
 735 
 736     /**
 737      * ECMA 15.9.5.40 Date.prototype.setFullYear (year [, month [, date ] ] )
 738      *
 739      * @param self self reference
 740      * @param args year (optional second and third arguments are month and date)
 741      * @return time
 742      */
 743     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
 744     public static Object setFullYear(final Object self, final Object... args) {
 745         final NativeDate nd   = ensureNativeDate(self);
 746         if (nd.isValidDate()) {
 747             setFields(nd, YEAR, args, true);
 748         } else {
 749             final double[] d = convertArgs(args, 0, YEAR, YEAR, 3);

 750             nd.setTime(timeClip(utc(makeDate(makeDay(d[0], d[1], d[2]), 0), nd.getTimeZone())));



 751         }
 752         return nd.getTime();
 753     }
 754 
 755     /**
 756      * ECMA 15.9.5.41 Date.prototype.setUTCFullYear (year [, month [, date ] ] )
 757      *
 758      * @param self self reference
 759      * @param args UTC full year (optional second and third arguments are month and date)
 760      * @return time
 761      */
 762     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
 763     public static Object setUTCFullYear(final Object self, final Object... args) {
 764         final NativeDate nd   = ensureNativeDate(self);
 765         if (nd.isValidDate()) {
 766             setFields(nd, YEAR, args, false);
 767         } else {
 768             final double[] d = convertArgs(args, 0, YEAR, YEAR, 3);
 769             nd.setTime(timeClip(makeDate(makeDay(d[0], d[1], d[2]), 0)));
 770         }
 771         return nd.getTime();
 772     }
 773 
 774     /**
 775      * ECMA B.2.5 Date.prototype.setYear (year)
 776      *
 777      * @param self self reference
 778      * @param year year
 779      * @return NativeDate
 780      */
 781     @Function(attributes = Attribute.NOT_ENUMERABLE)
 782     public static Object setYear(final Object self, final Object year) {
 783         final NativeDate nd = getNativeDate(self);
 784         if (isNaN(nd.getTime())) {
 785             return null;
 786         }
 787 
 788         final double yearNum = JSType.toNumber(year);
 789         if (isNaN(yearNum)) {
 790             nd.setTime(NaN);
 791             return nd;
 792         }
 793         int yearInt = JSType.toInteger(yearNum);
 794         if (0 <= yearInt && yearInt <= 99) {
 795             yearInt += 1900;
 796         }
 797         setFields(nd, YEAR, new Object[] {yearInt}, true);
 798 
 799         return nd;
 800     }
 801 
 802     /**
 803      * ECMA 15.9.5.42 Date.prototype.toUTCString ( )
 804      *
 805      * @param self self reference
 806      * @return string representation of date
 807      */
 808     @Function(attributes = Attribute.NOT_ENUMERABLE)
 809     public static Object toUTCString(final Object self) {
 810         return toGMTStringImpl(self);
 811     }
 812 
 813     /**
 814      * ECMA B.2.6 Date.prototype.toGMTString ( )
 815      *
 816      * See {@link NativeDate#toUTCString(Object)}
 817      *
 818      * @param self self reference
 819      * @return string representation of date


1280         final NativeDate nd = getNativeDate(self);
1281         return (nd != null && nd.isValidDate()) ? valueFromTime(field, nd.getLocalTime()) : Double.NaN;
1282     }
1283 
1284     private static Object getUTCField(final Object self, final int field) {
1285         final NativeDate nd = getNativeDate(self);
1286         return (nd != null && nd.isValidDate()) ? valueFromTime(field, nd.getTime()) : Double.NaN;
1287     }
1288 
1289     private static void setFields(final NativeDate nd, final int fieldId, final Object[] args, final boolean local) {
1290         int start, length;
1291         if (fieldId < HOUR) {
1292             start = YEAR;
1293             length = 3;
1294         } else {
1295             start = HOUR;
1296             length = 4;
1297         }
1298         final double time = local ? nd.getLocalTime() : nd.getTime();
1299         final double d[] = convertArgs(args, time, fieldId, start, length);




1300 
1301         double newTime;
1302         if (d == null) {
1303             newTime = NaN;
1304         } else {
1305             if (start == YEAR) {
1306                 newTime = makeDate(makeDay(d[0], d[1], d[2]), timeWithinDay(time));
1307             } else {
1308                 newTime = makeDate(day(time), makeTime(d[0], d[1], d[2], d[3]));
1309             }
1310             if (local) {
1311                 newTime = utc(newTime, nd.getTimeZone());
1312             }
1313             newTime = timeClip(newTime);
1314         }
1315         nd.setTime(newTime);
1316     }
1317 
1318     private boolean isValidDate() {
1319         return !isNaN(time);


 502     /**
 503      * ECMA 15.9.5.25 Date.prototype.getUTCMilliseconds ( )
 504      *
 505      * @param self self reference
 506      * @return UTC milliseconds
 507      */
 508     @Function(attributes = Attribute.NOT_ENUMERABLE)
 509     public static Object getUTCMilliseconds(final Object self) {
 510         return getUTCField(self, MILLISECOND);
 511     }
 512 
 513     /**
 514      * ECMA 15.9.5.26 Date.prototype.getTimezoneOffset ( )
 515      *
 516      * @param self self reference
 517      * @return time zone offset or NaN if N/A
 518      */
 519     @Function(attributes = Attribute.NOT_ENUMERABLE)
 520     public static Object getTimezoneOffset(final Object self) {
 521         final NativeDate nd = getNativeDate(self);
 522         if (nd != null && nd.isValidDate()) {
 523             final long msec = (long) nd.getTime();
 524             return - nd.getTimeZone().getOffset(msec) / msPerMinute;
 525         }
 526         return Double.NaN;
 527     }
 528 
 529     /**
 530      * ECMA 15.9.5.27 Date.prototype.setTime (time)
 531      *
 532      * @param self self reference
 533      * @param time time
 534      * @return time
 535      */
 536     @Function(attributes = Attribute.NOT_ENUMERABLE)
 537     public static Object setTime(final Object self, final Object time) {

 538         final NativeDate nd  = getNativeDate(self);
 539         final double     num = timeClip(JSType.toNumber(time));
 540         nd.setTime(num);
 541         return num;
 542     }
 543 
 544     /**
 545      * ECMA 15.9.5.28 Date.prototype.setMilliseconds (ms)
 546      *
 547      * @param self self reference
 548      * @param args milliseconds
 549      * @return time
 550      */
 551     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
 552     public static Object setMilliseconds(final Object self, final Object... args) {
 553         final NativeDate nd = getNativeDate(self);

 554         setFields(nd, MILLISECOND, args, true);

 555         return nd.getTime();
 556     }
 557 
 558     /**
 559      * ECMA 15.9.5.29 Date.prototype.setUTCMilliseconds (ms)
 560      *
 561      * @param self self reference
 562      * @param args utc milliseconds
 563      * @return time
 564      */
 565     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
 566     public static Object setUTCMilliseconds(final Object self, final Object... args) {
 567         final NativeDate nd = getNativeDate(self);

 568         setFields(nd, MILLISECOND, args, false);

 569         return nd.getTime();
 570     }
 571 
 572     /**
 573      * ECMA 15.9.5.30 Date.prototype.setSeconds (sec [, ms ] )
 574      *
 575      * @param self self reference
 576      * @param args seconds (milliseconds optional second argument)
 577      * @return time
 578      */
 579     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
 580     public static Object setSeconds(final Object self, final Object... args) {
 581         final NativeDate nd = getNativeDate(self);

 582         setFields(nd, SECOND, args, true);

 583         return nd.getTime();
 584     }
 585 
 586     /**
 587      * ECMA 15.9.5.31 Date.prototype.setUTCSeconds (sec [, ms ] )
 588      *
 589      * @param self self reference
 590      * @param args UTC seconds (milliseconds optional second argument)
 591      * @return time
 592      */
 593     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
 594     public static Object setUTCSeconds(final Object self, final Object... args) {
 595         final NativeDate nd = getNativeDate(self);

 596         setFields(nd, SECOND, args, false);

 597         return nd.getTime();
 598     }
 599 
 600     /**
 601      * ECMA 15.9.5.32 Date.prototype.setMinutes (min [, sec [, ms ] ] )
 602      *
 603      * @param self self reference
 604      * @param args minutes (seconds and milliseconds are optional second and third arguments)
 605      * @return time
 606      */
 607     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
 608     public static Object setMinutes(final Object self, final Object... args) {
 609         final NativeDate nd = getNativeDate(self);

 610         setFields(nd, MINUTE, args, true);

 611         return nd.getTime();
 612     }
 613 
 614     /**
 615      * ECMA 15.9.5.33 Date.prototype.setUTCMinutes (min [, sec [, ms ] ] )
 616      *
 617      * @param self self reference
 618      * @param args minutes (seconds and milliseconds are optional second and third arguments)
 619      * @return time
 620      */
 621     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
 622     public static Object setUTCMinutes(final Object self, final Object... args) {
 623         final NativeDate nd = getNativeDate(self);

 624         setFields(nd, MINUTE, args, false);

 625         return nd.getTime();
 626     }
 627 
 628     /**
 629      * ECMA 15.9.5.34 Date.prototype.setHours (hour [, min [, sec [, ms ] ] ] )
 630      *
 631      * @param self self reference
 632      * @param args hour (optional arguments after are minutes, seconds, milliseconds)
 633      * @return time
 634      */
 635     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4)
 636     public static Object setHours(final Object self, final Object... args) {
 637         final NativeDate nd = getNativeDate(self);

 638         setFields(nd, HOUR, args, true);

 639         return nd.getTime();
 640     }
 641 
 642     /**
 643      * ECMA 15.9.5.35 Date.prototype.setUTCHours (hour [, min [, sec [, ms ] ] ] )
 644      *
 645      * @param self self reference
 646      * @param args hour (optional arguments after are minutes, seconds, milliseconds)
 647      * @return time
 648      */
 649     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 4)
 650     public static Object setUTCHours(final Object self, final Object... args) {
 651         final NativeDate nd = getNativeDate(self);

 652         setFields(nd, HOUR, args, false);

 653         return nd.getTime();
 654     }
 655 
 656     /**
 657      * ECMA 15.9.5.36 Date.prototype.setDate (date)
 658      *
 659      * @param self self reference
 660      * @param args date
 661      * @return time
 662      */
 663     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
 664     public static Object setDate(final Object self, final Object... args) {
 665         final NativeDate nd = getNativeDate(self);

 666         setFields(nd, DAY, args, true);

 667         return nd.getTime();
 668     }
 669 
 670     /**
 671      * ECMA 15.9.5.37 Date.prototype.setUTCDate (date)
 672      *
 673      * @param self self reference
 674      * @param args UTC date
 675      * @return time
 676      */
 677     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
 678     public static Object setUTCDate(final Object self, final Object... args) {
 679         final NativeDate nd = getNativeDate(self);

 680         setFields(nd, DAY, args, false);

 681         return nd.getTime();
 682     }
 683 
 684     /**
 685      * ECMA 15.9.5.38 Date.prototype.setMonth (month [, date ] )
 686      *
 687      * @param self self reference
 688      * @param args month (optional second argument is date)
 689      * @return time
 690      */
 691     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
 692     public static Object setMonth(final Object self, final Object... args) {
 693         final NativeDate nd = getNativeDate(self);

 694         setFields(nd, MONTH, args, true);

 695         return nd.getTime();
 696     }
 697 
 698     /**
 699      * ECMA 15.9.5.39 Date.prototype.setUTCMonth (month [, date ] )
 700      *
 701      * @param self self reference
 702      * @param args UTC month (optional second argument is date)
 703      * @return time
 704      */
 705     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
 706     public static Object setUTCMonth(final Object self, final Object... args) {
 707         final NativeDate nd = ensureNativeDate(self);

 708         setFields(nd, MONTH, args, false);

 709         return nd.getTime();
 710     }
 711 
 712     /**
 713      * ECMA 15.9.5.40 Date.prototype.setFullYear (year [, month [, date ] ] )
 714      *
 715      * @param self self reference
 716      * @param args year (optional second and third arguments are month and date)
 717      * @return time
 718      */
 719     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
 720     public static Object setFullYear(final Object self, final Object... args) {
 721         final NativeDate nd   = ensureNativeDate(self);
 722         if (nd.isValidDate()) {
 723             setFields(nd, YEAR, args, true);
 724         } else {
 725             final double[] d = convertArgs(args, 0, YEAR, YEAR, 3);
 726             if (d != null) {
 727                 nd.setTime(timeClip(utc(makeDate(makeDay(d[0], d[1], d[2]), 0), nd.getTimeZone())));
 728             } else {
 729                 nd.setTime(NaN);
 730             }
 731         }
 732         return nd.getTime();
 733     }
 734 
 735     /**
 736      * ECMA 15.9.5.41 Date.prototype.setUTCFullYear (year [, month [, date ] ] )
 737      *
 738      * @param self self reference
 739      * @param args UTC full year (optional second and third arguments are month and date)
 740      * @return time
 741      */
 742     @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 3)
 743     public static Object setUTCFullYear(final Object self, final Object... args) {
 744         final NativeDate nd   = ensureNativeDate(self);
 745         if (nd.isValidDate()) {
 746             setFields(nd, YEAR, args, false);
 747         } else {
 748             final double[] d = convertArgs(args, 0, YEAR, YEAR, 3);
 749             nd.setTime(timeClip(makeDate(makeDay(d[0], d[1], d[2]), 0)));
 750         }
 751         return nd.getTime();
 752     }
 753 
 754     /**
 755      * ECMA B.2.5 Date.prototype.setYear (year)
 756      *
 757      * @param self self reference
 758      * @param year year
 759      * @return NativeDate
 760      */
 761     @Function(attributes = Attribute.NOT_ENUMERABLE)
 762     public static Object setYear(final Object self, final Object year) {
 763         final NativeDate nd = getNativeDate(self);
 764         if (isNaN(nd.getTime())) {
 765             nd.setTime(utc(0, nd.getTimeZone()));
 766         }
 767 
 768         final double yearNum = JSType.toNumber(year);
 769         if (isNaN(yearNum)) {
 770             nd.setTime(NaN);
 771             return nd.getTime();
 772         }
 773         int yearInt = JSType.toInteger(yearNum);
 774         if (0 <= yearInt && yearInt <= 99) {
 775             yearInt += 1900;
 776         }
 777         setFields(nd, YEAR, new Object[] {yearInt}, true);
 778 
 779         return nd.getTime();
 780     }
 781 
 782     /**
 783      * ECMA 15.9.5.42 Date.prototype.toUTCString ( )
 784      *
 785      * @param self self reference
 786      * @return string representation of date
 787      */
 788     @Function(attributes = Attribute.NOT_ENUMERABLE)
 789     public static Object toUTCString(final Object self) {
 790         return toGMTStringImpl(self);
 791     }
 792 
 793     /**
 794      * ECMA B.2.6 Date.prototype.toGMTString ( )
 795      *
 796      * See {@link NativeDate#toUTCString(Object)}
 797      *
 798      * @param self self reference
 799      * @return string representation of date


1260         final NativeDate nd = getNativeDate(self);
1261         return (nd != null && nd.isValidDate()) ? valueFromTime(field, nd.getLocalTime()) : Double.NaN;
1262     }
1263 
1264     private static Object getUTCField(final Object self, final int field) {
1265         final NativeDate nd = getNativeDate(self);
1266         return (nd != null && nd.isValidDate()) ? valueFromTime(field, nd.getTime()) : Double.NaN;
1267     }
1268 
1269     private static void setFields(final NativeDate nd, final int fieldId, final Object[] args, final boolean local) {
1270         int start, length;
1271         if (fieldId < HOUR) {
1272             start = YEAR;
1273             length = 3;
1274         } else {
1275             start = HOUR;
1276             length = 4;
1277         }
1278         final double time = local ? nd.getLocalTime() : nd.getTime();
1279         final double d[] = convertArgs(args, time, fieldId, start, length);
1280 
1281         if (! nd.isValidDate()) {
1282             return;
1283         }
1284 
1285         double newTime;
1286         if (d == null) {
1287             newTime = NaN;
1288         } else {
1289             if (start == YEAR) {
1290                 newTime = makeDate(makeDay(d[0], d[1], d[2]), timeWithinDay(time));
1291             } else {
1292                 newTime = makeDate(day(time), makeTime(d[0], d[1], d[2], d[3]));
1293             }
1294             if (local) {
1295                 newTime = utc(newTime, nd.getTimeZone());
1296             }
1297             newTime = timeClip(newTime);
1298         }
1299         nd.setTime(newTime);
1300     }
1301 
1302     private boolean isValidDate() {
1303         return !isNaN(time);