diff --git a/src/fns.js b/src/fns.js index e0701132..dccb0ee6 100644 --- a/src/fns.js +++ b/src/fns.js @@ -76,7 +76,9 @@ exports.beADate = (d, s) => { } exports.formatTimezone = (offset, delimiter = '') => { - const absOffset = Math.abs(offset) const sign = offset > 0 ? '+' : '-' - return `${sign}${exports.zeroPad(absOffset)}${delimiter}00` + const absOffset = Math.abs(offset) + const hours = exports.zeroPad(parseInt('' + absOffset, 10)) + const minutes = exports.zeroPad(absOffset % 1 * 60) + return `${sign}${hours}${delimiter}${minutes}` } diff --git a/src/methods/format/_offset.js b/src/methods/format/_offset.js index 03e51cad..75e3e7e0 100644 --- a/src/methods/format/_offset.js +++ b/src/methods/format/_offset.js @@ -5,32 +5,7 @@ const fns = require('../../fns') // "+01:00", "+0100", or simply "+01" const isoOffset = s => { let offset = s.timezone().current.offset - const isNegative = offset < 0 - let minute = '00' - //handle 5.5 → '5:30' - if (Math.abs(offset % 1) === 0.5) { - minute = '30' - if (offset >= 0) { - offset = Math.floor(offset) - } else { - offset = Math.ceil(offset) - } - } - if (isNegative) { - //handle negative sign - offset *= -1 - offset = fns.zeroPad(offset, 2) - offset = '-' + offset - } else { - offset = fns.zeroPad(offset, 2) - offset = '+' + offset - } - offset = offset + ':' + minute - //'Z' means 00 - if (offset === '+00:00') { - offset = 'Z' - } - return offset + return !offset ? 'Z' : fns.formatTimezone(offset, ':') } module.exports = isoOffset