Skip to content

Instantly share code, notes, and snippets.

@mccraychassidy
Forked from defunkt/zoned.js
Created January 16, 2024 02:21
Show Gist options
  • Save mccraychassidy/aee123523aaa30577d20aaac587f895e to your computer and use it in GitHub Desktop.
Save mccraychassidy/aee123523aaa30577d20aaac587f895e to your computer and use it in GitHub Desktop.
Timezones in JavaScript, from http://errtheblog.com/posts/49-a-zoned-defense
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=/";
}
}
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