1- import { FormatOptions , ICalendarDate , ICalendarDay , IDefaultSelect } from '../interfaces' ;
1+ import { FormatOptions , ICalendarDate , ICalendarDay , IDefaultSelect , IHoursOptions } from '../interfaces' ;
22
33/**
44 * Depending on a week start get starting date of the current calendar
@@ -61,6 +61,13 @@ export const getCalendarDays = (month: number, year: number, start: number): ICa
6161 return weeks ;
6262} ;
6363
64+ /**
65+ * Different config for 24h and 12H
66+ */
67+ const getHoursOptions = ( is24 : boolean ) : IHoursOptions => {
68+ return is24 ? { hourCycle : 'h23' } : { hour12 : true } ;
69+ } ;
70+
6471/**
6572 * Format Date object into readable format, specified by props
6673 */
@@ -73,7 +80,12 @@ export const formatSingleDate = (
7380) : string => {
7481 let options = formatOptions ;
7582 if ( showTime ) {
76- options = Object . assign ( options , { hour : 'numeric' , minute : 'numeric' , hour12 : ! is24 } ) ;
83+ options = Object . assign ( options , {
84+ hour : 'numeric' ,
85+ minute : 'numeric' ,
86+ hourCycle : 'h23' ,
87+ ...getHoursOptions ( is24 ) ,
88+ } ) ;
7789 }
7890 return date . toLocaleDateString ( locale , options ) ;
7991} ;
@@ -91,7 +103,7 @@ export const formatRangeDate = (
91103) : string | string [ ] => {
92104 let options = formatOptions ;
93105 if ( showTime ) {
94- options = Object . assign ( options , { hour : 'numeric' , minute : 'numeric' , hour12 : ! is24 } ) ;
106+ options = Object . assign ( options , { hour : 'numeric' , minute : 'numeric' , ... getHoursOptions ( is24 ) } ) ;
95107 }
96108 if ( returnArr ) {
97109 return [ dates [ 0 ] . toLocaleDateString ( locale , options ) , dates [ 1 ] . toLocaleDateString ( locale , options ) ] ;
0 commit comments