Permalink
Browse files

Fixed offset in date.parse to handle basic as well as extended format

  • Loading branch information...
1 parent 7245b6d commit 0e45934e3bb6ce7f41494c96b4d87d820922225a @mde committed Mar 4, 2014
Showing with 28 additions and 7 deletions.
  1. +28 −7 lib/date.js
View
@@ -660,6 +660,7 @@ date = new (function () {
, posOff
, offHours
, offMinutes
+ , offSeconds
, curr
, stamp
, utc;
@@ -724,19 +725,39 @@ date = new (function () {
}
else {
utc = false;
- off = off.replace(/\+|-|:/g, '');
+ // Convert from extended to basic if necessary
+ off = off.replace(/:/g, '');
+ // '+0000' will still be zero
if (parseInt(off, 10) === 0) {
utc = true;
}
else {
posOff = off.indexOf('+') === 0;
+ // Strip plus or minus
off = off.substr(1);
- off = off.split(':');
- offHours = parseInt(off[0], 10);
- offMinutes = parseInt(off[1], 10) || 0;
- offMinutes += (offHours * 60);
+
+ offHours = parseInt(off.substr(0, 2), 10);
+
+ offMinutes = off.substr(2, 2);
+ if (offMinutes) {
+ offMinutes = parseInt(offMinutes, 10);
+ }
+ else {
+ offMinutes = 0;
+ }
+
+ offSeconds = off.substr(4, 2);
+ if (offSeconds) {
+ offSeconds = parseInt(offSeconds, 10);
+ }
+ else {
+ offSeconds = 0;
+ }
+
+ offSeconds += (offMinutes * 60)
+ offSeconds += (offHours * 60 * 60);
if (!posOff) {
- offMinutes = 0 - offMinutes;
+ offSeconds = 0 - offSeconds;
}
}
}
@@ -755,7 +776,7 @@ date = new (function () {
dt['setUTC' + _dateMethods[i]](curr);
}
// Add any offset
- dt.setMinutes(dt.getMinutes() - offMinutes);
+ dt.setSeconds(dt.getSeconds() - offSeconds);
}
// Otherwise we know nothing about the offset, just iterate the
// array and set each date property using regular setters

0 comments on commit 0e45934

Please sign in to comment.