corrade-nucleus-nucleons – Blame information for rev 38

Subversion Repositories:
Rev:
Rev Author Line No. Line
38 office 1 import { createLocal } from '../create/local';
2 import { cloneWithOffset } from '../units/offset';
3 import isFunction from '../utils/is-function';
4 import { hooks } from '../utils/hooks';
5  
6 export function getCalendarFormat(myMoment, now) {
7 var diff = myMoment.diff(now, 'days', true);
8 return diff < -6 ? 'sameElse' :
9 diff < -1 ? 'lastWeek' :
10 diff < 0 ? 'lastDay' :
11 diff < 1 ? 'sameDay' :
12 diff < 2 ? 'nextDay' :
13 diff < 7 ? 'nextWeek' : 'sameElse';
14 }
15  
16 export function calendar (time, formats) {
17 // We want to compare the start of today, vs this.
18 // Getting start-of-today depends on whether we're local/utc/offset or not.
19 var now = time || createLocal(),
20 sod = cloneWithOffset(now, this).startOf('day'),
21 format = hooks.calendarFormat(this, sod) || 'sameElse';
22  
23 var output = formats && (isFunction(formats[format]) ? formats[format].call(this, now) : formats[format]);
24  
25 return this.format(output || this.localeData().calendar(format, this, createLocal(now)));
26 }