import { format , setHours , setMinutes , differenceInHours , distanceInWordsToNow , } from 'date-fns' ; import firebase from 'firebase/app' ; export type Timestamp = firebase . firestore . Timestamp ; export const convertTimestampToDate = ( timestamp ) : Date => timestamp . toDate ( ) ; export const convertDateToTimestamp = ( date ) : Timestamp => firebase . firestore . Timestamp . fromDate ( date ) ; export const now = ( ) : Timestamp => firebase . firestore . Timestamp . now ( ) ; export const formatIncidentDate = ( incidentTimestamp ) => { const timestampToDate = convertTimestampToDate ( incidentTimestamp ) ; return format ( timestampToDate , 'MMM Do YYYY @ h:mma' ) ; } ; export const createDateWithHoursAndMinutes = ( { hours , minutes , } ) => setHours ( setMinutes ( new Date ( ) , minutes ) , hours ) ; export const compareHourDifference = ( firstDate , secondDate ) : number => differenceInHours ( convertTimestampToDate ( firstDate ) , convertTimestampToDate ( secondDate ) ) ; export const distanceInWords = ( timestamp ) : string => distanceInWordsToNow ( convertTimestampToDate ( timestamp ) ) ;