File tree Expand file tree Collapse file tree 2 files changed +120
-2
lines changed Expand file tree Collapse file tree 2 files changed +120
-2
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ function isValidFormat(format) {
12
12
13
13
function zip ( date , format ) {
14
14
const zippedArr = [ ] ,
15
- len = Math . min ( date . length , format . length ) ;
15
+ len = Math . max ( date . length , format . length ) ;
16
16
17
17
for ( let i = 0 ; i < len ; i ++ ) {
18
18
zippedArr . push ( [ date [ i ] , format [ i ] ] ) ;
@@ -40,7 +40,7 @@ export default function isDate(input, options) {
40
40
const dateObj = { } ;
41
41
42
42
for ( const [ dateWord , formatWord ] of dateAndFormat ) {
43
- if ( dateWord . length !== formatWord . length ) {
43
+ if ( ! dateWord || ! formatWord || dateWord . length !== formatWord . length ) {
44
44
return false ;
45
45
}
46
46
Original file line number Diff line number Diff line change @@ -13680,6 +13680,7 @@ describe('Validators', () => {
13680
13680
new Date ( [ 2014 , 2 , 15 ] ) ,
13681
13681
new Date ( '2014-03-15' ) ,
13682
13682
'2020/02/29' ,
13683
+ '2020-02-19' ,
13683
13684
] ,
13684
13685
invalid : [
13685
13686
'' ,
@@ -13695,6 +13696,18 @@ describe('Validators', () => {
13695
13696
'2020/03-15' , // mixed delimiter
13696
13697
'-2020-04-19' ,
13697
13698
'-2023/05/24' ,
13699
+ 'abc-2023/05/24' ,
13700
+ '2024' ,
13701
+ '2024-' ,
13702
+ '2024-05' ,
13703
+ '2024-05-' ,
13704
+ '2024-05-01-' ,
13705
+ '2024-05-01-abc' ,
13706
+ '2024/' ,
13707
+ '2024/05' ,
13708
+ '2024/05/' ,
13709
+ '2024/05/01/' ,
13710
+ '2024/05/01/abc' ,
13698
13711
] ,
13699
13712
} ) ;
13700
13713
test ( {
@@ -13710,6 +13723,21 @@ describe('Validators', () => {
13710
13723
'15/7/02' ,
13711
13724
'15-7-02' ,
13712
13725
'15-07/2002' ,
13726
+ '2024' ,
13727
+ '2024-' ,
13728
+ '2024-05' ,
13729
+ '2024-05-' ,
13730
+ '2024-05-01-' ,
13731
+ '2024-05-01-abc' ,
13732
+ '2024/' ,
13733
+ '2024/05' ,
13734
+ '2024/05/' ,
13735
+ '2024/05/01/' ,
13736
+ '2024/05/01/abc' ,
13737
+ '15/' ,
13738
+ '15/07' ,
13739
+ '15/07/' ,
13740
+ '15/07/2024/' ,
13713
13741
] ,
13714
13742
} ) ;
13715
13743
test ( {
@@ -13725,6 +13753,21 @@ describe('Validators', () => {
13725
13753
'15/7/02' ,
13726
13754
'15-7-02' ,
13727
13755
'15-07/2002' ,
13756
+ '2024' ,
13757
+ '2024-' ,
13758
+ '2024-05' ,
13759
+ '2024-05-' ,
13760
+ '2024-05-01-' ,
13761
+ '2024-05-01-abc' ,
13762
+ '2024/' ,
13763
+ '2024/05' ,
13764
+ '2024/05/' ,
13765
+ '2024/05/01/' ,
13766
+ '2024/05/01/abc' ,
13767
+ '15/' ,
13768
+ '15/07' ,
13769
+ '15/07/' ,
13770
+ '15/07/2024/' ,
13728
13771
] ,
13729
13772
} ) ;
13730
13773
test ( {
@@ -13739,6 +13782,22 @@ describe('Validators', () => {
13739
13782
'15-7-2002' ,
13740
13783
'15/07-02' ,
13741
13784
'30/04/--' ,
13785
+ '2024' ,
13786
+ '2024-' ,
13787
+ '2024-05' ,
13788
+ '2024-05-' ,
13789
+ '2024-05-01-' ,
13790
+ '2024-05-01-abc' ,
13791
+ '2024/' ,
13792
+ '2024/05' ,
13793
+ '2024/05/' ,
13794
+ '2024/05/01/' ,
13795
+ '2024/05/01/abc' ,
13796
+ '15/' ,
13797
+ '15/07' ,
13798
+ '15/07/' ,
13799
+ '15/07/2024/' ,
13800
+ '15/07/24/' ,
13742
13801
] ,
13743
13802
} ) ;
13744
13803
test ( {
@@ -13754,6 +13813,16 @@ describe('Validators', () => {
13754
13813
'15-7-02' ,
13755
13814
'5/7-02' ,
13756
13815
'3/4/aa' ,
13816
+ '2024/' ,
13817
+ '2024/05' ,
13818
+ '2024/05/' ,
13819
+ '2024/05/01/' ,
13820
+ '2024/05/01/abc' ,
13821
+ '15/' ,
13822
+ '15/07' ,
13823
+ '15/07/' ,
13824
+ '15/07/2024/' ,
13825
+ '15/07/24/' ,
13757
13826
] ,
13758
13827
} ) ;
13759
13828
test ( {
@@ -13769,6 +13838,16 @@ describe('Validators', () => {
13769
13838
'15/7/02' ,
13770
13839
'15-7-02' ,
13771
13840
'15-07/2002' ,
13841
+ '2024/' ,
13842
+ '2024/05' ,
13843
+ '2024/05/' ,
13844
+ '2024/05/01/' ,
13845
+ '2024/05/01/abc' ,
13846
+ '15/' ,
13847
+ '15/07' ,
13848
+ '15/07/' ,
13849
+ '15/07/2024/' ,
13850
+ '15/07/24/' ,
13772
13851
] ,
13773
13852
} ) ;
13774
13853
test ( {
@@ -13787,6 +13866,20 @@ describe('Validators', () => {
13787
13866
new Date ( ) ,
13788
13867
new Date ( [ 2014 , 2 , 15 ] ) ,
13789
13868
new Date ( '2014-03-15' ) ,
13869
+ '-2020-04-19' ,
13870
+ '-2023/05/24' ,
13871
+ 'abc-2023/05/24' ,
13872
+ '2024' ,
13873
+ '2024-' ,
13874
+ '2024-05' ,
13875
+ '2024-05-' ,
13876
+ '2024-05-01-' ,
13877
+ '2024-05-01-abc' ,
13878
+ '2024/' ,
13879
+ '2024/05' ,
13880
+ '2024/05/' ,
13881
+ '2024/05/01/' ,
13882
+ '2024/05/01/abc' ,
13790
13883
] ,
13791
13884
} ) ;
13792
13885
test ( {
@@ -13812,6 +13905,21 @@ describe('Validators', () => {
13812
13905
'2019/02/29' ,
13813
13906
'2020/04/31' ,
13814
13907
'2020/03-15' ,
13908
+ '-2020-04-19' ,
13909
+ '-2023/05/24' ,
13910
+ 'abc-2023/05/24' ,
13911
+ '2024' ,
13912
+ '2024-' ,
13913
+ '2024-05' ,
13914
+ '2024-05-' ,
13915
+ '2024-05-01-' ,
13916
+ '2024-05-01-abc' ,
13917
+ '2024/' ,
13918
+ '2024/05' ,
13919
+ '2024/05/' ,
13920
+ '2024/05/01/' ,
13921
+ '2024/05/01/abc' ,
13922
+ '2024 05 01 abc' ,
13815
13923
] ,
13816
13924
} ) ;
13817
13925
test ( {
@@ -13831,6 +13939,16 @@ describe('Validators', () => {
13831
13939
new Date ( [ 2014 , 2 , 15 ] ) ,
13832
13940
new Date ( '2014-03-15' ) ,
13833
13941
'29.02.2020' ,
13942
+ '2024-' ,
13943
+ '2024-05' ,
13944
+ '2024-05-' ,
13945
+ '2024-05-01' ,
13946
+ '-2020-04-19' ,
13947
+ '-2023/05/24' ,
13948
+ 'abc-2023/05/24' ,
13949
+ '04.05.2024.' ,
13950
+ '04.05.2024.abc' ,
13951
+ 'abc.04.05.2024' ,
13834
13952
] ,
13835
13953
} ) ;
13836
13954
// emulating Pacific time zone offset & time
You can’t perform that action at this time.
0 commit comments