import { createLocal } from '../create/local';
import { cloneWithOffset } from '../units/offset';
-export function calendar (time) {
+export function calendar (time, formats) {
// We want to compare the start of today, vs this.
// Getting start-of-today depends on whether we're local/utc/offset or not.
var now = time || createLocal(),
diff < 1 ? 'sameDay' :
diff < 2 ? 'nextDay' :
diff < 7 ? 'nextWeek' : 'sameElse';
- return this.format(this.localeData().calendar(format, this, createLocal(now)));
+ return this.format(formats && formats[format] || this.localeData().calendar(format, this, createLocal(now)));
}
assert.equal(moment(c).local().calendar(d), 'Tomorrow at 11:59 PM', 'Tomorrow at 11:59 PM, not Yesterday, or the wrong time');
});
+test('calendar with custom formats', function (assert) {
+ assert.equal(moment().calendar(null, {sameDay: '[Today]'}), 'Today', 'Today');
+ assert.equal(moment().add(1, 'days').calendar(null, {nextDay: '[Tomorrow]'}), 'Tomorrow', 'Tomorrow');
+ assert.equal(moment([1985, 1, 4]).calendar(null, {sameElse: 'YYYY-MM-DD'}), '1985-02-04', 'Else');
+});
+
test('invalid', function (assert) {
assert.equal(moment.invalid().format(), 'Invalid date');
assert.equal(moment.invalid().format('YYYY-MM-DD'), 'Invalid date');