aboutsummaryrefslogtreecommitdiffstats
path: root/node_modules/date-fns/esm/roundToNearestMinutes
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/date-fns/esm/roundToNearestMinutes')
-rw-r--r--node_modules/date-fns/esm/roundToNearestMinutes/index.d.ts4
-rw-r--r--node_modules/date-fns/esm/roundToNearestMinutes/index.js49
-rw-r--r--node_modules/date-fns/esm/roundToNearestMinutes/index.js.flow58
-rw-r--r--node_modules/date-fns/esm/roundToNearestMinutes/package.json4
4 files changed, 115 insertions, 0 deletions
diff --git a/node_modules/date-fns/esm/roundToNearestMinutes/index.d.ts b/node_modules/date-fns/esm/roundToNearestMinutes/index.d.ts
new file mode 100644
index 0000000..8e56491
--- /dev/null
+++ b/node_modules/date-fns/esm/roundToNearestMinutes/index.d.ts
@@ -0,0 +1,4 @@
+// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
+
+import { roundToNearestMinutes } from 'date-fns'
+export default roundToNearestMinutes
diff --git a/node_modules/date-fns/esm/roundToNearestMinutes/index.js b/node_modules/date-fns/esm/roundToNearestMinutes/index.js
new file mode 100644
index 0000000..bfac929
--- /dev/null
+++ b/node_modules/date-fns/esm/roundToNearestMinutes/index.js
@@ -0,0 +1,49 @@
+import toDate from "../toDate/index.js";
+import { getRoundingMethod } from "../_lib/roundingMethods/index.js";
+import toInteger from "../_lib/toInteger/index.js";
+/**
+ * @name roundToNearestMinutes
+ * @category Minute Helpers
+ * @summary Rounds the given date to the nearest minute
+ *
+ * @description
+ * Rounds the given date to the nearest minute (or number of minutes).
+ * Rounds up when the given date is exactly between the nearest round minutes.
+ *
+ * @param {Date|Number} date - the date to round
+ * @param {Object} [options] - an object with options.
+ * @param {Number} [options.nearestTo=1] - nearest number of minutes to round to. E.g. `15` to round to quarter hours.
+ * @param {String} [options.roundingMethod='trunc'] - a rounding method (`ceil`, `floor`, `round` or `trunc`)
+ * @returns {Date} the new date rounded to the closest minute
+ * @throws {TypeError} 1 argument required
+ * @throws {RangeError} `options.nearestTo` must be between 1 and 30
+ *
+ * @example
+ * // Round 10 July 2014 12:12:34 to nearest minute:
+ * const result = roundToNearestMinutes(new Date(2014, 6, 10, 12, 12, 34))
+ * //=> Thu Jul 10 2014 12:13:00
+ *
+ * @example
+ * // Round 10 July 2014 12:07:30 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
+ */
+export default function roundToNearestMinutes(dirtyDate, options) {
+ var _options$nearestTo;
+ if (arguments.length < 1) {
+ throw new TypeError('1 argument required, but only none provided present');
+ }
+ var nearestTo = toInteger((_options$nearestTo = options === null || options === void 0 ? void 0 : options.nearestTo) !== null && _options$nearestTo !== void 0 ? _options$nearestTo : 1);
+ if (nearestTo < 1 || nearestTo > 30) {
+ throw new RangeError('`options.nearestTo` must be between 1 and 30');
+ }
+ var date = toDate(dirtyDate);
+ var seconds = date.getSeconds(); // relevant if nearestTo is 1, which is the default case
+ var minutes = date.getMinutes() + seconds / 60;
+ var roundingMethod = getRoundingMethod(options === null || options === void 0 ? void 0 : options.roundingMethod);
+ var roundedMinutes = roundingMethod(minutes / nearestTo) * nearestTo;
+ var remainderMinutes = minutes % nearestTo;
+ var addedMinutes = Math.round(remainderMinutes / nearestTo) * nearestTo;
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), roundedMinutes + addedMinutes);
+} \ No newline at end of file
diff --git a/node_modules/date-fns/esm/roundToNearestMinutes/index.js.flow b/node_modules/date-fns/esm/roundToNearestMinutes/index.js.flow
new file mode 100644
index 0000000..41b3dfa
--- /dev/null
+++ b/node_modules/date-fns/esm/roundToNearestMinutes/index.js.flow
@@ -0,0 +1,58 @@
+// @flow
+// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
+
+export type Interval = {
+ start: Date | number,
+ end: Date | number,
+}
+
+export type Locale = {
+ code?: string,
+ formatDistance?: (...args: Array<any>) => any,
+ formatRelative?: (...args: Array<any>) => any,
+ localize?: {
+ ordinalNumber: (...args: Array<any>) => any,
+ era: (...args: Array<any>) => any,
+ quarter: (...args: Array<any>) => any,
+ month: (...args: Array<any>) => any,
+ day: (...args: Array<any>) => any,
+ dayPeriod: (...args: Array<any>) => any,
+ },
+ formatLong?: {
+ date: (...args: Array<any>) => any,
+ time: (...args: Array<any>) => any,
+ dateTime: (...args: Array<any>) => any,
+ },
+ match?: {
+ ordinalNumber: (...args: Array<any>) => any,
+ era: (...args: Array<any>) => any,
+ quarter: (...args: Array<any>) => any,
+ month: (...args: Array<any>) => any,
+ day: (...args: Array<any>) => any,
+ dayPeriod: (...args: Array<any>) => any,
+ },
+ options?: {
+ weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
+ firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7,
+ },
+}
+
+export type Duration = {
+ years?: number,
+ months?: number,
+ weeks?: number,
+ days?: number,
+ hours?: number,
+ minutes?: number,
+ seconds?: number,
+}
+
+export type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
+
+declare module.exports: (
+ date: Date | number,
+ options?: {
+ nearestTo?: number,
+ roundingMethod?: string,
+ }
+) => Date
diff --git a/node_modules/date-fns/esm/roundToNearestMinutes/package.json b/node_modules/date-fns/esm/roundToNearestMinutes/package.json
new file mode 100644
index 0000000..b109f05
--- /dev/null
+++ b/node_modules/date-fns/esm/roundToNearestMinutes/package.json
@@ -0,0 +1,4 @@
+{
+ "sideEffects": false,
+ "typings": "../../typings.d.ts"
+} \ No newline at end of file
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage