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

Convert to native classes #157

Merged
merged 1 commit into from
Jun 7, 2021
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
20 changes: 10 additions & 10 deletions addon-test-support/date.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import DateService from "ember-date-service/services/date";
import DateService from 'ember-date-service/services/date';

/**
* @class FakeDateService
*
* 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.now(...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);
},
});
}
}