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