registration

This commit is contained in:
User
2025-02-02 16:08:03 +03:00
parent 7f6495eb4d
commit 78afbaed71
6334 changed files with 196774 additions and 165754 deletions

View File

@@ -1,10 +1,8 @@
"use strict";
exports.getWeekOfMonth = getWeekOfMonth;
var _index = require("./getDate.js");
var _index2 = require("./getDay.js");
var _index3 = require("./startOfMonth.js");
var _index4 = require("./_lib/defaultOptions.js");
import { getDefaultOptions } from "./_lib/defaultOptions.js";
import { getDate } from "./getDate.js";
import { getDay } from "./getDay.js";
import { startOfMonth } from "./startOfMonth.js";
import { toDate } from "./toDate.js";
/**
* The {@link getWeekOfMonth} function options.
@@ -18,8 +16,6 @@ var _index4 = require("./_lib/defaultOptions.js");
* @description
* Get the week of the month of the given date.
*
* @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
*
* @param date - The given date
* @param options - An object with options.
*
@@ -30,8 +26,8 @@ var _index4 = require("./_lib/defaultOptions.js");
* const result = getWeekOfMonth(new Date(2017, 10, 9))
* //=> 2
*/
function getWeekOfMonth(date, options) {
const defaultOptions = (0, _index4.getDefaultOptions)();
export function getWeekOfMonth(date, options) {
const defaultOptions = getDefaultOptions();
const weekStartsOn =
options?.weekStartsOn ??
options?.locale?.options?.weekStartsOn ??
@@ -39,10 +35,10 @@ function getWeekOfMonth(date, options) {
defaultOptions.locale?.options?.weekStartsOn ??
0;
const currentDayOfMonth = (0, _index.getDate)(date);
const currentDayOfMonth = getDate(toDate(date, options?.in));
if (isNaN(currentDayOfMonth)) return NaN;
const startWeekDay = (0, _index2.getDay)((0, _index3.startOfMonth)(date));
const startWeekDay = getDay(startOfMonth(date, options));
let lastDayOfFirstWeek = weekStartsOn - startWeekDay;
if (lastDayOfFirstWeek <= 0) lastDayOfFirstWeek += 7;
@@ -50,3 +46,6 @@ function getWeekOfMonth(date, options) {
const remainingDaysAfterFirstWeek = currentDayOfMonth - lastDayOfFirstWeek;
return Math.ceil(remainingDaysAfterFirstWeek / 7) + 1;
}
// Fallback for modularized imports:
export default getWeekOfMonth;