From f2e5be99a928821eb248a4a753bfef17a235aaae Mon Sep 17 00:00:00 2001 From: Tatsuki Sugiura Date: Thu, 18 Jul 2013 10:07:45 +0900 Subject: [PATCH] Fix timezone issue on all day event. --- ReleaseNote | 6 +++++ gcal_flow.jquery.json | 4 ++-- jquery.gcal_flow.coffee | 50 +++++++++++++++++++---------------------- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/ReleaseNote b/ReleaseNote index e8026dd..f012abd 100644 --- a/ReleaseNote +++ b/ReleaseNote @@ -1,3 +1,9 @@ +== v1.2.5 (2013-07-18) + + * Fix timezone issue on all day event. + (Wrong date was shown on all day event with Firefox + and Chrome when system has negative timezone offset.) + == v1.2.4 (2013-05-25) * Null update to fix download URL on jQuery Plugin Registry. diff --git a/gcal_flow.jquery.json b/gcal_flow.jquery.json index ca138ad..4b1e697 100644 --- a/gcal_flow.jquery.json +++ b/gcal_flow.jquery.json @@ -1,6 +1,6 @@ { "name": "gcal_flow", - "version": "1.2.4", + "version": "1.2.5", "title": "jQuery gCalFlow", "description": "jQuery plug-in to format your google calenar feeds.", "keywords": [ @@ -18,7 +18,7 @@ "url": "http://www.opensource.org/licenses/MIT" } ], - "download": "https://googledrive.com/host/0B1NvujAKTAEaRXRTT1c3dGpZRDA/jquery-gcal-flow-1.2.4.zip", + "download": "https://googledrive.com/host/0B1NvujAKTAEaRXRTT1c3dGpZRDA/jquery-gcal-flow-1.2.5.zip", "bugs": "https://github.com/sugi/jquery-gcal-flow/issues", "homepage": "http://sugi.github.io/jquery-gcal-flow/", "dependencies": { diff --git a/jquery.gcal_flow.coffee b/jquery.gcal_flow.coffee index 2717f77..91b2a29 100644 --- a/jquery.gcal_flow.coffee +++ b/jquery.gcal_flow.coffee @@ -131,34 +131,30 @@ class gCalFlow } parse_date: (dstr) -> - date = new Date dstr - unless isNaN date.getTime() - log.debug date - return date - else - if m = dstr.match /^(\d{4})-(\d{2})-(\d{2})$/ - return new Date parseInt(m[1], 10), parseInt(m[2], 10) - 1, parseInt(m[3], 10), 0, 0, 0 + # I do not use built-in Date() parser to avoid timezone issue on all day event. + if m = dstr.match /^(\d{4})-(\d{2})-(\d{2})$/ + return new Date parseInt(m[1], 10), parseInt(m[2], 10) - 1, parseInt(m[3], 10), 0, 0, 0 - offset = (new Date()).getTimezoneOffset() * 60 * 1000 - year = mon = day = null - hour = min = sec = 0 - if m = dstr.match /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|([+-])(\d{2}):(\d{2}))$/ - year = parseInt m[1], 10 - mon = parseInt m[2], 10 - day = parseInt m[3], 10 - hour = parseInt m[4], 10 - min = parseInt m[5], 10 - sec = parseInt m[6], 10 - if m[7] != "Z" - offset += (if m[8] is "+" then 1 else -1) * (parseInt(m[9], 10) * 60 + parseInt(m[10], 10)) * 1000 * 60 - else - log.warn "Time parse error! Unknown time pattern: #{dstr}" - return new Date 1970, 1, 1, 0, 0, 0 + offset = (new Date()).getTimezoneOffset() * 60 * 1000 + year = mon = day = null + hour = min = sec = 0 + if m = dstr.match /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|([+-])(\d{2}):(\d{2}))$/ + year = parseInt m[1], 10 + mon = parseInt m[2], 10 + day = parseInt m[3], 10 + hour = parseInt m[4], 10 + min = parseInt m[5], 10 + sec = parseInt m[6], 10 + if m[7] != "Z" + offset += (if m[8] is "+" then 1 else -1) * (parseInt(m[9], 10) * 60 + parseInt(m[10], 10)) * 1000 * 60 + else + log.warn "Time parse error! Unknown time pattern: #{dstr}" + return new Date 1970, 1, 1, 0, 0, 0 - log.debug "time parse (gap to local): #{offset}" - ret = new Date(new Date(year, mon - 1, day, hour, min, sec).getTime() - offset) - log.debug "time parse: #{dstr} -> ", ret - return ret + log.debug "time parse (gap to local): #{offset}" + ret = new Date(new Date(year, mon - 1, day, hour, min, sec).getTime() - offset) + log.debug "time parse: #{dstr} -> ", ret + return ret render_data: (data) -> log.debug "start rendering for data:", data @@ -272,7 +268,7 @@ $.fn.gCalFlow = (method) -> @each -> methods[method].apply $(@), Array.prototype.slice.call(orig_args, 1) else if method == 'version' - "1.2.4" + "1.2.5" else $.error "Method #{method} does not exist on jQuery.gCalFlow"