Socket
Socket
Sign inDemoInstall

date-fns

Package Overview
Dependencies
0
Maintainers
1
Versions
200
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.0 to 3.2.0

_lib/getRoundingMethod.d.mts

13

differenceInHours.js
"use strict";
exports.differenceInHours = differenceInHours;
var _index = require("./constants.js");
var _index2 = require("./differenceInMilliseconds.js");
var _index = require("./_lib/getRoundingMethod.js");
var _index2 = require("./constants.js");
var _index3 = require("./differenceInMilliseconds.js");
var _index3 = require("./_lib/roundingMethods.js");
/**

@@ -38,5 +37,5 @@ * The {@link differenceInHours} function options.

const diff =
(0, _index2.differenceInMilliseconds)(dateLeft, dateRight) /
_index.millisecondsInHour;
return (0, _index3.getRoundingMethod)(options?.roundingMethod)(diff);
(0, _index3.differenceInMilliseconds)(dateLeft, dateRight) /
_index2.millisecondsInHour;
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
}
"use strict";
exports.differenceInMinutes = differenceInMinutes;
var _index = require("./constants.js");
var _index2 = require("./differenceInMilliseconds.js");
var _index = require("./_lib/getRoundingMethod.js");
var _index2 = require("./constants.js");
var _index3 = require("./differenceInMilliseconds.js");
var _index3 = require("./_lib/roundingMethods.js");
/**

@@ -46,5 +45,5 @@ * The {@link differenceInMinutes} function options.

const diff =
(0, _index2.differenceInMilliseconds)(dateLeft, dateRight) /
_index.millisecondsInMinute;
return (0, _index3.getRoundingMethod)(options?.roundingMethod)(diff);
(0, _index3.differenceInMilliseconds)(dateLeft, dateRight) /
_index2.millisecondsInMinute;
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
}
"use strict";
exports.differenceInQuarters = differenceInQuarters;
var _index = require("./differenceInMonths.js");
var _index = require("./_lib/getRoundingMethod.js");
var _index2 = require("./differenceInMonths.js");
var _index2 = require("./_lib/roundingMethods.js");
/**

@@ -33,4 +32,4 @@ * The {@link differenceInQuarters} function options.

function differenceInQuarters(dateLeft, dateRight, options) {
const diff = (0, _index.differenceInMonths)(dateLeft, dateRight) / 3;
return (0, _index2.getRoundingMethod)(options?.roundingMethod)(diff);
const diff = (0, _index2.differenceInMonths)(dateLeft, dateRight) / 3;
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
}
"use strict";
exports.differenceInSeconds = differenceInSeconds;
var _index = require("./differenceInMilliseconds.js");
var _index = require("./_lib/getRoundingMethod.js");
var _index2 = require("./differenceInMilliseconds.js");
var _index2 = require("./_lib/roundingMethods.js");
/**

@@ -37,4 +36,5 @@ * The {@link differenceInSeconds} function options.

function differenceInSeconds(dateLeft, dateRight, options) {
const diff = (0, _index.differenceInMilliseconds)(dateLeft, dateRight) / 1000;
return (0, _index2.getRoundingMethod)(options?.roundingMethod)(diff);
const diff =
(0, _index2.differenceInMilliseconds)(dateLeft, dateRight) / 1000;
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
}
"use strict";
exports.differenceInWeeks = differenceInWeeks;
var _index = require("./differenceInDays.js");
var _index = require("./_lib/getRoundingMethod.js");
var _index2 = require("./differenceInDays.js");
var _index2 = require("./_lib/roundingMethods.js");
/**

@@ -54,4 +53,4 @@ * The {@link differenceInWeeks} function options.

function differenceInWeeks(dateLeft, dateRight, options) {
const diff = (0, _index.differenceInDays)(dateLeft, dateRight) / 7;
return (0, _index2.getRoundingMethod)(options?.roundingMethod)(diff);
const diff = (0, _index2.differenceInDays)(dateLeft, dateRight) / 7;
return (0, _index.getRoundingMethod)(options?.roundingMethod)(diff);
}

@@ -7,2 +7,5 @@ import type {

} from "./types.js";
import { formatters } from "./_lib/format/formatters.js";
import { longFormatters } from "./_lib/format/longFormatters.js";
export { longFormatters, formatters };
/**

@@ -9,0 +12,0 @@ * The {@link format} function options.

"use strict";
exports.format = format;
Object.defineProperty(exports, "formatters", {
enumerable: true,
get: function () {
return _index5.formatters;
},
});
Object.defineProperty(exports, "longFormatters", {
enumerable: true,
get: function () {
return _index6.longFormatters;
},
});
var _index = require("./isValid.js");

@@ -12,2 +24,5 @@ var _index2 = require("./toDate.js");

// Rexports of internal for libraries to use.
// See: https://github.com/date-fns/date-fns/issues/3638#issuecomment-1877082874
// This RegExp consists of three parts separated by `|`:

@@ -14,0 +29,0 @@ // - [yYQqMLwIdDecihHKkms]o matches any available ordinal number token

"use strict";
exports.formatDistanceStrict = formatDistanceStrict;
var _index = require("./compareAsc.js");
var _index2 = require("./constants.js");
var _index = require("./_lib/defaultLocale.js");
var _index2 = require("./_lib/defaultOptions.js");
var _index3 = require("./_lib/getRoundingMethod.js");
var _index4 = require("./_lib/getTimezoneOffsetInMilliseconds.js");
var _index5 = require("./compareAsc.js");
var _index6 = require("./constants.js");
var _index3 = require("./toDate.js");
var _index7 = require("./toDate.js");
var _index4 = require("./_lib/defaultLocale.js");
var _index5 = require("./_lib/defaultOptions.js");
var _index6 = require("./_lib/getTimezoneOffsetInMilliseconds.js");
var _index7 = require("./_lib/roundingMethods.js");
/**

@@ -102,7 +101,7 @@ * The {@link formatDistanceStrict} function options.

function formatDistanceStrict(date, baseDate, options) {
const defaultOptions = (0, _index5.getDefaultOptions)();
const defaultOptions = (0, _index2.getDefaultOptions)();
const locale =
options?.locale ?? defaultOptions.locale ?? _index4.defaultLocale;
options?.locale ?? defaultOptions.locale ?? _index.defaultLocale;
const comparison = (0, _index.compareAsc)(date, baseDate);
const comparison = (0, _index5.compareAsc)(date, baseDate);

@@ -121,10 +120,10 @@ if (isNaN(comparison)) {

if (comparison > 0) {
dateLeft = (0, _index3.toDate)(baseDate);
dateRight = (0, _index3.toDate)(date);
dateLeft = (0, _index7.toDate)(baseDate);
dateRight = (0, _index7.toDate)(date);
} else {
dateLeft = (0, _index3.toDate)(date);
dateRight = (0, _index3.toDate)(baseDate);
dateLeft = (0, _index7.toDate)(date);
dateRight = (0, _index7.toDate)(baseDate);
}
const roundingMethod = (0, _index7.getRoundingMethod)(
const roundingMethod = (0, _index3.getRoundingMethod)(
options?.roundingMethod ?? "round",

@@ -134,7 +133,7 @@ );

const milliseconds = dateRight.getTime() - dateLeft.getTime();
const minutes = milliseconds / _index2.millisecondsInMinute;
const minutes = milliseconds / _index6.millisecondsInMinute;
const timezoneOffset =
(0, _index6.getTimezoneOffsetInMilliseconds)(dateRight) -
(0, _index6.getTimezoneOffsetInMilliseconds)(dateLeft);
(0, _index4.getTimezoneOffsetInMilliseconds)(dateRight) -
(0, _index4.getTimezoneOffsetInMilliseconds)(dateLeft);

@@ -144,3 +143,3 @@ // Use DST-normalized difference in minutes for years, months and days;

const dstNormalizedMinutes =
(milliseconds - timezoneOffset) / _index2.millisecondsInMinute;
(milliseconds - timezoneOffset) / _index6.millisecondsInMinute;

@@ -154,7 +153,7 @@ const defaultUnit = options?.unit;

unit = "minute";
} else if (minutes < _index2.minutesInDay) {
} else if (minutes < _index6.minutesInDay) {
unit = "hour";
} else if (dstNormalizedMinutes < _index2.minutesInMonth) {
} else if (dstNormalizedMinutes < _index6.minutesInMonth) {
unit = "day";
} else if (dstNormalizedMinutes < _index2.minutesInYear) {
} else if (dstNormalizedMinutes < _index6.minutesInYear) {
unit = "month";

@@ -185,3 +184,3 @@ } else {

} else if (unit === "day") {
const days = roundingMethod(dstNormalizedMinutes / _index2.minutesInDay);
const days = roundingMethod(dstNormalizedMinutes / _index6.minutesInDay);
return locale.formatDistance("xDays", days, localizeOptions);

@@ -192,3 +191,3 @@

const months = roundingMethod(
dstNormalizedMinutes / _index2.minutesInMonth,
dstNormalizedMinutes / _index6.minutesInMonth,
);

@@ -201,5 +200,5 @@ return months === 12 && defaultUnit !== "month"

} else {
const years = roundingMethod(dstNormalizedMinutes / _index2.minutesInYear);
const years = roundingMethod(dstNormalizedMinutes / _index6.minutesInYear);
return locale.formatDistance("xYears", years, localizeOptions);
}
}

@@ -38,9 +38,9 @@ /**

/**
* Curried version of the function. Returns itself.
*/
(): FPFn1<Result, Arg>;
/**
* Returns the result of the function call.
*/
(arg: Arg): Result;
/**
* Curried version of the function. Returns itself.
*/
(): FPFn1<Result, Arg>;
}

