MCPcopy
hub / github.com/valor-software/ngx-bootstrap / calendar

Function calendar

src/chronos/moment/calendar.ts:39–66  ·  view source on GitHub ↗
(date: Date,
                         time: Date,
                         formats: CalendarSpec,
                         locale: Locale = getLocale(),
                         config: DateParsingConfig = {})

Source from the content-addressed store, hash-verified

37}
38
39export function calendar(date: Date,
40 time: Date,
41 formats: CalendarSpec,
42 locale: Locale = getLocale(),
43 config: DateParsingConfig = {}): string {
44 // We want to compare the start of today, vs this.
45 // Getting start-of-today depends on whether we're local/utc/offset or not.
46 const now = time;
47 const sod = startOf(cloneWithOffset(now, date, config), 'day', config._isUTC);
48 const format = getCalendarFormat(date, sod, {_isUTC: true, _offset: 0}) || 'sameElse';
49
50 let output;
51 if (formats) {
52 const _format = formats[format];
53 if (isString(_format)) {
54 output = _format;
55 }
56 if (isFunction(_format)) {
57 output = _format.call(null, date, now);
58 }
59 }
60
61 if (!output) {
62 output = locale.calendar(format, date, cloneDate(now));
63 }
64
65 return formatDate(date, output, config._locale._abbr, config._isUTC, config._offset);
66}

Callers 1

calendarMethod · 0.90

Calls 9

getLocaleFunction · 0.90
startOfFunction · 0.90
cloneWithOffsetFunction · 0.90
isStringFunction · 0.90
isFunctionFunction · 0.90
cloneDateFunction · 0.90
formatDateFunction · 0.90
getCalendarFormatFunction · 0.85
calendarMethod · 0.45

Tested by

no test coverage detected