-
-
Save acgerhold/c5d2c4f67a70d75d0ce67634a3ee564b to your computer and use it in GitHub Desktop.
Timezones in JavaScript, from http://errtheblog.com/posts/49-a-zoned-defense
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Timezone = { | |
set : function() { | |
var date = new Date(); | |
date.setTime(date.getTime() + (1000*24*60*60*1000)); | |
var expires = "; expires=" + date.toGMTString(); | |
document.cookie = "timezone=" + (-date.getTimezoneOffset() * 60) + expires + "; path=/"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Zoned | |
def zoned(date) | |
return date unless timezone = cookies[:timezone] | |
date - (Time.now.gmtoff - timezone.to_i) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment