license import { NativeDateService , NativeDateServiceOptions , } from '@ui-kitten/components' ; import dateFnsParse from 'date-fns/parse' ; import dateFnsFormat from 'date-fns/format' ; export interface DateFnsOptions extends NativeDateServiceOptions { parseOptions ? : { } ; formatOptions ? : { } ; } const DEFAULT_OPTIONS = { format : 'dd/MM/yyyy' , parseOptions : { useAdditionalDayOfYearTokens : true , useAdditionalWeekYearTokens : true , } , formatOptions : { useAdditionalDayOfYearTokens : true , useAdditionalWeekYearTokens : true , } , } ; export class DateFnsService extends NativeDateService { constructor ( locale = 'en' , options ? ) { super ( locale , { ... DEFAULT_OPTIONS , ... options } ) ; } public format ( date , format ) { if ( date ) { return dateFnsFormat ( date , format || this . options . format , ( this . options as DateFnsOptions ) . formatOptions ) ; } return '' ; } public parse ( date , format ) { return dateFnsParse ( date , format || this . options . format , new Date ( ) , ( this . options as DateFnsOptions ) . parseOptions ) ; } public getId ( ) { return 'date-fns' ; } }