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