Skip to content

Commit

Permalink
Make toDate and isValid to accept any as the first argument
Browse files Browse the repository at this point in the history
  • Loading branch information
kossnocorp committed Sep 13, 2017
1 parent 88d8175 commit 1d25287
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -371,6 +371,9 @@ for the list of changes made since `v2.0.0-alpha.1`.
by all the functions, operations over `null` will also return an invalid date.
[See #537](https://github.com/date-fns/date-fns/issues/537) for the reasoning.

- `toDate` (previously `parse`) and `isValid` functions now accept `any` type
as the first argument.

## [1.28.5] - 2017-05-19

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/fp/isValid/index.js.flow
Expand Up @@ -63,4 +63,4 @@ type CurriedFn4<A, B, C, D, R> = <A>(a: A) => CurriedFn3<B, C, D, R>
| <A,B,C>(a: A, b: B, c: C) => CurriedFn1<D, R>
| <A,B,C,D>(a: A, b: B, c: C, d: D) => R

declare module.exports: CurriedFn1<Date | string | number, boolean>
declare module.exports: CurriedFn1<any, boolean>
2 changes: 1 addition & 1 deletion src/fp/isValidWithOptions/index.js.flow
Expand Up @@ -63,4 +63,4 @@ type CurriedFn4<A, B, C, D, R> = <A>(a: A) => CurriedFn3<B, C, D, R>
| <A,B,C>(a: A, b: B, c: C) => CurriedFn1<D, R>
| <A,B,C,D>(a: A, b: B, c: C, d: D) => R

declare module.exports: CurriedFn2<Options, Date | string | number, boolean>
declare module.exports: CurriedFn2<Options, any, boolean>
2 changes: 1 addition & 1 deletion src/fp/toDate/index.js.flow
Expand Up @@ -63,4 +63,4 @@ type CurriedFn4<A, B, C, D, R> = <A>(a: A) => CurriedFn3<B, C, D, R>
| <A,B,C>(a: A, b: B, c: C) => CurriedFn1<D, R>
| <A,B,C,D>(a: A, b: B, c: C, d: D) => R

declare module.exports: CurriedFn1<Date | string | number, Date>
declare module.exports: CurriedFn1<any, Date>
2 changes: 1 addition & 1 deletion src/fp/toDateWithOptions/index.js.flow
Expand Up @@ -63,4 +63,4 @@ type CurriedFn4<A, B, C, D, R> = <A>(a: A) => CurriedFn3<B, C, D, R>
| <A,B,C>(a: A, b: B, c: C) => CurriedFn1<D, R>
| <A,B,C,D>(a: A, b: B, c: C, d: D) => R

declare module.exports: CurriedFn2<Options, Date | string | number, Date>
declare module.exports: CurriedFn2<Options, any, Date>
2 changes: 1 addition & 1 deletion src/isValid/index.js
Expand Up @@ -12,7 +12,7 @@ import toDate from '../toDate/index.js'
*
* Time value of Date: http://es5.github.io/#x15.9.1.1
*
* @param {Date|String|Number} date - the date to check
* @param {*} date - the date to check
* @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 {Boolean} the date is valid
Expand Down
2 changes: 1 addition & 1 deletion src/isValid/index.js.flow
Expand Up @@ -50,6 +50,6 @@ type Locale = {
}

declare module.exports: (
date: Date | string | number,
date: any,
options?: Options
) => boolean
4 changes: 3 additions & 1 deletion src/toDate/index.js
Expand Up @@ -54,12 +54,14 @@ var patterns = {
* Function accepts complete ISO 8601 formats as well as partial implementations.
* ISO 8601: http://en.wikipedia.org/wiki/ISO_8601
*
* If the argument is null, it is treated as an invalid date.
*
* If all above fails, the function passes the given argument to Date constructor.
*
* **Note**: *all* Date arguments passed to any *date-fns* function is processed by `toDate`.
* All *date-fns* functions will throw `RangeError` if `options.additionalDigits` is not 0, 1, 2 or undefined.
*
* @param {Date|String|Number} argument - the value to convert
* @param {*} argument - the value to convert
* @param {Options} [options] - the object with options. See [Options]{@link https://date-fns.org/docs/Options}
* @param {0|1|2} [options.additionalDigits=2] - the additional number of digits in the extended year format
* @returns {Date} the parsed date in the local time zone
Expand Down
2 changes: 1 addition & 1 deletion src/toDate/index.js.flow
Expand Up @@ -50,6 +50,6 @@ type Locale = {
}

declare module.exports: (
argument: Date | string | number,
argument: any,
options?: Options
) => Date
28 changes: 14 additions & 14 deletions typings.d.ts
Expand Up @@ -650,7 +650,7 @@ declare module 'date-fns' {
namespace isTuesday {}

function isValid (
date: Date | string | number,
date: any,
options?: Options
): boolean
namespace isValid {}
Expand Down Expand Up @@ -952,7 +952,7 @@ declare module 'date-fns' {
namespace subYears {}

function toDate (
argument: Date | string | number,
argument: any,
options?: Options
): Date
namespace toDate {}
Expand Down Expand Up @@ -3493,10 +3493,10 @@ declare module 'date-fns/fp' {
const isTuesdayWithOptions: CurriedFn2<Options, Date | string | number, boolean>
namespace isTuesdayWithOptions {}

const isValid: CurriedFn1<Date | string | number, boolean>
const isValid: CurriedFn1<any, boolean>
namespace isValid {}

const isValidWithOptions: CurriedFn2<Options, Date | string | number, boolean>
const isValidWithOptions: CurriedFn2<Options, any, boolean>
namespace isValidWithOptions {}

const isWednesday: CurriedFn1<Date | string | number, boolean>
Expand Down Expand Up @@ -3769,10 +3769,10 @@ declare module 'date-fns/fp' {
const subYearsWithOptions: CurriedFn3<Options, number, Date | string | number, Date>
namespace subYearsWithOptions {}

const toDate: CurriedFn1<Date | string | number, Date>
const toDate: CurriedFn1<any, Date>
namespace toDate {}

const toDateWithOptions: CurriedFn2<Options, Date | string | number, Date>
const toDateWithOptions: CurriedFn2<Options, any, Date>
namespace toDateWithOptions {}
}

Expand Down Expand Up @@ -8372,7 +8372,7 @@ declare module 'date-fns/esm' {
namespace isTuesday {}

function isValid (
date: Date | string | number,
date: any,
options?: Options
): boolean
namespace isValid {}
Expand Down Expand Up @@ -8674,7 +8674,7 @@ declare module 'date-fns/esm' {
namespace subYears {}

function toDate (
argument: Date | string | number,
argument: any,
options?: Options
): Date
namespace toDate {}
Expand Down Expand Up @@ -11215,10 +11215,10 @@ declare module 'date-fns/esm/fp' {
const isTuesdayWithOptions: CurriedFn2<Options, Date | string | number, boolean>
namespace isTuesdayWithOptions {}

const isValid: CurriedFn1<Date | string | number, boolean>
const isValid: CurriedFn1<any, boolean>
namespace isValid {}

const isValidWithOptions: CurriedFn2<Options, Date | string | number, boolean>
const isValidWithOptions: CurriedFn2<Options, any, boolean>
namespace isValidWithOptions {}

const isWednesday: CurriedFn1<Date | string | number, boolean>
Expand Down Expand Up @@ -11491,10 +11491,10 @@ declare module 'date-fns/esm/fp' {
const subYearsWithOptions: CurriedFn3<Options, number, Date | string | number, Date>
namespace subYearsWithOptions {}

const toDate: CurriedFn1<Date | string | number, Date>
const toDate: CurriedFn1<any, Date>
namespace toDate {}

const toDateWithOptions: CurriedFn2<Options, Date | string | number, Date>
const toDateWithOptions: CurriedFn2<Options, any, Date>
namespace toDateWithOptions {}
}

Expand Down Expand Up @@ -17239,7 +17239,7 @@ interface dateFns {
): boolean

isValid(
date: Date | string | number,
date: any,
options?: Options
): boolean

Expand Down Expand Up @@ -17495,7 +17495,7 @@ interface dateFns {
): Date

toDate(
argument: Date | string | number,
argument: any,
options?: Options
): Date
}

0 comments on commit 1d25287

Please sign in to comment.