import { format } from 'date-fns' ; const DATE_REGEX = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/ ; const NEUTRAL_TIME = 'T12:00:00-00:00' ; /**
 * dateValue must follow the format: 'YYYY-MM-DD'
 */ type DateValueType = string ; /**
 * follow https://date-fns.org/v2.21.3/docs/format to define date format
 */ type DateFormatType = string ; param { DateValueType } dateValue param { string } dateFormat return { * } export const formatReturnDate = ( dateValue , dateFormat ) : string => { if ( dateValue . match ( DATE_REGEX ) ) { const datePlusNoonUTC = new Date ( dateValue . concat ( NEUTRAL_TIME ) ) ; return format ( datePlusNoonUTC , dateFormat ) ; } throw new Error ( '[Paste Date Picker]: Please make sure dateValue string matches YYYY-MM-DD format' ) ; } ;