registration
This commit is contained in:
40
frontend/style/node_modules/date-fns/eachYearOfInterval.js
generated
vendored
40
frontend/style/node_modules/date-fns/eachYearOfInterval.js
generated
vendored
@@ -1,11 +1,17 @@
|
||||
"use strict";
|
||||
exports.eachYearOfInterval = eachYearOfInterval;
|
||||
var _index = require("./toDate.js");
|
||||
import { normalizeInterval } from "./_lib/normalizeInterval.js";
|
||||
import { constructFrom } from "./constructFrom.js";
|
||||
|
||||
/**
|
||||
* The {@link eachYearOfInterval} function options.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The {@link eachYearOfInterval} function result type. It resolves the proper data type.
|
||||
* It uses the first argument date object type, starting from the date argument,
|
||||
* then the start interval date, and finally the end interval date. If
|
||||
* a context function is passed, it uses the context function return type.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @name eachYearOfInterval
|
||||
* @category Interval Helpers
|
||||
@@ -14,9 +20,11 @@ var _index = require("./toDate.js");
|
||||
* @description
|
||||
* Return the array of yearly timestamps within the specified time interval.
|
||||
*
|
||||
* @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 IntervalType - Interval type.
|
||||
* @typeParam Options - Options type.
|
||||
*
|
||||
* @param interval - The interval.
|
||||
* @param options - An object with options.
|
||||
*
|
||||
* @returns The array with starts of yearly timestamps from the month of the interval start to the month of the interval end
|
||||
*
|
||||
@@ -33,15 +41,14 @@ var _index = require("./toDate.js");
|
||||
* // Sun Jan 01 2017 00:00:00
|
||||
* // ]
|
||||
*/
|
||||
function eachYearOfInterval(interval, options) {
|
||||
const startDate = (0, _index.toDate)(interval.start);
|
||||
const endDate = (0, _index.toDate)(interval.end);
|
||||
export function eachYearOfInterval(interval, options) {
|
||||
const { start, end } = normalizeInterval(options?.in, interval);
|
||||
|
||||
let reversed = +startDate > +endDate;
|
||||
const endTime = reversed ? +startDate : +endDate;
|
||||
const currentDate = reversed ? endDate : startDate;
|
||||
currentDate.setHours(0, 0, 0, 0);
|
||||
currentDate.setMonth(0, 1);
|
||||
let reversed = +start > +end;
|
||||
const endTime = reversed ? +start : +end;
|
||||
const date = reversed ? end : start;
|
||||
date.setHours(0, 0, 0, 0);
|
||||
date.setMonth(0, 1);
|
||||
|
||||
let step = options?.step ?? 1;
|
||||
if (!step) return [];
|
||||
@@ -52,10 +59,13 @@ function eachYearOfInterval(interval, options) {
|
||||
|
||||
const dates = [];
|
||||
|
||||
while (+currentDate <= endTime) {
|
||||
dates.push((0, _index.toDate)(currentDate));
|
||||
currentDate.setFullYear(currentDate.getFullYear() + step);
|
||||
while (+date <= endTime) {
|
||||
dates.push(constructFrom(start, date));
|
||||
date.setFullYear(date.getFullYear() + step);
|
||||
}
|
||||
|
||||
return reversed ? dates.reverse() : dates;
|
||||
}
|
||||
|
||||
// Fallback for modularized imports:
|
||||
export default eachYearOfInterval;
|
||||
|
||||
Reference in New Issue
Block a user