summaryrefslogtreecommitdiff
path: root/date-fns/src/millisecondsToHours
diff options
context:
space:
mode:
Diffstat (limited to 'date-fns/src/millisecondsToHours')
-rw-r--r--date-fns/src/millisecondsToHours/index.d.ts4
-rw-r--r--date-fns/src/millisecondsToHours/index.js.flow52
-rw-r--r--date-fns/src/millisecondsToHours/index.ts31
-rw-r--r--date-fns/src/millisecondsToHours/test.ts22
4 files changed, 109 insertions, 0 deletions
diff --git a/date-fns/src/millisecondsToHours/index.d.ts b/date-fns/src/millisecondsToHours/index.d.ts
new file mode 100644
index 0000000..af90bf8
--- /dev/null
+++ b/date-fns/src/millisecondsToHours/index.d.ts
@@ -0,0 +1,4 @@
+// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
+
+import { millisecondsToHours } from 'date-fns'
+export default millisecondsToHours
diff --git a/date-fns/src/millisecondsToHours/index.js.flow b/date-fns/src/millisecondsToHours/index.js.flow
new file mode 100644
index 0000000..c998756
--- /dev/null
+++ b/date-fns/src/millisecondsToHours/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/millisecondsToHours/index.ts b/date-fns/src/millisecondsToHours/index.ts
new file mode 100644
index 0000000..a843a4d
--- /dev/null
+++ b/date-fns/src/millisecondsToHours/index.ts
@@ -0,0 +1,31 @@
+import requiredArgs from '../_lib/requiredArgs/index'
+import { millisecondsInHour } from '../constants/index'
+
+/**
+ * @name millisecondsToHours
+ * @category Conversion Helpers
+ * @summary Convert milliseconds to hours.
+ *
+ * @description
+ * Convert a number of milliseconds to a full number of hours.
+ *
+ * @param {number} milliseconds - number of milliseconds to be converted
+ *
+ * @returns {number} the number of milliseconds converted in hours
+ * @throws {TypeError} 1 argument required
+ *
+ * @example
+ * // Convert 7200000 milliseconds to hours:
+ * const result = millisecondsToHours(7200000)
+ * //=> 2
+ *
+ * @example
+ * // It uses floor rounding:
+ * const result = millisecondsToHours(7199999)
+ * //=> 1
+ */
+export default function millisecondsToHours(milliseconds: number): number {
+ requiredArgs(1, arguments)
+ const hours = milliseconds / millisecondsInHour
+ return Math.floor(hours)
+}
diff --git a/date-fns/src/millisecondsToHours/test.ts b/date-fns/src/millisecondsToHours/test.ts
new file mode 100644
index 0000000..5fed366
--- /dev/null
+++ b/date-fns/src/millisecondsToHours/test.ts
@@ -0,0 +1,22 @@
+/* eslint-env mocha */
+
+import assert from 'assert'
+import millisecondsToHours from '.'
+
+describe('millisecondsToHours', function () {
+
+ it('converts milliseconds to hours', function () {
+ assert(millisecondsToHours(3600000) === 1)
+ assert(millisecondsToHours(7200000) === 2)
+ })
+
+ it('uses floor rounding', () => {
+ assert(millisecondsToHours(3600001) === 1)
+ assert(millisecondsToHours(3599999) === 0)
+ })
+
+ it('handles border values', () => {
+ assert(millisecondsToHours(3600000.5) === 1)
+ assert(millisecondsToHours(0) === 0)
+ })
+})