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/weekofyear.js
12923 views
1
import { MS, Y, D, W } from "./constant.js";
2
3
export default (o, c, d) => {
4
const proto = c.prototype;
5
proto.week = function (week = null) {
6
if (week !== null) {
7
return this.add((week - this.week()) * 7, D);
8
}
9
const yearStart = this.$locale().yearStart || 1;
10
if (this.month() === 11 && this.date() > 25) {
11
// d(this) is for badMutable
12
const nextYearStartDay = d(this).startOf(Y).add(1, Y).date(yearStart);
13
const thisEndOfWeek = d(this).endOf(W);
14
if (nextYearStartDay.isBefore(thisEndOfWeek)) {
15
return 1;
16
}
17
}
18
const yearStartDay = d(this).startOf(Y).date(yearStart);
19
const yearStartWeek = yearStartDay.startOf(W).subtract(1, MS);
20
const diffInWeek = this.diff(yearStartWeek, W, true);
21
if (diffInWeek < 0) {
22
return d(this).startOf("week").week();
23
}
24
return Math.ceil(diffInWeek);
25
};
26
27
proto.weeks = function (week = null) {
28
return this.week(week);
29
};
30
};
31
32