Skip to content

Commit

Permalink
[bugfix] More complete type definitions for strict formatless parsing #…
Browse files Browse the repository at this point in the history
…4611 (#5574)

* Reflect changes from #4611 in ts3.1-typings

* Add types for `moment.utc(..., true)`
  • Loading branch information
thorn0 committed Sep 15, 2020
1 parent a3824e3 commit a364b34
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
19 changes: 17 additions & 2 deletions moment.d.ts
Expand Up @@ -4,13 +4,13 @@
*/
declare function moment(inp?: moment.MomentInput, strict?: boolean): moment.Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimeters.
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, strict?: boolean): moment.Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimeters.
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
Expand Down Expand Up @@ -663,7 +663,22 @@ declare namespace moment {
export var fn: Moment;

// NOTE(constructor): Same as moment constructor
/**
* @param strict Strict parsing disables the deprecated fallback to the native Date constructor when
* parsing a string.
*/
export function utc(inp?: MomentInput, strict?: boolean): Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
export function utc(inp?: MomentInput, format?: MomentFormatSpecification, strict?: boolean): Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
export function utc(inp?: MomentInput, format?: MomentFormatSpecification, language?: string, strict?: boolean): Moment;

export function unix(timestamp: number): Moment;
Expand Down
2 changes: 2 additions & 0 deletions ts3.1-typing-tests/moment-tests.ts
Expand Up @@ -23,6 +23,8 @@ var day10 = moment([2010, 6, 10]);
var array = [2010, 1, 14, 15, 25, 50, 125];
var day11 = moment(Date.UTC.apply({}, array));
var day12 = moment.unix(1318781876);
var day13 = moment("/Date(1198908717056-0700)/", true);
var day14 = moment("foobazbar", 'L', true);

moment(null);
moment(undefined);
Expand Down
30 changes: 30 additions & 0 deletions ts3.1-typings/moment.d.ts
@@ -1,4 +1,19 @@
/**
* @param strict Strict parsing disables the deprecated fallback to the native Date constructor when
* parsing a string.
*/
declare function moment(inp?: moment.MomentInput, strict?: boolean): moment.Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, strict?: boolean): moment.Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
declare function moment(inp?: moment.MomentInput, format?: moment.MomentFormatSpecification, language?: string, strict?: boolean): moment.Moment;

declare namespace moment {
Expand Down Expand Up @@ -636,7 +651,22 @@ declare namespace moment {
export var fn: Moment;

// NOTE(constructor): Same as moment constructor
/**
* @param strict Strict parsing disables the deprecated fallback to the native Date constructor when
* parsing a string.
*/
export function utc(inp?: MomentInput, strict?: boolean): Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
export function utc(inp?: MomentInput, format?: MomentFormatSpecification, strict?: boolean): Moment;
/**
* @param strict Strict parsing requires that the format and input match exactly, including delimiters.
* Strict parsing is frequently the best parsing option. For more information about choosing strict vs
* forgiving parsing, see the [parsing guide](https://momentjs.com/guides/#/parsing/).
*/
export function utc(inp?: MomentInput, format?: MomentFormatSpecification, language?: string, strict?: boolean): Moment;

export function unix(timestamp: number): Moment;
Expand Down

0 comments on commit a364b34

Please sign in to comment.