Permalink
Browse files

Fixed timezone releated bugs (had to be in Singapore to discover them…

… ;))
  • Loading branch information...
1 parent c4f05f1 commit 42f3fb6c5546416c7e0b2f4b4a8a81ed13f6a668 @laktek committed Nov 27, 2012
Showing with 18 additions and 18 deletions.
  1. +4 −4 lib/cache_store.js
  2. +2 −2 spec/asset_bundler.spec.js
  3. +6 −6 spec/cache_store.spec.js
  4. +6 −6 spec/helpers/datetime_helper.js
View
@@ -58,8 +58,8 @@ module.exports = {
cache_obj.body = cached_content;
cache_obj.options.header["Content-Length"] = (cached_content && cached_content.length || 0);
- cache_obj.options.header["ETag"] = ("\"" + stat.size + "-" + Number(stat.mtime) + "\"");
- cache_obj.options.header["Last-Modified"] = new Date(stat.mtime).toUTCString();
+ cache_obj.options.header["ETag"] = ("\"" + stat.size + "-" + Number(stat.mtime.getTime()) + "\"");
+ cache_obj.options.header["Last-Modified"] = stat.mtime.toUTCString();
return callback(err, cache_obj);
});
@@ -93,8 +93,8 @@ module.exports = {
var cache_obj = { "body": body, "options": { "header": header } };
cache_obj.options.header["Content-Length"] = (body && body.length || 0);
- cache_obj.options.header["ETag"] = ("\"" + stat.size + "-" + Number(stat.mtime) + "\"");
- cache_obj.options.header["Last-Modified"] = new Date(stat.mtime).toUTCString();
+ cache_obj.options.header["ETag"] = ("\"" + stat.size + "-" + stat.mtime.getTime() + "\"");
+ cache_obj.options.header["Last-Modified"] = stat.mtime.toUTCString();
return callback(err, cache_obj);
});
@@ -609,7 +609,7 @@ describe("fingerprint a bundle", function() {
var spyBundleContent = jasmine.createSpy();
spyOn(asset_bundler, "statBundle").andCallFake(function(basename, extension, callback) {
- return callback(null, { "mtime": new Date(2012, 10, 8) });
+ return callback(null, { "mtime": new Date(1352313000000) });
});
var spyCacheStoreGet = jasmine.createSpy();
@@ -629,7 +629,7 @@ describe("fingerprint a bundle", function() {
var spyBundleContent = jasmine.createSpy();
spyOn(asset_bundler, "statBundle").andCallFake(function(basename, extension, callback) {
- return callback(null, { "mtime": new Date(2012, 10, 8) });
+ return callback(null, { "mtime": new Date(1352313000000) });
});
var spyCacheStoreGet = jasmine.createSpy();
@@ -136,7 +136,7 @@ describe("get", function(){
cache_store.contents = { "isSection": spyIsSection };
spyOn(fs, "stat").andCallFake(function(file_path, callback){
- return callback(null, { "mtime": new Date(2012, 6, 21), "size": 567 });
+ return callback(null, { "mtime": new Date(1342800000000), "size": 567 });
});
spyOn(fs, "readFile").andCallFake(function(file_path, encoding, callback){
@@ -146,7 +146,7 @@ describe("get", function(){
var spyCallback = jasmine.createSpy();
cache_store.get("path/test", ".html", { "options": { "header": { "custom-key": "custom-value" } } }, {}, spyCallback);
- expect(spyCallback).toHaveBeenCalledWith(null, { "body": cached_content, "options": { "header": { "Content-Length": 14, "ETag": "\"567-1342809000000\"", "Last-Modified": "Fri, 20 Jul 2012 18:30:00 GMT", "custom-key": "custom-value" } } });
+ expect(spyCallback).toHaveBeenCalledWith(null, { "body": cached_content, "options": { "header": { "Content-Length": 14, "ETag": "\"567-1342800000000\"", "Last-Modified": new Date(1342800000000).toUTCString(), "custom-key": "custom-value" } } });
});
@@ -159,7 +159,7 @@ describe("get", function(){
cache_store.contents = { "isSection": spyIsSection };
spyOn(fs, "stat").andCallFake(function(file_path, callback){
- return callback(null, { "mtime": new Date(2012, 6, 21), "size": 567 });
+ return callback(null, { "mtime": new Date(1342809000000), "size": 567 });
});
spyOn(fs, "readFile").andCallFake(function(file_path, encoding, callback){
@@ -169,7 +169,7 @@ describe("get", function(){
var spyCallback = jasmine.createSpy();
cache_store.get("path/test", ".html", { "options": { "header": {} } }, {}, spyCallback);
- expect(spyCallback).toHaveBeenCalledWith("error", { "body": null, "options": { "header": { "Content-Length": 0, "ETag": "\"567-1342809000000\"", "Last-Modified": "Fri, 20 Jul 2012 18:30:00 GMT" } } });
+ expect(spyCallback).toHaveBeenCalledWith("error", { "body": null, "options": { "header": { "Content-Length": 0, "ETag": "\"567-1342809000000\"", "Last-Modified": new Date(1342809000000).toUTCString() } } });
});
@@ -299,13 +299,13 @@ describe("update", function(){
});
spyOn(cache_store, "stat").andCallFake(function(file_path, file_ext, options, callback) {
- return callback(null, {"mtime": new Date(2012, 6, 21), "size": 527});
+ return callback(null, {"mtime": new Date(1342809000000), "size": 527});
});
var spyCallback = jasmine.createSpy();
cache_store.update("path/subdir/test", ".html", { "body": "test", "options": { "header": { "Content-Type": "text/css", "Cache-Control": "public, max-age=0" } } }, {}, spyCallback);
- expect(spyCallback).toHaveBeenCalledWith(null, { "body": "test", "options": { "header": { "Content-Type": "text/css", "Cache-Control": "public, max-age=0", "Content-Length": 4, "ETag": "\"527-1342809000000\"", "Last-Modified": "Fri, 20 Jul 2012 18:30:00 GMT" } } });
+ expect(spyCallback).toHaveBeenCalledWith(null, { "body": "test", "options": { "header": { "Content-Type": "text/css", "Cache-Control": "public, max-age=0", "Content-Length": 4, "ETag": "\"527-1342809000000\"", "Last-Modified": new Date(1342809000000).toUTCString() } } });
});
});
@@ -4,11 +4,11 @@ var date_helper = date_helper_obj.directAccess()["block_helpers"];
describe("datetime", function() {
it("return datetime string for JSON date strings", function() {
- expect(date_helper.datetime("2012-08-02T01:27:13.300Z")).toEqual("Thu Aug 02 2012 06:57:13 GMT+0530 (IST)");
+ expect(date_helper.datetime("2012-08-02T01:27:13.300Z")).toEqual(new Date("2012-08-02T01:27:13.300Z").toString());
});
it("return datetime string for unix epoch values", function() {
- expect(date_helper.datetime("1343870833300")).toEqual("Thu Aug 02 2012 06:57:13 GMT+0530 (IST)");
+ expect(date_helper.datetime("1343870833300")).toEqual(new Date(1343870833300).toString());
});
it("return an empty string for null values", function() {
@@ -20,11 +20,11 @@ describe("datetime", function() {
describe("date", function() {
it("return date string for JSON date strings", function() {
- expect(date_helper.date("2012-08-02T01:27:13.300Z")).toEqual("Thu Aug 02 2012");
+ expect(date_helper.date("2012-08-02T01:27:13.300Z")).toEqual(new Date("2012-08-02T01:27:13.300Z").toDateString());
});
it("return date string for unix epoch values", function() {
- expect(date_helper.date("1343870833300")).toEqual("Thu Aug 02 2012");
+ expect(date_helper.date("1343870833300")).toEqual(new Date(1343870833300).toDateString());
});
it("return an empty string for null values", function() {
@@ -36,11 +36,11 @@ describe("date", function() {
describe("time", function() {
it("return time string for JSON date strings", function() {
- expect(date_helper.time("2012-08-02T01:27:13.300Z")).toEqual("06:57:13 GMT+0530 (IST)");
+ expect(date_helper.time("2012-08-02T01:27:13.300Z")).toEqual(new Date("2012-08-02T01:27:13.300Z").toTimeString());
});
it("return date string for unix epoch values", function() {
- expect(date_helper.time("1343870833300")).toEqual("06:57:13 GMT+0530 (IST)");
+ expect(date_helper.time("1343870833300")).toEqual(new Date(1343870833300).toTimeString());
});
it("return an empty string for null values", function() {

0 comments on commit 42f3fb6

Please sign in to comment.