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,8 +1,10 @@
"use strict";
exports.setMonth = setMonth;
var _index = require("./constructFrom.js");
var _index2 = require("./getDaysInMonth.js");
var _index3 = require("./toDate.js");
import { constructFrom } from "./constructFrom.js";
import { getDaysInMonth } from "./getDaysInMonth.js";
import { toDate } from "./toDate.js";
/**
* The {@link setMonth} function options.
*/
/**
* @name setMonth
@@ -13,9 +15,11 @@ var _index3 = require("./toDate.js");
* Set the month to 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).
* @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
*
* @param date - The date to be changed
* @param month - The month index to set (0-11)
* @param options - The options
*
* @returns The new date with the month set
*
@@ -24,17 +28,20 @@ var _index3 = require("./toDate.js");
* const result = setMonth(new Date(2014, 8, 1), 1)
* //=> Sat Feb 01 2014 00:00:00
*/
function setMonth(date, month) {
const _date = (0, _index3.toDate)(date);
export function setMonth(date, month, options) {
const _date = toDate(date, options?.in);
const year = _date.getFullYear();
const day = _date.getDate();
const dateWithDesiredMonth = (0, _index.constructFrom)(date, 0);
dateWithDesiredMonth.setFullYear(year, month, 15);
dateWithDesiredMonth.setHours(0, 0, 0, 0);
const daysInMonth = (0, _index2.getDaysInMonth)(dateWithDesiredMonth);
// Set the last day of the new month
// if the original date was the last day of the longer month
const midMonth = constructFrom(options?.in || date, 0);
midMonth.setFullYear(year, month, 15);
midMonth.setHours(0, 0, 0, 0);
const daysInMonth = getDaysInMonth(midMonth);
// Set the earlier date, allows to wrap Jan 31 to Feb 28
_date.setMonth(month, Math.min(day, daysInMonth));
return _date;
}
// Fallback for modularized imports:
export default setMonth;