Index: branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.js |
— | — | @@ -914,7 +914,7 @@ |
915 | 915 | var value = options.values && options.values[this.desc.name], |
916 | 916 | date; |
917 | 917 | if ( typeof value != 'undefined' && value !== null ) { |
918 | | - date = new Date( value ); |
| 918 | + date = this._parseDate( value ); |
919 | 919 | |
920 | 920 | if ( !isFinite( date ) ) { |
921 | 921 | $.error( "value is invalid" ); |
— | — | @@ -933,6 +933,39 @@ |
934 | 934 | DateField.prototype = Object.create( SimpleField.prototype ); |
935 | 935 | DateField.prototype.constructor = DateField; |
936 | 936 | |
| 937 | + //Parses a date in the [YYYY]-[MM]-[DD]T[hh]:[mm]:[ss]Z format, returns a date object |
| 938 | + //Used to avoid the "new Date( dateString )" constructor, which is implementation-specific. |
| 939 | + DateField.prototype._parseDate = function( str ) { |
| 940 | + var date, |
| 941 | + parts = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/.exec( str ); |
| 942 | + |
| 943 | + if ( parts === null ) { |
| 944 | + return new Date( NaN ); |
| 945 | + } |
| 946 | + |
| 947 | + var year = parseInt( parts[1], 10 ), |
| 948 | + month = parseInt( parts[2], 10 ) - 1, |
| 949 | + day = parseInt( parts[3], 10 ), |
| 950 | + h = parseInt( parts[4], 10 ), |
| 951 | + m = parseInt( parts[5], 10 ), |
| 952 | + s = parseInt( parts[6], 10 ); |
| 953 | + |
| 954 | + date = new Date(); |
| 955 | + date.setUTCFullYear( year, month, day ); |
| 956 | + date.setUTCHours( h ); |
| 957 | + date.setUTCMinutes( m ); |
| 958 | + date.setUTCSeconds( s ); |
| 959 | + |
| 960 | + //Check if the date was actually correct, since the date handling functions may wrap around invalid dates |
| 961 | + if ( date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day || |
| 962 | + date.getUTCHours() !== h || date.getUTCMinutes() !== m || date.getUTCSeconds() !== s ) |
| 963 | + { |
| 964 | + return new Date( NaN ); |
| 965 | + } |
| 966 | + |
| 967 | + return date; |
| 968 | + }; |
| 969 | + |
937 | 970 | DateField.prototype.getValues = function() { |
938 | 971 | var d = this.$text.datepicker( 'getDate' ), |
939 | 972 | res = {}; |