aboutsummaryrefslogtreecommitdiffstats
path: root/library/moment/src/lib/moment/calendar.js
blob: c9df8031123d3938581b3d2e314258013050e617 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { createLocal } from '../create/local';
import { cloneWithOffset } from '../units/offset';

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(),
        sod = cloneWithOffset(now, this).startOf('day'),
        diff = this.diff(sod, 'days', true),
        format = diff < -6 ? 'sameElse' :
            diff < -1 ? 'lastWeek' :
            diff < 0 ? 'lastDay' :
            diff < 1 ? 'sameDay' :
            diff < 2 ? 'nextDay' :
            diff < 7 ? 'nextWeek' : 'sameElse';
    return this.format(formats && formats[format] || this.localeData().calendar(format, this, createLocal(now)));
}