Add ISO 8601 timestamp parsing for legacy browsers.
Would cause legacy browsers (e.g. Safari 4.1.3) to show posts in the reverse order and the infinite scroll would not be triggered when scrolling down to the end of the page.
This commit is contained in:
parent
7036c82562
commit
4769a25d59
2 changed files with 33 additions and 1 deletions
|
|
@ -21,7 +21,31 @@ app.models.Post = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
timeOf: function(field) {
|
timeOf: function(field) {
|
||||||
return new Date(this.get(field)) /1000;
|
var timestamp = new Date(this.get(field)) /1000;
|
||||||
|
|
||||||
|
if (isNaN(timestamp)) {
|
||||||
|
timestamp = this.legacyTimeOf(field);
|
||||||
|
}
|
||||||
|
|
||||||
|
return timestamp;
|
||||||
|
},
|
||||||
|
|
||||||
|
legacyTimeOf: function(field) {
|
||||||
|
var iso8601_utc_pattern = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.(\d{3}))?Z$/;
|
||||||
|
var time_components = this.get(field).match(iso8601_utc_pattern);
|
||||||
|
var timestamp = 0;
|
||||||
|
|
||||||
|
if (time_components != null) {
|
||||||
|
if (time_components[8] == undefined) {
|
||||||
|
time_components[8] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
timestamp = Date.UTC(time_components[1], time_components[2] - 1, time_components[3],
|
||||||
|
time_components[4], time_components[5], time_components[6],
|
||||||
|
time_components[8]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return timestamp /1000;
|
||||||
},
|
},
|
||||||
|
|
||||||
createReshareUrl : "/reshares",
|
createReshareUrl : "/reshares",
|
||||||
|
|
|
||||||
|
|
@ -119,5 +119,13 @@ describe("app.views.Post", function(){
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
context("legacy browsers", function(){
|
||||||
|
it("supports iso8501 utc timestamps", function(){
|
||||||
|
var timestamp = new Date(this.statusMessage.get("created_at")) /1000;
|
||||||
|
|
||||||
|
expect(this.statusMessage.legacyTimeOf("created_at")).toEqual(timestamp);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue