Skip to content

Commit

Permalink
Convert date.js to a native class
Browse files Browse the repository at this point in the history
Updating this to Octane idioms allows us to remove one more bit of
Ember Classic code in the ecosystem!
  • Loading branch information
chriskrycho committed Apr 20, 2021
1 parent cead476 commit 6c2a8a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions addon-test-support/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ import DateService from "ember-date-service/services/date";
* Extends the provided internal DateService, allowing you to override
* Date.now() and Date.UTC() without modifying the native Date object.
*/
export default DateService.extend({
init() {
this._super(...arguments);
export default class FakeDateService extends DateService {
constructor() {
super(...arguments);

this._now = null;
},
}

now() {
if (this._now) {
return this._now;
}

return this._super(...arguments);
},
return super(...arguments);
}

setNow(date = Date.now()) {
this._now = date instanceof Date ? date.getTime() : date;

return this._now;
},
}

reset() {
this._now = null;
},
});
}
}
10 changes: 5 additions & 5 deletions addon/services/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import Service from '@ember/service';
* which allows you to override dates with static values without having to
* modify the native Date object.
*/
export default Service.extend({
export default class DateService extends Service {
now() {
return Date.now();
},
}

UTC(...args) {
return new Date(Date.UTC(...args));
},
}

parse(dateString) {
return Date.parse(dateString);
},
});
}
}

0 comments on commit 6c2a8a7

Please sign in to comment.