Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
runspired committed Apr 25, 2017
1 parent e044293 commit ca15b82
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
17 changes: 16 additions & 1 deletion addon/transforms/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,23 @@ export default Transform.extend({
deserialize(serialized) {
let type = typeof serialized;

if (type === "string" || type === "number") {
if (type === "string") {
let offset = serialized.indexOf('+');

if (offset !== -1 && serialized.length - 3 === offset) {
deprecate(`The ECMA2015 Spec for ISO 8601 dates does not allow for shorthand timezone offsets such as +00.
Ember Data's normalization of date's allowing for this shorthand has been deprecated, please update your API to return
UTC dates formatted with ±hh:mm timezone offsets or implement a custom UTC transform.`,
false,
{
id: 'ds.attr.date.normalize-utc',
until: '3.0.0'
});
return new Date(`${serialized}:00`);
}
return new Date(serialized);
} else if (type === "number") {
return new Date(serialized)
} else if (serialized === null || serialized === undefined) {
// if the value is null return null
// if the value is not present in the data return undefined
Expand Down
15 changes: 10 additions & 5 deletions tests/unit/transform/date-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,22 @@ test('#deserialize', function(assert) {
assert.equal(transform.deserialize(undefined), null);
});

test('#deserialize with different offset formats', function(assert) {
testInDebug('#deserialize with different offset formats', function(assert) {
let transform = new DS.DateTransform();
let dateString = '2003-05-24T23:00:00.000+0000';
let dateStringColon = '2013-03-15T23:22:00.000+00:00';
let dateStringShortOffset = '2016-12-02T17:30:00.000+00';

assert.expect(3);
assert.expect(4);

assert.equal(transform.deserialize(dateString).getTime(), 1053817200000, '');
assert.equal(transform.deserialize(dateStringShortOffset).getTime(), 1480699800000, '');
assert.equal(transform.deserialize(dateStringColon).getTime(), 1363389720000, '');
let deserialized;
assert.expectDeprecation(() => {
deserialized = transform.deserialize(dateStringShortOffset).getTime();
}, /The ECMA2015 Spec for ISO 8601 dates does not allow for shorthand timezone offsets such as \+00/);

assert.equal(transform.deserialize(dateString).getTime(), 1053817200000);
assert.equal(deserialized, 1480699800000, 'This test can be removed once the deprecation is removed');
assert.equal(transform.deserialize(dateStringColon).getTime(), 1363389720000);
});

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

0 comments on commit ca15b82

Please sign in to comment.