Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
ember-moment
Advanced tools
moment.js template helpers and computed property macros for Ember
ember install ember-moment
It's advisable to run ember g ember-moment
between upgrades as dependencies may have been added, removed, or upgraded between releases. Please try this, along with clearing node_modules
and bower_components
before reporting issues after upgrading.
Ships with the following computed property macros: duration
, humanize
, locale
, tz
, format
, calendar
, moment
, toNow
, fromNow
. They can be used individually or composed together.
Computed Property Macro Documentation
{{moment '12-25-1995' 'MM-DD-YYYY'}}
{{moment-format '12-25-1995' 'MM/DD/YYYY' 'MM-DD-YYYY'}} {{!-- outputFormat and inputFormat are optional --}}
{{moment-from-now (now) hideSuffix=true}} {{!-- hideSuffix is optional --}}
{{moment-to-now (unix timeStamp) date hidePrefix=true}} {{!-- hidePrefix is optional --}}
{{moment-duration number units}} {{!-- units is optional --}}
{{moment-calendar date referenceDate}} {{!-- reference date is optional --}}
{{is-before date comparison precision='year'}} {{!-- precision is optional --}}
{{is-after date comparison precision='year'}} {{!-- precision is optional --}}
{{is-same date comparison precision='year'}} {{!-- precision is optional --}}
{{is-same-or-before date comparison precision='year'}} {{!-- precision is optional --}}
{{is-same-or-after date comparison precision='year'}} {{!-- precision is optional --}}
{{is-between date comparisonA comparisonB precision='year' inclusivity='[)'}} {{!-- precision is optional, inclusivity optional --}}
{{moment-from-now (now) interval=1000}} // interval is in ms
Recomputes the time ago every 1-second (1000 milliseconds). This is useful for "live" updating as time elapses.
This addon provides the ability to import moment as an ES6 module.
import moment from 'moment';
You can optionally include the Moment Timezone package in your config/environment.js
like so:
// config/environment.js
module.exports = function() {
return {
moment: {
// Options:
// 'all' - all years, all timezones
// '2010-2020' - 2010-2020, all timezones
// 'none' - no data, just timezone API
includeTimezone: 'all'
}
}
};
Your application may require a default format other than the default, ISO 8601. For example, you may want dates to fallback on the localized shorthand format L
by default.
// config/environment.js
module.exports = function() {
return {
moment: {
outputFormat: 'L'
}
}
};
If you need to change the default format during runtime, use the service API. During so, will trigger the moment-format helper instances to re-render with the new default format.
// app/controller/index.js
export default Ember.Controller.extend({
moment: Ember.inject.service(),
actions: {
changeDefaultFormat() {
this.set('moment.defaultFormat', 'MM.DD.YYYY');
}
}
})
If null
, undefined
, or an empty string as a date to any of the moment helpers then you you will Invalid Date
in the output. To avoid this issue globally, you can set the option allowEmpty
which all of the helpers respect and will result in nothing being rendered instead of Invalid Date
.
// config/environment.js
module.exports = function() {
return {
moment: {
allowEmpty: true // default: false
}
}
};
// config/environment.js
module.exports = function(environment) {
return {
moment: {
// To cherry-pick specific locale support into your application.
// Full list of locales: https://github.com/moment/moment/tree/2.10.3/locale
includeLocales: ['es', 'fr-ca']
}
};
// config/environment.js
module.exports = function(environment) {
return {
moment: {
includeLocales: true
}
};
NOTE: English is bundled automatically, not need to add en
in includeLocales
dist
Alternatively, you can copy all of moment's locale files into your dist
directory.
// config.environment.js
module.exports = function(environment) {
return {
moment: {
// This will output _all_ locale scripts to assets/moment-locales
// this option does not respect includeLocales
localeOutputPath: 'assets/moment-locales'
}
};
This allows you to load them on demand when you need them:
Ember.$.getScript('/assets/moment-locales/fr.js');
// app/routes/applicaton.js
export default Ember.Route.extend({
moment: Ember.inject.service(),
beforeModel() {
this.get('moment').changeLocale('es');
}
});
// app/routes/applicaton.js
export default Ember.Route.extend({
moment: Ember.inject.service(),
beforeModel() {
this.get('moment').changeTimeZone('America/Los_Angeles');
}
});
All helpers accept a locale
and timeZone
argument, which is a string. This allows for overriding of the global locale.
{{moment-format date locale='es' timeZone='America/Los_Angeles'}}
{{moment-duration (now) date locale='es' timeZone='America/Los_Angeles'}}
{{moment-from-now (now) date locale='es' timeZone='America/Los_Angeles'}}
{{moment-to-now date locale='es' timeZone='America/Los_Angeles'}}
Documentation on i18n support within moment can be found here: http://momentjs.com/docs/#/i18n/ Documentation on timezone within moment can be found here: http://momentjs.com/timezone/docs/
Invalid Date
is being rendered into the DOM, how do I avoid this?
An invalid date string is being passed into momentjs and/or the input string format was omitted. For example, if you're using the moment-format
you'll pass the input format as the 3rd argument:
{{moment-format date outputFormat inputFormat}}
NOTE: for all other helpers, the input format string is the second argument.
If you are knowingly passing null, undefined, or an empty string and want to ignore the output of Invalid Date
then pass the option allow-empty=true
to the helper (all helpers accept this property)
{{moment-format date allow-empty=true}}
git clone
this repositorynpm install
bower install
ember server
ember test
ember test --server
ember build
For more information on using ember-cli, visit http://www.ember-cli.com/.
7.2.0
ember-macro-helpers
FAQs
Moment.js template helpers Ember.js
The npm package ember-moment receives a total of 27,344 weekly downloads. As such, ember-moment popularity was classified as popular.
We found that ember-moment demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.