summaryrefslogtreecommitdiff
path: root/date-fns/src/getSeconds
diff options
context:
space:
mode:
Diffstat (limited to 'date-fns/src/getSeconds')
-rw-r--r--date-fns/src/getSeconds/benchmark.js21
-rw-r--r--date-fns/src/getSeconds/index.d.ts4
-rw-r--r--date-fns/src/getSeconds/index.js.flow52
-rw-r--r--date-fns/src/getSeconds/index.ts31
-rw-r--r--date-fns/src/getSeconds/test.ts28
5 files changed, 136 insertions, 0 deletions
diff --git a/date-fns/src/getSeconds/benchmark.js b/date-fns/src/getSeconds/benchmark.js
new file mode 100644
index 0000000..239fbe7
--- /dev/null
+++ b/date-fns/src/getSeconds/benchmark.js
@@ -0,0 +1,21 @@
+// @flow
+/* eslint-env mocha */
+/* global suite, benchmark */
+
+import getSeconds from '.'
+import moment from 'moment'
+
+suite('getSeconds', function () {
+ benchmark('date-fns', function () {
+ return getSeconds(this.date)
+ })
+
+ benchmark('Moment.js', function () {
+ return this.moment.seconds()
+ })
+}, {
+ setup: function () {
+ this.date = new Date()
+ this.moment = moment()
+ }
+})
diff --git a/date-fns/src/getSeconds/index.d.ts b/date-fns/src/getSeconds/index.d.ts
new file mode 100644
index 0000000..7b60944
--- /dev/null
+++ b/date-fns/src/getSeconds/index.d.ts
@@ -0,0 +1,4 @@
+// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
+
+import { getSeconds } from 'date-fns'
+export default getSeconds
diff --git a/date-fns/src/getSeconds/index.js.flow b/date-fns/src/getSeconds/index.js.flow
new file mode 100644
index 0000000..07bb012
--- /dev/null
+++ b/date-fns/src/getSeconds/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: (date: Date | number) => number
diff --git a/date-fns/src/getSeconds/index.ts b/date-fns/src/getSeconds/index.ts
new file mode 100644
index 0000000..58ba042
--- /dev/null
+++ b/date-fns/src/getSeconds/index.ts
@@ -0,0 +1,31 @@
+import toDate from '../toDate/index'
+import requiredArgs from '../_lib/requiredArgs/index'
+
+/**
+ * @name getSeconds
+ * @category Second Helpers
+ * @summary Get the seconds of the given date.
+ *
+ * @description
+ * Get the seconds of the given date.
+ *
+ * ### v2.0.0 breaking changes:
+ *
+ * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
+ *
+ * @param {Date|Number} date - the given date
+ * @returns {Number} the seconds
+ * @throws {TypeError} 1 argument required
+ *
+ * @example
+ * // Get the seconds of 29 February 2012 11:45:05.123:
+ * const result = getSeconds(new Date(2012, 1, 29, 11, 45, 5, 123))
+ * //=> 5
+ */
+export default function getSeconds(dirtyDate: Date | number): number {
+ requiredArgs(1, arguments)
+
+ const date = toDate(dirtyDate)
+ const seconds = date.getSeconds()
+ return seconds
+}
diff --git a/date-fns/src/getSeconds/test.ts b/date-fns/src/getSeconds/test.ts
new file mode 100644
index 0000000..bcc1c38
--- /dev/null
+++ b/date-fns/src/getSeconds/test.ts
@@ -0,0 +1,28 @@
+// @flow
+/* eslint-env mocha */
+
+import assert from 'power-assert'
+import getSeconds from '.'
+
+describe('getSeconds', function() {
+ it('returns the seconds of the given date', function() {
+ const result = getSeconds(new Date(2012, 1 /* Feb */, 29, 11, 45, 5, 123))
+ assert(result === 5)
+ })
+
+ it('accepts a timestamp', function() {
+ const result = getSeconds(
+ new Date(2014, 3 /* Apr */, 2, 23, 30, 42).getTime()
+ )
+ assert(result === 42)
+ })
+
+ it('returns NaN if the given date is invalid', function() {
+ const result = getSeconds(new Date(NaN))
+ assert(isNaN(result))
+ })
+
+ it('throws TypeError exception if passed less than 1 argument', function() {
+ assert.throws(getSeconds.bind(null), TypeError)
+ })
+})