Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX beta] Ensure ISO-8601 regex correctly matches timestamps #4771

Merged
merged 2 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/-private/ext/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const parseDate = function (date) {
// before falling back to any implementation-specific date parsing, so that’s what we do, even if native
// implementations could be faster
// 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
if ((struct = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?:(\d{2}))?)?)?$/.exec(date))) {
if ((struct = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2}):?(?:(\d{2}))?)?)?$/.exec(date))) {
// avoid NaN timestamps caused by “undefined” values being passed to Date.UTC
for (let i = 0, k; (k = numericKeys[i]); ++i) {
struct[k] = +struct[k] || 0;
Expand Down
19 changes: 16 additions & 3 deletions tests/unit/transform/date-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,22 @@ test("#deserialize with different offset formats", function(assert) {
var dateStringColon = '2013-03-15T23:22:00.000+00:00';
var dateStringShortOffset = '2016-12-02T17:30:00.000+00';

assert.equal(transform.deserialize(dateString).getTime(), 1053817200000);
assert.equal(transform.deserialize(dateStringShortOffset).getTime(), 1480699800000);
assert.equal(transform.deserialize(dateStringColon).getTime(), 1363389720000);
assert.expect(6);

var _dateUTC = Date.UTC;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should wrap this in a try/finally so that the original Date.UTC always gets restored.


try {
Date.UTC = function () {
assert.equal(arguments.length, 7);
return _dateUTC.apply(this, [].slice.call(arguments));
};

assert.equal(transform.deserialize(dateString).getTime(), 1053817200000);
assert.equal(transform.deserialize(dateStringShortOffset).getTime(), 1480699800000);
assert.equal(transform.deserialize(dateStringColon).getTime(), 1363389720000);
} finally {
Date.UTC = _dateUTC;
}
});

testInDebug('Ember.Date.parse has been deprecated', function(assert) {
Expand Down