File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -93,9 +93,7 @@ describe("parseDate", () => {
9393 new Date ( "2000-02-21T00:00:00.000Z" )
9494 ) ;
9595 } ) ;
96-
97- // TODO!!!! time still not working with asUTC: true
98- test . skip ( "time" , async ( ) => {
96+ test ( "time" , async ( ) => {
9997 expect ( parseDate ( "2000-02-02T40:00:00" ) ) . toBeUndefined ( ) ;
10098
10199 expect ( parseDate ( "2000-02-21T01" , { asUTC : true } ) ) . toStrictEqual (
@@ -106,8 +104,8 @@ describe("parseDate", () => {
106104 new Date ( "2000-02-21T00:01:00.000Z" )
107105 ) ;
108106
109- expect ( parseDate ( "2000-02-21T00:00:00 " , { asUTC : true } ) ) . toStrictEqual (
110- new Date ( "2000-02-21T00:00:00 .000Z" )
107+ expect ( parseDate ( "2000-02-21T00:00:01 " , { asUTC : true } ) ) . toStrictEqual (
108+ new Date ( "2000-02-21T00:00:01 .000Z" )
111109 ) ;
112110 } ) ;
113111 } ) ;
Original file line number Diff line number Diff line change @@ -32,13 +32,21 @@ export const parseDate = (
3232 if ( ! Number . isFinite ( arg ) ) return ;
3333 }
3434
35- if ( isString ( arg ) && partialDateRegex . test ( arg ) ) {
36- // Add time to date string because it will be interpreted
37- // as UTC date instead of local time, and there is no
38- // circumstance where UTC as default is desired.
39- arg = `${
40- arg + "-01-01" . slice ( arg . length - 4 ) // fill missing month and day if needed
41- } T00:00:00`;
35+ if ( isString ( arg ) ) {
36+ if ( partialDateRegex . test ( arg ) ) {
37+ // Add time to date string because it will be interpreted
38+ // as UTC date instead of local time, and there is no
39+ // circumstance where UTC as default is desired.
40+ arg = `${
41+ arg + "-01-01" . slice ( arg . length - 4 ) // fill missing month and day if needed
42+ } T00:00:00`;
43+ }
44+
45+ const [ date , time ] = arg . split ( "T" ) ;
46+ // 8 as in "HH:MM:SS"
47+ if ( time . length < 8 ) {
48+ arg = `${ date } T${ time } ${ "00:00:00" . slice ( time . length ) } ` ;
49+ }
4250
4351 if ( options ?. asUTC ) {
4452 arg += "Z" ; // In this case, force UTC
Original file line number Diff line number Diff line change @@ -26,10 +26,10 @@ describe("isPastDate", () => {
2626 } ) ;
2727
2828 it ( "should return false when date is after or equal to referenceDate" , ( ) => {
29- const referenceDate = new Date ( "2023-01-01 " ) ;
30- expect ( isPastDate ( "2023-06-01 " , { referenceDate } ) ) . toBe ( false ) ;
31- expect ( isPastDate ( "2024-01-01 " , { referenceDate } ) ) . toBe ( false ) ;
32- expect ( isPastDate ( "2023-01-01 " , { referenceDate } ) ) . toBe ( false ) ; // same date
29+ const referenceDate = new Date ( "2023-01-01T00:00:00Z " ) ;
30+ expect ( isPastDate ( "2023-06-01T00:00:00Z " , { referenceDate } ) ) . toBe ( false ) ;
31+ expect ( isPastDate ( "2024-01-01T00:00:00Z " , { referenceDate } ) ) . toBe ( false ) ;
32+ expect ( isPastDate ( "2023-01-01T00:00:00Z " , { referenceDate } ) ) . toBe ( false ) ; // same date
3333 } ) ;
3434
3535 it ( "should work with different date formats as referenceDate" , ( ) => {
You can’t perform that action at this time.
0 commit comments