diff --git a/src/datetime/CtoT.ts b/src/datetime/CtoT.ts index 2648db0..893b57b 100644 --- a/src/datetime/CtoT.ts +++ b/src/datetime/CtoT.ts @@ -78,7 +78,9 @@ export const fromString = ( if (dateFrom.toUpperCase().indexOf("PM") !== -1) { if (hour < 12) { hour = hour + 12; - } else { + } + } else { + if (hour === 12) { hour = 0; } } diff --git a/src/datetime/test/CtoT.spec.ts b/src/datetime/test/CtoT.spec.ts index edc08bf..f8d4685 100644 --- a/src/datetime/test/CtoT.spec.ts +++ b/src/datetime/test/CtoT.spec.ts @@ -15,6 +15,8 @@ export const testCases1: Array<[string, Date]> = [ ["12/17/2019 11:15:37 PM", new Date(2019, 11, 17, 23, 15, 37)], ["12/17/2019 11:15:37.000 AM", new Date(2019, 11, 17, 11, 15, 37, 0)], ["12/17/2019 11:15:37.000 PM", new Date(2019, 11, 17, 23, 15, 37, 0)], + ["03/23/2023 12:09:43.000 PM", new Date(2023, 2, 23, 12, 9, 43, 0)], + ["03/23/2023 12:09:43.000 AM", new Date(2023, 2, 23, 0, 9, 43, 0)], ["12172019 11:15 AM", EMPTY_DATE_VALUE], ["2172019 11:15 AM", EMPTY_DATE_VALUE], ["12172019 11:15:37 AM", EMPTY_DATE_VALUE], @@ -59,6 +61,8 @@ export const testCases3: Array<[string, Date]> = [ ["17/12/2019 11:15:37 PM", new Date(2019, 11, 17, 23, 15, 37)], ["17/12/2019 11:15:37.000 AM", new Date(2019, 11, 17, 11, 15, 37, 0)], ["17/12/2019 11:15:37.000 PM", new Date(2019, 11, 17, 23, 15, 37, 0)], + ["30/03/2023 12:09:43.000 PM", new Date(2023, 2, 30, 12, 9, 43, 0)], + ["30/03/2023 12:09:43.000 AM", new Date(2023, 2, 30, 0, 9, 43, 0)], ["17122019 11:15 AM", EMPTY_DATE_VALUE], ["1722019 11:15 AM", EMPTY_DATE_VALUE], ["17122019 11:15:37 AM", EMPTY_DATE_VALUE], @@ -101,9 +105,11 @@ export const testCases5: Array<[string, Date]> = [ ["2019/2/17 11:15 PM", new Date(2019, 1, 17, 23, 15)], ["2019/12/17 11:15:37 AM", new Date(2019, 11, 17, 11, 15, 37)], ["2019/12/17 11:15:37 PM", new Date(2019, 11, 17, 23, 15, 37)], - ["2019/12/17 12:15:37 PM", new Date(2019, 11, 17, 0, 15, 37)], + ["2019/12/17 12:15:37 PM", new Date(2019, 11, 17, 12, 15, 37)], ["2019/12/17 11:15:37.000 AM", new Date(2019, 11, 17, 11, 15, 37, 0)], ["2019/12/17 11:15:37.000 PM", new Date(2019, 11, 17, 23, 15, 37, 0)], + ["2023/03/30 12:09:43.000 PM", new Date(2023, 2, 30, 12, 9, 43, 0)], + ["2023/03/30 12:09:43.000 AM", new Date(2023, 2, 30, 0, 9, 43, 0)], ["20191217 11:15 AM", EMPTY_DATE_VALUE], ["2019217 11:15 AM", EMPTY_DATE_VALUE], ["20191217 11:15:37 AM", EMPTY_DATE_VALUE],