summaryrefslogtreecommitdiff
path: root/date-fns/src/millisecondsToMinutes
diff options
context:
space:
mode:
Diffstat (limited to 'date-fns/src/millisecondsToMinutes')
-rw-r--r--date-fns/src/millisecondsToMinutes/index.d.ts4
-rw-r--r--date-fns/src/millisecondsToMinutes/index.js.flow52
-rw-r--r--date-fns/src/millisecondsToMinutes/index.ts31
-rw-r--r--date-fns/src/millisecondsToMinutes/test.ts21
4 files changed, 108 insertions, 0 deletions
diff --git a/date-fns/src/millisecondsToMinutes/index.d.ts b/date-fns/src/millisecondsToMinutes/index.d.ts
new file mode 100644
index 0000000..ea00809
--- /dev/null
+++ b/date-fns/src/millisecondsToMinutes/index.d.ts
@@ -0,0 +1,4 @@
+// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
+
+import { millisecondsToMinutes } from 'date-fns'
+export default millisecondsToMinutes
diff --git a/date-fns/src/millisecondsToMinutes/index.js.flow b/date-fns/src/millisecondsToMinutes/index.js.flow
new file mode 100644
index 0000000..c998756
--- /dev/null
+++ b/date-fns/src/millisecondsToMinutes/index.js.flow
@@ -0,0 +1,52 @@
+// @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: (milliseconds: number) => number
diff --git a/date-fns/src/millisecondsToMinutes/index.ts b/date-fns/src/millisecondsToMinutes/index.ts
new file mode 100644
index 0000000..b4529f2
--- /dev/null
+++ b/date-fns/src/millisecondsToMinutes/index.ts
@@ -0,0 +1,31 @@
+import requiredArgs from '../_lib/requiredArgs/index'
+import { millisecondsInMinute } from '../constants/index'
+
+/**
+ * @name millisecondsToMinutes
+ * @category Conversion Helpers
+ * @summary Convert milliseconds to minutes.
+ *
+ * @description
+ * Convert a number of milliseconds to a full number of minutes.
+ *
+ * @param {number} milliseconds - number of milliseconds to be converted.
+ *
+ * @returns {number} the number of milliseconds converted in minutes
+ * @throws {TypeError} 1 argument required
+ *
+ * @example
+ * // Convert 60000 milliseconds to minutes:
+ * const result = millisecondsToMinutes(60000)
+ * //=> 1
+ *
+ * @example
+ * // It uses floor rounding:
+ * const result = millisecondsToMinutes(119999)
+ * //=> 1
+ */
+export default function millisecondsToMinutes(milliseconds: number): number {
+ requiredArgs(1, arguments)
+ const minutes = milliseconds / millisecondsInMinute
+ return Math.floor(minutes)
+}
diff --git a/date-fns/src/millisecondsToMinutes/test.ts b/date-fns/src/millisecondsToMinutes/test.ts
new file mode 100644
index 0000000..3d14345
--- /dev/null
+++ b/date-fns/src/millisecondsToMinutes/test.ts
@@ -0,0 +1,21 @@
+/* eslint-env mocha */
+
+import assert from 'assert'
+import millisecondsToMinutes from '.'
+
+describe('millisecondsToMinutes', () => {
+ it('converts milliseconds to minutes', function () {
+ assert(millisecondsToMinutes(60000) === 1)
+ assert(millisecondsToMinutes(120000) === 2)
+ })
+
+ it('uses floor rounding', () => {
+ assert(millisecondsToMinutes(60001) === 1)
+ assert(millisecondsToMinutes(59999) === 0)
+ })
+
+ it('handles border values', () => {
+ assert(millisecondsToMinutes(60000.5) === 1)
+ assert(millisecondsToMinutes(0) === 0)
+ })
+})