registration
This commit is contained in:
33
frontend/style/node_modules/date-fns/roundToNearestMinutes.js
generated
vendored
33
frontend/style/node_modules/date-fns/roundToNearestMinutes.js
generated
vendored
@@ -1,8 +1,6 @@
|
||||
"use strict";
|
||||
exports.roundToNearestMinutes = roundToNearestMinutes;
|
||||
var _index = require("./_lib/getRoundingMethod.js");
|
||||
var _index2 = require("./constructFrom.js");
|
||||
var _index3 = require("./toDate.js");
|
||||
import { getRoundingMethod } from "./_lib/getRoundingMethod.js";
|
||||
import { constructFrom } from "./constructFrom.js";
|
||||
import { toDate } from "./toDate.js";
|
||||
|
||||
/**
|
||||
* The {@link roundToNearestMinutes} function options.
|
||||
@@ -18,6 +16,7 @@ var _index3 = require("./toDate.js");
|
||||
* Rounds up when the given date is exactly between the nearest round minutes.
|
||||
*
|
||||
* @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 round
|
||||
* @param options - An object with options.
|
||||
@@ -44,25 +43,25 @@ var _index3 = require("./toDate.js");
|
||||
* const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), { roundingMethod: 'ceil', nearestTo: 30 })
|
||||
* //=> Thu Jul 10 2014 12:30:00
|
||||
*/
|
||||
function roundToNearestMinutes(date, options) {
|
||||
export function roundToNearestMinutes(date, options) {
|
||||
const nearestTo = options?.nearestTo ?? 1;
|
||||
|
||||
if (nearestTo < 1 || nearestTo > 30)
|
||||
return (0, _index2.constructFrom)(date, NaN);
|
||||
if (nearestTo < 1 || nearestTo > 30) return constructFrom(date, NaN);
|
||||
|
||||
const _date = (0, _index3.toDate)(date);
|
||||
const fractionalSeconds = _date.getSeconds() / 60;
|
||||
const fractionalMilliseconds = _date.getMilliseconds() / 1000 / 60;
|
||||
const date_ = toDate(date, options?.in);
|
||||
const fractionalSeconds = date_.getSeconds() / 60;
|
||||
const fractionalMilliseconds = date_.getMilliseconds() / 1000 / 60;
|
||||
const minutes =
|
||||
_date.getMinutes() + fractionalSeconds + fractionalMilliseconds;
|
||||
date_.getMinutes() + fractionalSeconds + fractionalMilliseconds;
|
||||
|
||||
// Unlike the `differenceIn*` functions, the default rounding behavior is `round` and not 'trunc'
|
||||
const method = options?.roundingMethod ?? "round";
|
||||
const roundingMethod = (0, _index.getRoundingMethod)(method);
|
||||
const roundingMethod = getRoundingMethod(method);
|
||||
|
||||
const roundedMinutes = roundingMethod(minutes / nearestTo) * nearestTo;
|
||||
|
||||
const result = (0, _index2.constructFrom)(date, _date);
|
||||
result.setMinutes(roundedMinutes, 0, 0);
|
||||
return result;
|
||||
date_.setMinutes(roundedMinutes, 0, 0);
|
||||
return date_;
|
||||
}
|
||||
|
||||
// Fallback for modularized imports:
|
||||
export default roundToNearestMinutes;
|
||||
|
||||
Reference in New Issue
Block a user