@@ -19,10 +19,10 @@ const getMonths = (locale: string, style: 'long' | 'short' | 'narrow') => {
1919 const months2 = [ ] ;
2020
2121 for ( let i = 0 ; i < 12 ; i ++ ) {
22- months1 . push ( dtf1 . formatToParts ( new Date ( 2024 , i , 1 , 0 ) ) . find ( p => p . type === 'month' ) ?. value || '' ) ;
22+ months1 . push ( dtf1 . formatToParts ( new Date ( 2024 , i , 1 , 0 ) ) . find ( p => p . type === 'month' ) ?. value ?? '' ) ;
2323 }
2424 for ( let i = 0 ; i < 12 ; i ++ ) {
25- months2 . push ( dtf2 . formatToParts ( new Date ( 2024 , i , 1 , 0 ) ) . find ( p => p . type === 'month' ) ?. value || '' ) ;
25+ months2 . push ( dtf2 . formatToParts ( new Date ( 2024 , i , 1 , 0 ) ) . find ( p => p . type === 'month' ) ?. value ?? '' ) ;
2626 }
2727 return compare ( months1 , months2 ) ? months1 : [ months1 , months2 ] ;
2828} ;
@@ -36,10 +36,10 @@ const getWeekdays = (locale: string, style: 'long' | 'short' | 'narrow') => {
3636 const weekdays2 = [ ] ;
3737
3838 for ( let i = 1 ; i <= 7 ; i ++ ) {
39- weekdays1 . push ( dtf1 . formatToParts ( new Date ( 2024 , 11 , i , 0 ) ) . find ( p => p . type === 'weekday' ) ?. value || '' ) ;
39+ weekdays1 . push ( dtf1 . formatToParts ( new Date ( 2024 , 11 , i , 0 ) ) . find ( p => p . type === 'weekday' ) ?. value ?? '' ) ;
4040 }
4141 for ( let i = 1 ; i <= 7 ; i ++ ) {
42- weekdays2 . push ( dtf2 . formatToParts ( new Date ( 2024 , 11 , i , 0 ) ) . find ( p => p . type === 'weekday' ) ?. value || '' ) ;
42+ weekdays2 . push ( dtf2 . formatToParts ( new Date ( 2024 , 11 , i , 0 ) ) . find ( p => p . type === 'weekday' ) ?. value ?? '' ) ;
4343 }
4444 return compare ( weekdays1 , weekdays2 ) ? weekdays1 : [ weekdays1 , weekdays2 ] ;
4545} ;
@@ -49,18 +49,18 @@ const getDayPeriod = (locale: string) => {
4949 const options2 : Intl . DateTimeFormatOptions = { ...options1 , weekday : 'long' , year : 'numeric' , month : 'long' , day : 'numeric' } ;
5050 const dtf1 = new Intl . DateTimeFormat ( locale , options1 ) ;
5151 const dtf2 = new Intl . DateTimeFormat ( locale , options2 ) ;
52- const dayperiod1 = [ ] ;
53- const dayperiod2 = [ ] ;
52+ const dayperiod1 : string [ ] = [ ] ;
53+ const dayperiod2 : string [ ] = [ ] ;
5454
5555 for ( let i = 0 ; i < 24 ; i ++ ) {
56- const value = dtf1 . formatToParts ( new Date ( 2024 , 11 , 1 , i ) ) . find ( p => p . type === 'dayPeriod' ) ?. value || '' ;
57- if ( dayperiod1 . indexOf ( value ) < 0 ) {
56+ const value = dtf1 . formatToParts ( new Date ( 2024 , 11 , 1 , i ) ) . find ( p => p . type === 'dayPeriod' ) ?. value ?? '' ;
57+ if ( ! dayperiod1 . includes ( value ) ) {
5858 dayperiod1 . push ( value ) ;
5959 }
6060 }
6161 for ( let i = 0 ; i < 24 ; i ++ ) {
62- const value = dtf2 . formatToParts ( new Date ( 2024 , 11 , 1 , i ) ) . find ( p => p . type === 'dayPeriod' ) ?. value || '' ;
63- if ( dayperiod2 . indexOf ( value ) < 0 ) {
62+ const value = dtf2 . formatToParts ( new Date ( 2024 , 11 , 1 , i ) ) . find ( p => p . type === 'dayPeriod' ) ?. value ?? '' ;
63+ if ( ! dayperiod2 . includes ( value ) ) {
6464 dayperiod2 . push ( value ) ;
6565 }
6666 }
@@ -82,7 +82,6 @@ const getParts = (locale: string) => {
8282const getDate = ( locale : string ) => {
8383 const options : Intl . DateTimeFormatOptions = {
8484 hour12 : true , weekday : 'short' ,
85- // year: 'numeric', month: 'long', day: 'numeric',
8685 year : 'numeric' , month : 'short' , day : 'numeric' ,
8786 hour : 'numeric' , minute : 'numeric' , second : 'numeric' , fractionalSecondDigits : 3 ,
8887 timeZone : 'Europe/Paris' , timeZoneName : 'longOffset'
0 commit comments