Just use new Date()
to parse ISO 8601 dates
This should fix a weird bug where ISO dates were being parsed as a year earlier.
This commit is contained in:
parent
5216f11885
commit
eb50067a41
1 changed files with 1 additions and 20 deletions
|
@ -228,32 +228,13 @@ Zotero.Date = new function(){
|
||||||
/**
|
/**
|
||||||
* Convert an ISO 8601–formatted date/time to a JS Date
|
* Convert an ISO 8601–formatted date/time to a JS Date
|
||||||
*
|
*
|
||||||
* Adapted from http://delete.me.uk/2005/03/iso8601.html (AFL-licensed)
|
|
||||||
*
|
|
||||||
* @param {String} isoDate ISO 8601 date
|
* @param {String} isoDate ISO 8601 date
|
||||||
* @return {Date|False} - JS Date, or false if not a valid date
|
* @return {Date|False} - JS Date, or false if not a valid date
|
||||||
*/
|
*/
|
||||||
this.isoToDate = function (isoDate) {
|
this.isoToDate = function (isoDate) {
|
||||||
var d = isoDate.match(_re8601);
|
var d = isoDate.match(_re8601);
|
||||||
if (!d) return false;
|
if (!d) return false;
|
||||||
|
return new Date(isoDate);
|
||||||
var offset = 0;
|
|
||||||
var date = new Date(d[1], 0, 1);
|
|
||||||
|
|
||||||
if (d[3]) { date.setMonth(d[3] - 1); }
|
|
||||||
if (d[5]) { date.setDate(d[5]); }
|
|
||||||
if (d[7]) { date.setHours(d[7]); }
|
|
||||||
if (d[8]) { date.setMinutes(d[8]); }
|
|
||||||
if (d[10]) { date.setSeconds(d[10]); }
|
|
||||||
if (d[12]) { date.setMilliseconds(Number("0." + d[12]) * 1000); }
|
|
||||||
if (d[14]) {
|
|
||||||
offset = (Number(d[16]) * 60) + Number(d[17]);
|
|
||||||
offset *= ((d[15] == '-') ? 1 : -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
offset -= date.getTimezoneOffset();
|
|
||||||
var time = (Number(date) + (offset * 60 * 1000));
|
|
||||||
return new Date(time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue