day.js template helpers and a service for Ember.
Nearly drop-in replacement for ember-moment.
Just replace all moment-
with dayjs-
and try.
- Ember.js v3.28 or above
- Embroider or ember-auto-import v2
ember install ember-dayjs
Parameters | Values |
---|---|
<date> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
Returns a Dayjs.
Parameters | Values |
---|---|
<date> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
Returns a Dayjs with UTC mode set.
Example
Parameters | Values |
---|---|
<date> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
outputFormat |
An optional date/time String output format, defaults to dayjs.defaultFormat |
inputFormat |
An optional named argument for date/time String input format |
advanced |
Pass true to be able to use advanced format |
Example
Parameters | Values |
---|---|
<date> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
<timeZone> |
Optional: Time Zone Name Ex: America/Los_Angeles |
Returns a Dayjs corresponding to the <timestamp>
.
Examples
Parameters | Values |
---|---|
<dateA> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
<dateB> |
An optional value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...), defaults to now |
hideAffix |
An optional Boolean to hide the relative prefix/suffix not. |
Returns the time between <dateA>
and <dateB>
relative to <dateB>
. See dayjs#from
.
Examples
Parameters | Values |
---|---|
<dateA> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
<dateB> |
An optional value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...), defaults to now |
hideAffix |
An optional Boolean to hide the relative prefix/suffix or not. |
Returns the time between <dateA>
and <dateB>
relative to <dateA>
. See dayjs#to
.
Note that dayjs-to-now
is just a more verbose dayjs-to
without dateB
. You don't need to use it anymore.
Examples
Parameters | Values |
---|---|
<number> |
Any value(s) interpretable as a duration by dayjs (typically a Number in milliseconds) |
<units> |
An optional String to specify the units of <number> (typically 'seconds' , 'minutes' , 'hours' ...) |
Examples
Parameters | Values |
---|---|
<number> |
Any value(s) interpretable as a duration by dayjs (typically a Number in milliseconds) |
<units> |
An optional String to specify the units of <number> (typically 'seconds' , 'minutes' , 'hours' ...) |
Examples
Parameters | Values |
---|---|
<dateA> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
<formatHash> |
An optional output format hash, defaults to {} |
Examples
Parameters | Values |
---|---|
<dateA> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
<dateB> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
precision |
An optional unit of measurement, defaults to 'milliseconds' |
float |
An optional Boolean to get the floating point result, rather than the integer value |
Returns the difference in precision
units between <dateA>
and <dateB>
with floating point accuracy if float
is true
. See dayjs#diff
.
Examples
Parameters | Values |
---|---|
<date> |
An optional value interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...). Defaults to value of dayjs() |
<number> |
Any value(s) interpretable as a duration by dayjs that is the amount of the precision you want to add to the date provided |
precision |
An optional unit of measurement, defaults to 'milliseconds' |
Mutates the original dayjs by adding time. See dayjs#add
.
Examples
Parameters | Values |
---|---|
<date> |
An optional value interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...). Defaults to value of dayjs() |
<number> |
Any value(s) interpretable as a duration by dayjs that is the amount of the precision you want to subtract from the date provided |
precision |
An optional unit of measurement, defaults to 'milliseconds' |
Mutates the original dayjs by removing time. See dayjs#subtract
.
Examples
Parameters | Values |
---|---|
<dateA> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
<dateB> |
An optional value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...). If not given, <dateA> becomes now and <dateB> becomes <dateA> |
precision |
An optional String unit of comparison precision, defaults to 'milliseconds' |
Returns a Boolean
that indicates if <dateA>
is respectively before/after/the same/same or before/ same or after <dateB>
to the precision
level. See dayjs#queries
.
Examples
Parameters | Values |
---|---|
<date> |
Any value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
<dateA> |
A boundary value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...) |
<dateB> |
An optional boundary value(s) interpretable as a date/time by dayjs (a date String or a Dayjs or a Date ...). If not given <date> is assigned now, <dateA> is assigned <date> and <dateB> is assigned <dateA> . |
precision |
An optional String unit of comparison precision, defaults to 'milliseconds' |
inclusivity |
An optional String indicating inclusivity of the boundaries, defaults to () |
Returns a Boolean
that indicates if <date>
is between <dateA>
and <dateB>
to the precision
level and with boundary inclusions specified by inclusivity
. See dayjs#is-between
.
Examples
Returns the present Dayjs.
Examples
Parameters | Values |
---|---|
<timestamp> |
An integer Number value representing the number of milliseconds since the Unix Epoch (January 1 1970 12AM UTC) |
Returns a Dayjs corresponding to the <timestamp>
.
Examples
All helpers accept the following optional named arguments (even though they are not always applicable):
Parameters | Values |
---|---|
locale |
An optional String locale, to override the default global dayjs.locale |
interval |
An optional interval Number of milliseconds when the helper should be recomputed |
Examples
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ApplicationController extends Controller {
@service dayjs;
@action
changeLanguage(locale) {
this.dayjs.setLocale(locale); // tr
}
}
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ApplicationController extends Controller {
@service dayjs;
@action
changeTimeZone(timeZone) {
this.dayjs.setTimeZone(timeZone); // 'America/Los_Angeles'
}
}
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ApplicationController extends Controller {
@service dayjs;
@action
resetTimezone() {
this.dayjs.resetTimezone();
}
}
See the Contributing guide for details.
This project is licensed under the MIT License.