import { IOSNativeProps } from '@react-native-community/datetimepicker' ; import { asLocaleDate } from './date' ; export type LabelExtractorOptions = { mode : IOSNativeProps [ 'mode' ] | 'month' | 'year' ; locale : IOSNativeProps [ 'locale' ] ; utc ? : boolean ; } ; export const withoutSeconds = ( localeString ) : string => localeString . replace ( /(.*):\d+(.*)/ , '$1$2' ) ; export const defaultLabelExtractor = ( date , { mode , locale , utc } ) : string => { const value = utc ? asLocaleDate ( date ) : date ; switch ( mode ) { case 'date' : return value . toLocaleDateString ( locale ) ; case 'time' : return withoutSeconds ( value . toLocaleTimeString ( locale ) ) ; case 'datetime' : return withoutSeconds ( value . toLocaleString ( locale ) ) ; case 'month' : { const month = value . getMonth ( ) + 1 ; return `${ month < 10 ? `0${ month }` : month }/${ value . getFullYear ( ) }` ; } default : return '' ; } } ;