Permalink
Browse files

begin adding timezone conversion

  • Loading branch information...
1 parent 23b8e06 commit e06ec89fbaed34b42518b79d9af584ad4082c19e @smith committed Oct 31, 2011
Showing with 23 additions and 8 deletions.
  1. +3 −8 CollegeFootball.wdgt/js/schedule.js
  2. +20 −0 CollegeFootball.wdgt/js/tz.js
@@ -1,15 +1,10 @@
-define(["require", "exports", "jquery", "./date"], function (require, exports, $) {
+define(["require", "exports", "jquery", "./tz", "./date"], function (require, exports, $, tz) {
var cellMethods;
- function convertTZ(time) {
- // TODO
- return time;
- }
-
function row(i, r) {
var cells = $(r).find("td"),
o = {},
- cols = ["date", "opponent", "resultTime", "recordTickets"]
+ cols = ["date", "opponent", "resultTime", "recordTickets"];
cells.each(function (i, c) {
cellMethods[cols[i]]($(c), o);
@@ -39,7 +34,7 @@ define(["require", "exports", "jquery", "./date"], function (require, exports, $
// If there's " ET " (eastern time)
if (/\sET\s?/.test(rt)) {
// Remove everything after the "ET " and convert timezone
- rt = convertTZ(rt.replace(/\sET\s?(.*)$/, ""));
+ rt = tz.convert(rt.replace(/\sET\s?(.*)$/, ""));
}
o.resultTime = rt;
},
@@ -0,0 +1,20 @@
+// Timezone utility functions
+define(["jquery", "./date"], function ($) {
+ var localTzOffset = new Date().getTimezoneOffset(),
+ // The GMT offset, in minutes, of the eastern timezone. DST DIAF
+ etTzOffset = 240, // TODO: Calculate this. Godspeed.
+ tzDiff = etTzOffset - localTzOffset;
+
+ return {
+ // Convert the time (12:00 PM) from eastern to local
+ convert: function (time) {
+ // No need to change
+ if (tzDiff === 0) { return time; }
+
+ // Create a new date, apply the offset, and format
+ return Date.parse("1970-01-01 " + time).
+ addMinutes(tzDiff).
+ toString("h:mm tt");
+ }
+ };
+});

0 comments on commit e06ec89

Please sign in to comment.