Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebccdd5
commit e48cdfb
Showing
18 changed files
with
408 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
import {getUnixTime} from 'date-fns/fp' | ||
export = getUnixTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. | ||
|
||
import fn from '../../getUnixTime/index.js' | ||
import convertToFP from '../_lib/convertToFP/index.js' | ||
|
||
var getUnixTime = convertToFP(fn, 1) | ||
|
||
export default getUnixTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// @flow | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
type Interval = { | ||
start: Date | string | number, | ||
end: Date | string | number | ||
} | ||
|
||
type Options = { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7, | ||
additionalDigits?: 0 | 1 | 2, | ||
locale?: Locale, | ||
includeSeconds?: boolean, | ||
addSuffix?: boolean, | ||
unit?: 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year', | ||
roundingMethod?: 'floor' | 'ceil' | 'round' | ||
} | ||
|
||
type Locale = { | ||
formatDistance: Function, | ||
formatRelative: Function, | ||
localize: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
formatLong: Object, | ||
date: Function, | ||
time: Function, | ||
dateTime: Function, | ||
match: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
options?: { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | ||
} | ||
} | ||
|
||
type CurriedFn1<A, R> = <A>(a: A) => R | ||
|
||
declare module.exports: CurriedFn1<Date | string | number, number> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
import {getUnixTimeWithOptions} from 'date-fns/fp' | ||
export = getUnixTimeWithOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This file is generated automatically by `scripts/build/fp.js`. Please, don't change it. | ||
|
||
import fn from '../../getUnixTime/index.js' | ||
import convertToFP from '../_lib/convertToFP/index.js' | ||
|
||
var getUnixTimeWithOptions = convertToFP(fn, 2) | ||
|
||
export default getUnixTimeWithOptions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// @flow | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
type Interval = { | ||
start: Date | string | number, | ||
end: Date | string | number | ||
} | ||
|
||
type Options = { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7, | ||
additionalDigits?: 0 | 1 | 2, | ||
locale?: Locale, | ||
includeSeconds?: boolean, | ||
addSuffix?: boolean, | ||
unit?: 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year', | ||
roundingMethod?: 'floor' | 'ceil' | 'round' | ||
} | ||
|
||
type Locale = { | ||
formatDistance: Function, | ||
formatRelative: Function, | ||
localize: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
formatLong: Object, | ||
date: Function, | ||
time: Function, | ||
dateTime: Function, | ||
match: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
options?: { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | ||
} | ||
} | ||
|
||
type CurriedFn1<A, R> = <A>(a: A) => R | ||
|
||
type CurriedFn2<A, B, R> = <A>(a: A) => CurriedFn1<B, R> | ||
| <A, B>(a: A, b: B) => R | ||
|
||
declare module.exports: CurriedFn2<Options, Date | string | number, number> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// @flow | ||
/* eslint-env mocha */ | ||
/* global suite, benchmark */ | ||
|
||
import getUnixTime from '.' | ||
import moment from 'moment' | ||
|
||
suite('getTime', function () { | ||
benchmark('date-fns', function () { | ||
return getUnixTime(this.date) | ||
}) | ||
|
||
benchmark('Moment.js', function () { | ||
return this.moment.unix() | ||
}) | ||
}, { | ||
setup: function () { | ||
this.date = new Date() | ||
this.moment = moment() | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
import {getUnixTime} from 'date-fns' | ||
export = getUnixTime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import getTime from '../getTime/index.js' | ||
|
||
/** | ||
* @name getUnixTime | ||
* @category Timestamp Helpers | ||
* @summary Get the seconds timestamp of the given date. | ||
* | ||
* @description | ||
* Get the seconds timestamp of the given date. | ||
* | ||
* @param {Date|String|Number} date - the given date | ||
* @param {Options} [options] - the object with options. See [Options]{@link https://date-fns.org/docs/Options} | ||
* @param {0|1|2} [options.additionalDigits=2] - passed to `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate} | ||
* @returns {Number} the timestamp | ||
* @throws {TypeError} 1 argument required | ||
* @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2 | ||
* | ||
* @example | ||
* // Get the timestamp of 29 February 2012 11:45:05: | ||
* var result = getTime(new Date(2012, 1, 29, 11, 45, 5)) | ||
* //=> 1330515905 | ||
*/ | ||
export default function getUnixTime (dirtyDate, dirtyOptions) { | ||
if (arguments.length < 1) { | ||
throw new TypeError('1 argument required, but only ' + arguments.length + ' present') | ||
} | ||
|
||
return Math.floor(getTime(dirtyDate, dirtyOptions) / 1000) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// @flow | ||
// This file is generated automatically by `scripts/build/typings.js`. Please, don't change it. | ||
|
||
type Interval = { | ||
start: Date | string | number, | ||
end: Date | string | number | ||
} | ||
|
||
type Options = { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7, | ||
additionalDigits?: 0 | 1 | 2, | ||
locale?: Locale, | ||
includeSeconds?: boolean, | ||
addSuffix?: boolean, | ||
unit?: 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year', | ||
roundingMethod?: 'floor' | 'ceil' | 'round' | ||
} | ||
|
||
type Locale = { | ||
formatDistance: Function, | ||
formatRelative: Function, | ||
localize: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
formatLong: Object, | ||
date: Function, | ||
time: Function, | ||
dateTime: Function, | ||
match: { | ||
ordinalNumber: Function, | ||
era: Function, | ||
quarter: Function, | ||
month: Function, | ||
day: Function, | ||
dayPeriod: Function | ||
}, | ||
options?: { | ||
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6, | ||
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | ||
} | ||
} | ||
|
||
declare module.exports: ( | ||
date: Date | string | number, | ||
options?: Options | ||
) => number |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// @flow | ||
/* eslint-env mocha */ | ||
|
||
import assert from 'power-assert' | ||
import getUnixTime from '.' | ||
|
||
describe('getUnixTime', function () { | ||
it('returns the timestamp of the given date', function () { | ||
var timestamp = 1483228800000 | ||
var result = getUnixTime(new Date(timestamp)) | ||
assert(result === Math.floor(timestamp / 1000)) | ||
}) | ||
|
||
it('accepts a string', function () { | ||
var timestamp = 1484503736150 | ||
var result = getUnixTime(new Date(timestamp).toISOString()) | ||
assert(result === Math.floor(timestamp / 1000)) | ||
}) | ||
|
||
it('accepts a timestamp (and returns it unchanged)', function () { | ||
var timestamp = 804643200000 | ||
var result = getUnixTime(timestamp) | ||
assert(result === Math.floor(timestamp / 1000)) | ||
}) | ||
|
||
it('returns NaN if the given date is invalid', function () { | ||
var result = getUnixTime(new Date(NaN)) | ||
assert(isNaN(result)) | ||
}) | ||
|
||
it('throws `RangeError` if `options.additionalDigits` is not convertable to 0, 1, 2 or undefined', function () { | ||
var timestamp = 1483228800000 | ||
// $ExpectedMistake | ||
var block = getUnixTime.bind(null, new Date(timestamp), {additionalDigits: NaN}) | ||
assert.throws(block, RangeError) | ||
}) | ||
|
||
it('throws TypeError exception if passed less than 1 argument', function () { | ||
assert.throws(getUnixTime.bind(null), TypeError) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.