This commit is contained in:
Lukáš Kaňka
2023-08-15 18:35:50 +02:00
commit ea3e372146
10019 changed files with 2548539 additions and 0 deletions

View File

@ -0,0 +1,10 @@
import { PluginFunc, ConfigType } from 'dayjs/esm'
declare const plugin: PluginFunc
export = plugin
declare module 'dayjs/esm' {
interface Dayjs {
calendar(referenceTime?: ConfigType, formats?: object): string
}
}

View File

@ -0,0 +1,32 @@
export default (function (o, c, d) {
var LT = 'h:mm A';
var L = 'MM/DD/YYYY';
var calendarFormat = {
lastDay: "[Yesterday at] " + LT,
sameDay: "[Today at] " + LT,
nextDay: "[Tomorrow at] " + LT,
nextWeek: "dddd [at] " + LT,
lastWeek: "[Last] dddd [at] " + LT,
sameElse: L
};
var proto = c.prototype;
proto.calendar = function (referenceTime, formats) {
var format = formats || this.$locale().calendar || calendarFormat;
var referenceStartOfDay = d(referenceTime || undefined).startOf('d');
var diff = this.diff(referenceStartOfDay, 'd', true);
var sameElse = 'sameElse';
/* eslint-disable no-nested-ternary */
var retVal = diff < -6 ? sameElse : diff < -1 ? 'lastWeek' : diff < 0 ? 'lastDay' : diff < 1 ? 'sameDay' : diff < 2 ? 'nextDay' : diff < 7 ? 'nextWeek' : sameElse;
/* eslint-enable no-nested-ternary */
var currentFormat = format[retVal] || calendarFormat[retVal];
if (typeof currentFormat === 'function') {
return currentFormat.call(this, d());
}
return this.format(currentFormat);
};
});