@@ -52,5 +52,5 @@ /**

/**
* Returns the result of the function call.
* Curried version of the function. Returns itself.
*/
(arg2: Arg2, arg1: Arg1): Result;
(): FPFn2<Result, Arg2, Arg1>;
/**

@@ -62,5 +62,5 @@ * Curried version of the function. Returns a function that accepts the rest

/**
* Curried version of the function. Returns itself.
* Returns the result of the function call.
*/
(): FPFn2<Result, Arg2, Arg1>;
(arg2: Arg2, arg1: Arg1): Result;
}

@@ -72,5 +72,5 @@ /**

/**
* Returns the result of the function call.
* Curried version of the function. Returns itself.
*/
(arg3: Arg3, arg2: Arg2, arg1: Arg1): Result;
(): FPFn3<Result, Arg3, Arg2, Arg1>;
/**

@@ -80,3 +80,3 @@ * Curried version of the function. Returns a function that accepts the rest

*/
(arg3: Arg3, arg2: Arg2): FPFn1<Result, Arg1>;
(arg3: Arg3): FPFn2<Result, Arg2, Arg1>;
/**

@@ -86,7 +86,7 @@ * Curried version of the function. Returns a function that accepts the rest

*/
(arg3: Arg3): FPFn2<Result, Arg2, Arg1>;
(arg3: Arg3, arg2: Arg2): FPFn1<Result, Arg1>;
/**
* Curried version of the function. Returns itself.
* Returns the result of the function call.
*/
(): FPFn3<Result, Arg3, Arg2, Arg1>;
(arg3: Arg3, arg2: Arg2, arg1: Arg1): Result;
}

