summaryrefslogtreecommitdiff
path: root/node_modules/moment/src/lib/units/week-year.js
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-08-18 13:29:54 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-08-18 13:29:54 +0300
commitfd70f95224374d23157ee7c0357733102cd0df53 (patch)
treee490c12e021cedaf211b292d5d623baa32a673fc /node_modules/moment/src/lib/units/week-year.js
initialHEADmaster
Diffstat (limited to 'node_modules/moment/src/lib/units/week-year.js')
-rw-r--r--node_modules/moment/src/lib/units/week-year.js128
1 files changed, 128 insertions, 0 deletions
diff --git a/node_modules/moment/src/lib/units/week-year.js b/node_modules/moment/src/lib/units/week-year.js
new file mode 100644
index 0000000..585362c
--- /dev/null
+++ b/node_modules/moment/src/lib/units/week-year.js
@@ -0,0 +1,128 @@
+import { addFormatToken } from '../format/format';
+import {
+ addRegexToken,
+ match1to2,
+ match1to4,
+ match1to6,
+ match2,
+ match4,
+ match6,
+ matchSigned,
+} from '../parse/regex';
+import { addWeekParseToken } from '../parse/token';
+import {
+ weekOfYear,
+ weeksInYear,
+ dayOfYearFromWeeks,
+} from './week-calendar-utils';
+import toInt from '../utils/to-int';
+import { hooks } from '../utils/hooks';
+import { createUTCDate } from '../create/date-from-array';
+
+// FORMATTING
+
+addFormatToken(0, ['gg', 2], 0, function () {
+ return this.weekYear() % 100;
+});
+
+addFormatToken(0, ['GG', 2], 0, function () {
+ return this.isoWeekYear() % 100;
+});
+
+function addWeekYearFormatToken(token, getter) {
+ addFormatToken(0, [token, token.length], 0, getter);
+}
+
+addWeekYearFormatToken('gggg', 'weekYear');
+addWeekYearFormatToken('ggggg', 'weekYear');
+addWeekYearFormatToken('GGGG', 'isoWeekYear');
+addWeekYearFormatToken('GGGGG', 'isoWeekYear');
+
+// ALIASES
+
+// PARSING
+
+addRegexToken('G', matchSigned);
+addRegexToken('g', matchSigned);
+addRegexToken('GG', match1to2, match2);
+addRegexToken('gg', match1to2, match2);
+addRegexToken('GGGG', match1to4, match4);
+addRegexToken('gggg', match1to4, match4);
+addRegexToken('GGGGG', match1to6, match6);
+addRegexToken('ggggg', match1to6, match6);
+
+addWeekParseToken(
+ ['gggg', 'ggggg', 'GGGG', 'GGGGG'],
+ function (input, week, config, token) {
+ week[token.substr(0, 2)] = toInt(input);
+ }
+);
+
+addWeekParseToken(['gg', 'GG'], function (input, week, config, token) {
+ week[token] = hooks.parseTwoDigitYear(input);
+});
+
+// MOMENTS
+
+export function getSetWeekYear(input) {
+ return getSetWeekYearHelper.call(
+ this,
+ input,
+ this.week(),
+ this.weekday() + this.localeData()._week.dow,
+ this.localeData()._week.dow,
+ this.localeData()._week.doy
+ );
+}
+
+export function getSetISOWeekYear(input) {
+ return getSetWeekYearHelper.call(
+ this,
+ input,
+ this.isoWeek(),
+ this.isoWeekday(),
+ 1,
+ 4
+ );
+}
+
+export function getISOWeeksInYear() {
+ return weeksInYear(this.year(), 1, 4);
+}
+
+export function getISOWeeksInISOWeekYear() {
+ return weeksInYear(this.isoWeekYear(), 1, 4);
+}
+
+export function getWeeksInYear() {
+ var weekInfo = this.localeData()._week;
+ return weeksInYear(this.year(), weekInfo.dow, weekInfo.doy);
+}
+
+export function getWeeksInWeekYear() {
+ var weekInfo = this.localeData()._week;
+ return weeksInYear(this.weekYear(), weekInfo.dow, weekInfo.doy);
+}
+
+function getSetWeekYearHelper(input, week, weekday, dow, doy) {
+ var weeksTarget;
+ if (input == null) {
+ return weekOfYear(this, dow, doy).year;
+ } else {
+ weeksTarget = weeksInYear(input, dow, doy);
+ if (week > weeksTarget) {
+ week = weeksTarget;
+ }
+ return setWeekAll.call(this, input, week, weekday, dow, doy);
+ }
+}
+
+function setWeekAll(weekYear, week, weekday, dow, doy) {
+ var dayOfYearData = dayOfYearFromWeeks(weekYear, week, weekday, dow, doy),
+ date = createUTCDate(dayOfYearData.year, 0, dayOfYearData.dayOfYear);
+
+ this.year(date.getUTCFullYear());
+ this.month(date.getUTCMonth());
+ this.date(date.getUTCDate());
+ return this;
+}