Skip to content

Commit

Permalink
Fix timezone issue on all day event.
Browse files Browse the repository at this point in the history
  • Loading branch information
sugi committed Jul 18, 2013
1 parent 1d030e9 commit f2e5be9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
6 changes: 6 additions & 0 deletions ReleaseNote
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions gcal_flow.jquery.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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": {
Expand Down
50 changes: 23 additions & 27 deletions jquery.gcal_flow.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down

0 comments on commit f2e5be9

Please sign in to comment.