@@ -98,5 +98,5 @@ /**

/**
* Returns the result of the function call.
* Curried version of the function. Returns itself.
*/
(arg4: Arg4, arg3: Arg3, arg2: Arg2, arg1: Arg1): Result;
(): FPFn4<Result, Arg4, Arg3, Arg2, Arg1>;
/**

@@ -106,3 +106,3 @@ * Curried version of the function. Returns a function that accepts the rest

*/
(arg4: Arg4, arg3: Arg3, arg2: Arg2): FPFn1<Result, Arg1>;
(arg4: Arg4): FPFn3<Result, Arg3, Arg2, Arg1>;
/**

@@ -117,7 +117,7 @@ * Curried version of the function. Returns a function that accepts the rest

*/
(arg4: Arg4): FPFn3<Result, Arg3, Arg2, Arg1>;
(arg4: Arg4, arg3: Arg3, arg2: Arg2): FPFn1<Result, Arg1>;
/**
* Curried version of the function. Returns itself.
* Returns the result of the function call.
*/
(): FPFn4<Result, Arg4, Arg3, Arg2, Arg1>;
(arg4: Arg4, arg3: Arg3, arg2: Arg2, arg1: Arg1): Result;
}

@@ -0,1 +1,3 @@

import { lightFormatters } from "./_lib/format/lightFormatters.js";
export { lightFormatters };
/**

@@ -2,0 +4,0 @@ * @name lightFormat

"use strict";
exports.lightFormat = lightFormat;
Object.defineProperty(exports, "lightFormatters", {
enumerable: true,
get: function () {
return _index3.lightFormatters;
},
});
var _index = require("./isValid.js");

@@ -7,2 +13,5 @@ var _index2 = require("./toDate.js");

// Rexports of internal for libraries to use.
// See: https://github.com/date-fns/date-fns/issues/3638#issuecomment-1877082874
// This RegExp consists of three parts separated by `|`:

@@ -9,0 +18,0 @@ // - (\w)\1* matches any sequences of the same letter

@@ -7,2 +7,5 @@ import type {

} from "./types.js";
import { longFormatters } from "./_lib/format/longFormatters.js";
import { parsers } from "./parse/_lib/parsers.js";
export { longFormatters, parsers };
/**

@@ -9,0 +12,0 @@ * The {@link parse} function options.

"use strict";
Object.defineProperty(exports, "longFormatters", {
enumerable: true,
get: function () {
return _index5.longFormatters;
},
});
exports.parse = parse;
Object.defineProperty(exports, "parsers", {
enumerable: true,
get: function () {
return _index7.parsers;
},
});
var _index = require("./constructFrom.js");

@@ -15,2 +27,5 @@ var _index2 = require("./getDefaultOptions.js");

// Rexports of internal for libraries to use.
// See: https://github.com/date-fns/date-fns/issues/3638#issuecomment-1877082874
/**

@@ -17,0 +32,0 @@ * The {@link parse} function options.

@@ -30,6 +30,15 @@ import type { NearestMinutesOptions, RoundingOptions } from "./types.js";

* @example
* // Round 10 July 2014 12:07:30 to nearest quarter hour:
* // Round 10 July 2014 12:12:34 to nearest quarter hour:
* const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), { nearestTo: 15 })
* // rounds up because given date is exactly between 12:00:00 and 12:15:00
* //=> Thu Jul 10 2014 12:15:00
*
* @example
* // Floor (rounds down) 10 July 2014 12:12:34 to nearest minute:
* const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), { roundingMethod: 'floor' })
* //=> Thu Jul 10 2014 12:12:00
*
* @example
* // Ceil (rounds up) 10 July 2014 12:12:34 to nearest half hour:
* const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), { roundingMethod: 'ceil', nearestTo: 30 })
* //=> Thu Jul 10 2014 12:30:00
*/

