forked from date-fns/date-fns
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add constants: `minTime`, `maxTime`. * Integrate constants into build system & docs.
- Loading branch information
Showing
27 changed files
with
289 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Constants | ||
|
||
date-fns provides with a number of useful constants. | ||
|
||
## Usage | ||
|
||
The constants could be imported from `date-fns/constants` or directly | ||
from `date-fns`: | ||
|
||
```js | ||
import { maxTime } from 'date-fns/constants' | ||
import { minTime } from 'date-fns' | ||
|
||
function isAllowedTime(time) { | ||
return time <= maxTime && time >= minTime | ||
} | ||
``` | ||
|
||
## Constants | ||
|
||
### `maxTime` | ||
|
||
Maximum allowed time: | ||
|
||
```js | ||
import { maxTime } from 'date-fns' | ||
|
||
const isValid = 8640000000000001 <= maxTime | ||
//=> false | ||
|
||
new Date(8640000000000001) | ||
//=> Invalid Date | ||
``` | ||
|
||
### `minTime` | ||
|
||
Minimum allowed time: | ||
|
||
```js | ||
import { minTime } from 'date-fns' | ||
|
||
const isValid = -8640000000000001 >= minTime | ||
//=> false | ||
|
||
new Date(-8640000000000001) | ||
//=> Invalid Date | ||
``` |
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,11 @@ | ||
// @flow | ||
|
||
const dateFns = require('date-fns') | ||
const constants = require('date-fns/constants') | ||
const { minTime: fpMinTime } = require('date-fns/fp') | ||
|
||
console.log( | ||
dateFns.maxTime === 8640000000000000 && | ||
dateFns.minTime === constants.minTime && | ||
constants.minTime === fpMinTime | ||
) |
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,9 @@ | ||
import { maxTime as rootMaxTime, minTime as rootMinTime } from 'date-fns' | ||
import { minTime } from 'date-fns/constants' | ||
import { minTime as fpMinTime } from 'date-fns/fp' | ||
|
||
console.log( | ||
rootMaxTime === 8640000000000000 && | ||
rootMinTime === minTime && | ||
minTime === fpMinTime | ||
) |
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,9 @@ | ||
const dateFns = require('date-fns') | ||
const constants = require('date-fns/constants') | ||
const { minTime: fpMinTime } = require('date-fns/fp') | ||
|
||
console.log( | ||
dateFns.maxTime === 8640000000000000 && | ||
dateFns.minTime === constants.minTime && | ||
constants.minTime === fpMinTime | ||
) |
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,9 @@ | ||
import { maxTime as rootMaxTime, minTime as rootMinTime } from 'date-fns' | ||
import { minTime } from 'date-fns/constants' | ||
import { minTime as fpMinTime } from 'date-fns/fp' | ||
|
||
console.log( | ||
rootMaxTime === 8640000000000000 && | ||
rootMinTime === minTime && | ||
minTime === fpMinTime | ||
) |
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,13 @@ | ||
const path = require('path') | ||
const jsDocParser = require('jsdoc-to-markdown') | ||
|
||
module.exports = getConstants | ||
|
||
function getConstants() { | ||
return jsDocParser | ||
.getJsdocDataSync({ | ||
files: path.resolve(process.cwd(), 'src/constants/index.js'), | ||
'no-cache': true | ||
}) | ||
.filter(c => c.kind === 'constant' && !c.undocumented) | ||
} |
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ const ignoredFiles = [ | |
'locale', | ||
'esm', | ||
'fp', | ||
'constants', | ||
'index.js', | ||
'test.js', | ||
'index.js.flow', | ||
|
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.