Path: blob/main/src/resources/library/dayjs/plugins/advanced.js
12923 views
import { FORMAT_DEFAULT } from "./constant.js";12export default (o, c, d) => {3// locale needed later4const proto = c.prototype;5const oldFormat = proto.format;6d.en.ordinal = (number) => {7const s = ["th", "st", "nd", "rd"];8const v = number % 100;9return `[${number}${s[(v - 20) % 10] || s[v] || s[0]}]`;10};11// extend en locale here12proto.format = function (formatStr) {13const locale = this.$locale();1415if (!this.isValid()) {16return oldFormat.bind(this)(formatStr);17}1819const utils = this.$utils();20const str = formatStr || FORMAT_DEFAULT;21const result = str.replace(22/\[([^\]]+)]|Q|wo|ww|w|WW|W|zzz|z|gggg|GGGG|Do|X|x|k{1,2}|S/g,23(match) => {24switch (match) {25case "Q":26return Math.ceil((this.$M + 1) / 3);27case "Do":28return locale.ordinal(this.$D);29case "gggg":30return this.weekYear();31case "GGGG":32return this.isoWeekYear();33case "wo":34return locale.ordinal(this.week(), "W"); // W for week35case "w":36case "ww":37return utils.s(this.week(), match === "w" ? 1 : 2, "0");38case "W":39case "WW":40return utils.s(this.isoWeek(), match === "W" ? 1 : 2, "0");41case "k":42case "kk":43return utils.s(44String(this.$H === 0 ? 24 : this.$H),45match === "k" ? 1 : 2,46"0"47);48case "X":49return Math.floor(this.$d.getTime() / 1000);50case "x":51return this.$d.getTime();52case "z":53return `[${this.offsetName()}]`;54case "zzz":55return `[${this.offsetName("long")}]`;56default:57return match;58}59}60);61return oldFormat.bind(this)(result);62};63};646566