Skip to content

Commit

Permalink
interpret iso -05 as GMT+5 #61
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Sep 1, 2018
1 parent fef2f64 commit 3f02dd5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
11 changes: 9 additions & 2 deletions scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@ const spacetime = require('./src/index')
// var minus = spacetime('2018-07-09T12:59:00-07:00');
// console.log(minus.format('iso'));

let s=spacetime('June 8th 1918').time('4:00pm').goto('Asia/Calcutta')
console.log( s.format('iso'))
// let s=spacetime('June 8th 1918').time('4:00pm').goto('Asia/Calcutta')
// console.log( s.format('iso'))
// console.log(spacetime.now().goto('America/New_York').format('iso'))
// console.log(spacetime.now().goto('America/New_York').format('iso'))
// console.log('2018-09-01T13:47:16-04:00')

var s = spacetime('2018-07-09T12:59:00.362Z');
console.log(s.timezone())
console.log(s.format('iso'))
6 changes: 6 additions & 0 deletions src/input/parseOffset.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ const parseOffset = function(s, offset, givenTz) {
return s
}
//okay, try to match it to a utc timezone

//this is opposite! a -5 offset maps to Etc/GMT+5 ¯\_()_/¯
//https://askubuntu.com/questions/519550/why-is-the-8-timezone-called-gmt-8-in-the-filesystem
num*=-1

if (num >= 0) {
num = '+' + num
}

let tz = 'Etc/GMT' + num
let zones = s.timezones
if (zones[tz]) {

// console.log('changing timezone to: ' + tz)
//log a warning if we're over-writing a given timezone
if (givenTz && zones[givenTz] && zones[givenTz].o !== zones[tz].o && s.silent === false) {
Expand Down
12 changes: 6 additions & 6 deletions src/methods/format/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ const isoOffset = function(s) {
minute = '30'
offset=Math.floor(offset)
}
//offset numbers are opposite in ISO-186 format!
//"2018-07-09T12:59:00.908-07:00" means +7 hours from UTC!
if (offset <= 0) {
if (offset < 0) {
//handle negative sign
offset *= -1
offset = '+' + fns.zeroPad(offset, 2)
} else {
offset = fns.zeroPad(offset, 2) //handle negative sign
offset = fns.zeroPad(offset, 2)
offset = '-' + offset
} else {
offset = fns.zeroPad(offset, 2)
offset = '+' + offset
}
offset = offset + ':' + minute
//this is a little cleaner?
Expand Down
2 changes: 1 addition & 1 deletion test/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ test('iso-in = iso-out', t => {

test('iso-with-fraction-offset', t => {
let s=spacetime('June 8th 1918').time('4:00pm').goto('Asia/Calcutta')
t.equal(s.format('iso'),'1918-06-09T01:30:00.000-05:30','correct offset')
t.equal(s.format('iso'),'1918-06-09T01:30:00.000+05:30','correct offset')
t.end();
});
/* FIXME failing test
Expand Down
20 changes: 10 additions & 10 deletions test/utcOffset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ test('set-offset-from-ISO-8601', t => {
let defaultTz = 'Canada/Eastern'
let arr = [
['2017-04-03T08:00:00', defaultTz],
['2017-04-03T08:00:00-0700', 'Etc/GMT-7'],
['2017-04-03T08:00:00-1000', 'Etc/GMT-10'],
['2017-04-03T08:00:00+0700', 'Etc/GMT+7'],
['2017-04-03T08:00:00-0700', 'Etc/GMT+7'],
['2017-04-03T08:00:00-1000', 'Etc/GMT+10'],
['2017-04-03T08:00:00+0700', 'Etc/GMT-7'],
['2017-10-03T08:00:00+0000', 'Etc/GMT+0'],
// ['2017-04-03T08:00:00-0500', defaultTz], //the same
['2017-05-03T13:00:00+0500', 'Etc/GMT+5'],
['2017-04-02T08:00:00-10:00', 'Etc/GMT-10'],
['2017-04-11T02:00:00+10:00', 'Etc/GMT+10'],
['2017-04-02T08:00:00-01:00', 'Etc/GMT-1'],
['2017-04-11T02:00:00+01:00', 'Etc/GMT+1'],
['2018-04-10T08:00:00-03', 'Etc/GMT-3'],
['2017-04-03T12:00:00+03', 'Etc/GMT+3'],
['2017-05-03T13:00:00+0500', 'Etc/GMT-5'],
['2017-04-02T08:00:00-10:00', 'Etc/GMT+10'],
['2017-04-11T02:00:00+10:00', 'Etc/GMT-10'],
['2017-04-02T08:00:00-01:00', 'Etc/GMT+1'],
['2017-04-11T02:00:00+01:00', 'Etc/GMT-1'],
['2018-04-10T08:00:00-03', 'Etc/GMT+3'],
['2017-04-03T12:00:00+03', 'Etc/GMT-3'],
['2017-04-03T01:00:00+00', 'Etc/GMT+0'],
['2017-04-03T01:00:00Z', 'Etc/GMT+0'],
]
Expand Down

0 comments on commit 3f02dd5

Please sign in to comment.