(date: Date,
time: Date,
formats: CalendarSpec,
locale: Locale = getLocale(),
config: DateParsingConfig = {})
| 37 | } |
| 38 | |
| 39 | export 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 | } |
no test coverage detected