diff options
Diffstat (limited to 'date-fns/src/hoursToMinutes')
-rw-r--r-- | date-fns/src/hoursToMinutes/index.d.ts | 4 | ||||
-rw-r--r-- | date-fns/src/hoursToMinutes/index.js.flow | 52 | ||||
-rw-r--r-- | date-fns/src/hoursToMinutes/index.ts | 25 | ||||
-rw-r--r-- | date-fns/src/hoursToMinutes/test.ts | 20 |
4 files changed, 101 insertions, 0 deletions
diff --git a/date-fns/src/hoursToMinutes/index.d.ts b/date-fns/src/hoursToMinutes/index.d.ts new file mode 100644 index 0000000..d0fbbbf --- /dev/null +++ b/date-fns/src/hoursToMinutes/index.d.ts @@ -0,0 +1,4 @@ +// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. + +import { hoursToMinutes } from 'date-fns' +export default hoursToMinutes diff --git a/date-fns/src/hoursToMinutes/index.js.flow b/date-fns/src/hoursToMinutes/index.js.flow new file mode 100644 index 0000000..950ac71 --- /dev/null +++ b/date-fns/src/hoursToMinutes/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: (hours: number) => number diff --git a/date-fns/src/hoursToMinutes/index.ts b/date-fns/src/hoursToMinutes/index.ts new file mode 100644 index 0000000..dcf61de --- /dev/null +++ b/date-fns/src/hoursToMinutes/index.ts @@ -0,0 +1,25 @@ +import requiredArgs from '../_lib/requiredArgs/index' +import { minutesInHour } from '../constants/index' + +/** + * @name hoursToMinutes + * @category Conversion Helpers + * @summary Convert hours to minutes. + * + * @description + * Convert a number of hours to a full number of minutes. + * + * @param {number} hours - number of hours to be converted + * + * @returns {number} the number of hours converted in minutes + * @throws {TypeError} 1 argument required + * + * @example + * // Convert 2 hours to minutes: + * const result = hoursToMinutes(2) + * //=> 120 + */ +export default function hoursToMinutes(hours: number): number { + requiredArgs(1, arguments) + return Math.floor(hours * minutesInHour) +} diff --git a/date-fns/src/hoursToMinutes/test.ts b/date-fns/src/hoursToMinutes/test.ts new file mode 100644 index 0000000..ead8b21 --- /dev/null +++ b/date-fns/src/hoursToMinutes/test.ts @@ -0,0 +1,20 @@ +/* eslint-env mocha */ + +import assert from 'assert' +import hoursToMinutes from '.' + +describe('hoursToMinutes', function () { + it('converts hours to minutes', function () { + assert(hoursToMinutes(1) === 60) + assert(hoursToMinutes(2) === 120) + }) + + it('uses floor rounding', () => { + assert(hoursToMinutes(0.123) === 7) + }) + + it('handles border values', () => { + assert(hoursToMinutes(1.5) === 90) + assert(hoursToMinutes(0) === 0) + }) +}) |