@@ -36,0 +45,0 @@ export declare function roundToNearestMinutes<DateType extends Date>(

"use strict";
exports.roundToNearestMinutes = roundToNearestMinutes;
var _index = require("./constructFrom.js");
var _index2 = require("./toDate.js");
var _index = require("./_lib/getRoundingMethod.js");
var _index2 = require("./constructFrom.js");
var _index3 = require("./toDate.js");
var _index3 = require("./_lib/roundingMethods.js");
/**

@@ -34,6 +33,15 @@ * The {@link roundToNearestMinutes} function options.

* @example
* // Round 10 July 2014 12:07:30 to nearest quarter hour:
* // Round 10 July 2014 12:12:34 to nearest quarter hour:
* const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), { nearestTo: 15 })
* // rounds up because given date is exactly between 12:00:00 and 12:15:00
* //=> Thu Jul 10 2014 12:15:00
*
* @example
* // Floor (rounds down) 10 July 2014 12:12:34 to nearest minute:
* const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), { roundingMethod: 'floor' })
* //=> Thu Jul 10 2014 12:12:00
*
* @example
* // Ceil (rounds up) 10 July 2014 12:12:34 to nearest half hour:
* const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34), { roundingMethod: 'ceil', nearestTo: 30 })
* //=> Thu Jul 10 2014 12:30:00
*/

@@ -44,17 +52,19 @@ function roundToNearestMinutes(date, options) {

if (nearestTo < 1 || nearestTo > 30)
return (0, _index.constructFrom)(date, NaN);
return (0, _index2.constructFrom)(date, NaN);
const _date = (0, _index2.toDate)(date);
const seconds = _date.getSeconds(); // relevant if nearestTo is 1, which is the default case
const minutes = _date.getMinutes() + seconds / 60;
const roundingMethod = (0, _index3.getRoundingMethod)(
options?.roundingMethod,
);
const _date = (0, _index3.toDate)(date);
const fractionalSeconds = _date.getSeconds() / 60;
const fractionalMilliseconds = _date.getMilliseconds() / 1000 / 60;
const minutes =
_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 roundedMinutes = roundingMethod(minutes / nearestTo) * nearestTo;
const remainderMinutes = minutes % nearestTo;
const addedMinutes = Math.round(remainderMinutes / nearestTo) * nearestTo;
const result = (0, _index.constructFrom)(_date, _date);
result.setMinutes(roundedMinutes + addedMinutes, 0, 0);
const result = (0, _index2.constructFrom)(date, _date);
result.setMinutes(roundedMinutes, 0, 0);
return result;
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc