summaryrefslogtreecommitdiff
path: root/date-fns/src/minutesToMilliseconds
diff options
context:
space:
mode:
Diffstat (limited to 'date-fns/src/minutesToMilliseconds')
-rw-r--r--date-fns/src/minutesToMilliseconds/index.d.ts4
-rw-r--r--date-fns/src/minutesToMilliseconds/index.js.flow52
-rw-r--r--date-fns/src/minutesToMilliseconds/index.ts25
-rw-r--r--date-fns/src/minutesToMilliseconds/test.ts20
4 files changed, 101 insertions, 0 deletions
diff --git a/date-fns/src/minutesToMilliseconds/index.d.ts b/date-fns/src/minutesToMilliseconds/index.d.ts
new file mode 100644
index 0000000..14b5513
--- /dev/null
+++ b/date-fns/src/minutesToMilliseconds/index.d.ts
@@ -0,0 +1,4 @@
+// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
+
+import { minutesToMilliseconds } from 'date-fns'
+export default minutesToMilliseconds
diff --git a/date-fns/src/minutesToMilliseconds/index.js.flow b/date-fns/src/minutesToMilliseconds/index.js.flow
new file mode 100644
index 0000000..efb76c7
--- /dev/null
+++ b/date-fns/src/minutesToMilliseconds/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: (minutes: number) => number
diff --git a/date-fns/src/minutesToMilliseconds/index.ts b/date-fns/src/minutesToMilliseconds/index.ts
new file mode 100644
index 0000000..dd95314
--- /dev/null
+++ b/date-fns/src/minutesToMilliseconds/index.ts
@@ -0,0 +1,25 @@
+import requiredArgs from '../_lib/requiredArgs/index'
+import { millisecondsInMinute } from '../constants/index'
+
+/**
+ * @name minutesToMilliseconds
+ * @category Conversion Helpers
+ * @summary Convert minutes to milliseconds.
+ *
+ * @description
+ * Convert a number of minutes to a full number of milliseconds.
+ *
+ * @param {number} minutes - number of minutes to be converted
+ *
+ * @returns {number} the number of minutes converted in milliseconds
+ * @throws {TypeError} 1 argument required
+ *
+ * @example
+ * // Convert 2 minutes to milliseconds
+ * const result = minutesToMilliseconds(2)
+ * //=> 120000
+ */
+export default function minutesToMilliseconds(minutes: number): number {
+ requiredArgs(1, arguments)
+ return Math.floor(minutes * millisecondsInMinute)
+}
diff --git a/date-fns/src/minutesToMilliseconds/test.ts b/date-fns/src/minutesToMilliseconds/test.ts
new file mode 100644
index 0000000..4864a2b
--- /dev/null
+++ b/date-fns/src/minutesToMilliseconds/test.ts
@@ -0,0 +1,20 @@
+/* eslint-env mocha */
+
+import assert from 'assert'
+import minutesToMilliseconds from '.'
+
+describe('minutesToMilliseconds', function () {
+ it('converts minutes to milliseconds', function () {
+ assert(minutesToMilliseconds(1) === 60000)
+ assert(minutesToMilliseconds(2) === 120000)
+ })
+
+ it('uses floor rounding', () => {
+ assert(minutesToMilliseconds(0.123456) === 7407)
+ })
+
+ it('handles border values', () => {
+ assert(minutesToMilliseconds(1.5) === 90000)
+ assert(minutesToMilliseconds(0) === 0)
+ })
+})