Methods
(static) setDateArr(value) → {Array.<Object>|null}
Creates an array expressing a date ([ year, month, day ]).
Parameters:
Name | Type | Description |
---|---|---|
value |
Object | Array.<Object> | string | Date | A date value |
- Source:
Returns:
An array ([ year, month, day ]) or null in case of invalid param
- Type
- Array.<Object> | null
Example
setDateArr( { year: 2021, month: 1, day: 31 } ); // returns [ 2021, 1, 31 ]
setDateArr( [ 2021, 1, 31 ] ); // returns [ 2021, 1, 31 ]
setDateArr( '20210131' ); // returns [ 2021, 1, 31 ]
setDateArr( '31/01/2021' ); // returns [ 2021, 1, 31 ]
setDateArr( new Date( 2021, 0, 31 ) ); // returns [ 2021, 1, 31 ]
setDateArr(); // returns null
- - -
(static) setDateDate(value) → {Date|null}
Creates a Date instance.
Parameters:
Name | Type | Description |
---|---|---|
value |
Object | Array.<Object> | string | Date | A date value |
- Source:
Returns:
An instance of Date() or null in case of invalid param
- Type
- Date | null
Example
setDateDate( { year: 2021, month: 1, day: 31 } ); // returns new Date( 2021, 0, 31 )
setDateDate( [ 2021, 1, 31 ] ); // returns new Date( 2021, 0, 31 )
setDateDate( '20210131' ); // returns new Date( 2021, 0, 31 )
setDateDate( '31/01/2021' ); // returns new Date( 2021, 0, 31 )
setDateDate( new Date( 2021, 0, 31 ) ); // returns new Date( 2021, 0, 31 )
setDateDate(); // returns null
- - -
(static) setDateObj(value) → {Object|null}
Creates an object expressing a date ({ year:, month:, day: }).
Parameters:
Name | Type | Description |
---|---|---|
value |
Object | Array.<Object> | string | Date | A date value |
- Source:
Returns:
An object ({ year:, month:, day: }) or null in case of invalid param
- Type
- Object | null
Example
setDateObj( { year: 2021, month: 1, day: 31 } ); // returns { year: 2021, month: 1, day: 31 }
setDateObj( [ 2021, 1, 31 ] ); // returns { year: 2021, month: 1, day: 31 }
setDateObj( '20210131' ); // returns { year: 2021, month: 1, day: 31 }
setDateObj( '31/01/2021' ); // returns { year: 2021, month: 1, day: 31 }
setDateObj( new Date( 2021, 0, 31 ) ); // returns { year: 2021, month: 1, day: 31 }
setDateObj(); // returns null
- - -
(static) setDateRepr(value, patternopt) → {string|null}
Creates a string expressing a date (in representation format).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
Object | Array.<Object> | string | Date | A date value | |
pattern |
string |
<optional> |
A representation pattern |
- Source:
Returns:
A string in representation format or null in case of invalid params
- Type
- string | null
Example
setDateRepr( { year: 2021, month: 1, day: 31 } ); // returns '31/12/2021'
setDateRepr( [ 2021, 1, 31 ] ); // returns '31/12/2021'
setDateRepr( '20210131' ); // returns '31/12/2021'
setDateRepr( '31/01/2021' ); // returns '31/12/2021'
setDateRepr( new Date( 2021, 0, 31 ) ); // returns '31/12/2021'
setDateRepr(); // returns null
- - -
(static) setDateStr(value) → {string|null}
Creates a string expressing a date (in YYYYMMDD format).
Parameters:
Name | Type | Description |
---|---|---|
value |
Object | Array.<Object> | string | Date | A date value |
- Source:
Returns:
A string in YYYYMMDD format or null in case of invalid param
- Type
- string | null
Example
setDateStr( { year: 2021, month: 1, day: 31 } ); // returns '20210131'
setDateStr( [ 2021, 1, 31 ] ); // returns '20210131'
setDateStr( '20210131' ); // returns '20210131'
setDateStr( '31/01/2021' ); // returns '20210131'
setDateStr( new Date( 2021, 0, 31 ) ); // returns '20210131'
setDateStr(); // returns null
- - -