import moment , { Moment } from 'moment' ; import 'moment-timezone' ; type DateObj = { M ? : number ; Y ? : number ; } ; export function london ( d ? ) { return moment . tz ( d , 'Europe/London' ) ; } export function formatDay ( date ) { return london ( date ) . format ( 'dddd' ) ; } export function formatDayDate ( date ) { return london ( date ) . format ( 'dddd D MMMM YYYY' ) ; } export function formatDate ( date ) { return london ( date ) . format ( 'D MMMM YYYY' ) ; } export function formatDateRange ( date ) { return london ( date ) . format ( 'D MMMM YYYY' ) ; } export function formatTime ( date ) { return london ( date ) . format ( 'HH:mm' ) ; } export function isTimePast ( date ) { const momentNow = london ( ) ; const momentEnd = london ( date ) ; return momentEnd . isBefore ( momentNow ) ; } export function isDatePast ( date ) { const momentNow = london ( ) ; const momentEnd = london ( date ) ; return momentEnd . isBefore ( momentNow , 'day' ) ; } export function formatDateRangeWithMessage ( { start , end , } ) { const now = london ( ) ; const s = london ( start ) ; const e = london ( end ) ; if ( s . isAfter ( now , 'day' ) ) { return { text : 'Coming soon' , color : 'marble' } ; } else if ( e . isBefore ( now , 'day' ) ) { return { text : 'Past' , color : 'marble' } ; } else if ( now . isBetween ( e . clone ( ) . subtract ( 1 , 'w' ) , e , 'day' ) ) { return { text : 'Final week' , color : 'orange' } ; } else { return { text : 'Now on' , color : 'green' } ; } } export function formatYear ( date ) { return london ( date ) . format ( 'YYYY' ) ; } export function formatDayMonth ( date ) { return london ( date ) . format ( 'D MMMM' ) ; }