From 4b8c1a7d6ba1977e0b7504746529da254111efb3 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 27 May 2012 15:01:22 +0200 Subject: [PATCH] Ox.formatDate: better tests for '%s' and '%+', fix '%s', '%Z' and '%z' --- source/Ox/js/Format.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index 4feca259..2ada6212 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -39,6 +39,7 @@ Ox.formatDate Formats a date according to a format string utc date is utc > Ox.formatDate(Ox.test.date, '%A') // Full weekday 'Sunday' @@ -92,8 +93,8 @@ Ox.formatDate Formats a date according to a format string '12:03:04 AM' > Ox.formatDate(Ox.test.date, '%S') // Zero-padded second '04' - > Ox.formatDate(Ox.test.date, '%s', true) // Number of seconds since the Epoch - '1104620584' + > Ox.formatDate(Ox.test.epoch, '%s', true) // Number of seconds since the Epoch + '0' > Ox.formatDate(Ox.test.date, '%T') // Time '00:03:04' > Ox.formatDate(Ox.test.date, '%t') // Tab @@ -122,8 +123,8 @@ Ox.formatDate Formats a date according to a format string 'UTC' > Ox.formatDate(Ox.test.date, '%z', true) // Time zone offset '+0000' - > Ox.formatDate(Ox.test.date, '%+', true) // Formatted date and time - 'Sun Jan 2 00:03:04 CET 2005' + > Ox.formatDate(Ox.test.date, '%+').replace(/ [A-Z]+ /, ' XYZ ') // Formatted date and time + 'Sun Jan 2 00:03:04 XYZ 2005' > Ox.formatDate(Ox.test.date, '%%') '%' @*/ @@ -219,8 +220,9 @@ Ox.formatDate Formats a date according to a format string return Ox.pad(Ox.getSeconds(date, utc), 2); }], ['s', function(date, utc) { - return Math.floor(date.getTime() / 1000) - - (utc ? Ox.getTimezoneOffset() / 1000 : 0); + return Math.floor((+date - ( + utc ? Ox.getTimezoneOffset(date) : 0 + )) / 1000); }], ['U', function(date, utc) { return Ox.pad(Ox.getWeek(date, utc), 2); @@ -252,11 +254,12 @@ Ox.formatDate Formats a date according to a format string ['y', function(date, utc) { return Ox.getFullYear(date, utc).toString().slice(-2); }], - ['Z', function(date) { - return (date.toString().split('(')[1] || '').replace(')', ''); + ['Z', function(date, utc) { + return utc ? 'UTC' + : (date.toString().split('(')[1] || '').replace(')', ''); }], - ['z', function(date) { - return Ox.getTimezoneOffsetString(date); + ['z', function(date, utc) { + return utc ? '+0000' : Ox.getTimezoneOffsetString(date); }], ['n', function() { return '\n';