import { MessageThreadStrings } from '../MessageThread' ; private export const formatTimeForChatMessage = ( messageDate ) : string => { let hours = messageDate . getHours ( ) ; let minutes = messageDate . getMinutes ( ) . toString ( ) ; const isAm = hours < 12 ; if ( hours > 12 ) { hours = hours - 12 ; } if ( hours === 0 ) { hours = 12 ; } if ( minutes . length < 2 ) { minutes = '0' + minutes ; } return hours . toString ( ) + ':' + minutes + ' ' + ( isAm ? 'a.m.' : 'p.m.' ) ; } ; private export const formatDateForChatMessage = ( messageDate ) : string => { const year = messageDate . getFullYear ( ) . toString ( ) ; let month = ( messageDate . getMonth ( ) + 1 ) . toString ( ) ; let day = messageDate . getDate ( ) . toString ( ) ; if ( month . length === 1 ) { month = '0' + month ; } if ( day . length === 1 ) { day = '0' + day ; } return year + '-' + month + '-' + day ; } ; param messageDate param currentDate private export const formatTimestampForChatMessage = ( messageDate , todayDate , dateStrings ) : string => { const startOfDay = new Date ( todayDate . getFullYear ( ) , todayDate . getMonth ( ) , todayDate . getDate ( ) ) ; if ( messageDate > startOfDay ) { return formatTimeForChatMessage ( messageDate ) ; } const yesterdayDate = new Date ( todayDate . getFullYear ( ) , todayDate . getMonth ( ) , todayDate . getDate ( ) - 1 ) ; if ( messageDate > yesterdayDate ) { return dateStrings . yesterday + ' ' + formatTimeForChatMessage ( messageDate ) ; } const weekDay = todayDate . getDay ( ) ; if ( weekDay === 0 ) { return formatDateForChatMessage ( messageDate ) + ' ' + formatTimeForChatMessage ( messageDate ) ; } const firstDayOfTheWeekDate = new Date ( todayDate . getFullYear ( ) , todayDate . getMonth ( ) , todayDate . getDate ( ) - weekDay ) ; if ( messageDate > firstDayOfTheWeekDate ) { return dayToDayName ( messageDate . getDay ( ) , dateStrings ) + ' ' + formatTimeForChatMessage ( messageDate ) ; } return formatDateForChatMessage ( messageDate ) + ' ' + formatTimeForChatMessage ( messageDate ) ; } ; const dayToDayName = ( day , dateStrings ) : string => { switch ( day ) { case 0 : return dateStrings . sunday ; case 1 : return dateStrings . monday ; case 2 : return dateStrings . tuesday ; case 3 : return dateStrings . wednesday ; case 4 : return dateStrings . thursday ; case 5 : return dateStrings . friday ; case 6 : return dateStrings . saturday ; default : throw new Error ( `Invalid day [${ day }] passed` ) ; } } ;