import moment from 'moment-timezone' ; import type { Moment } from 'moment-timezone' ; import type { SingleBuildingScheduleType } from '../types' ; import { timezone } from '@frogpond/constants' ; import { TIME_FORMAT } from './constants' ; type HourPairType = { open : Moment ; close : Moment ; } ; export function parseHours ( { from : fromTime , to : toTime } , m ) { let dayOfYear = m . dayOfYear ( ) ; if ( m . hour ( ) < 2 ) { dayOfYear -= 1 ; } let open = moment . tz ( fromTime , TIME_FORMAT , true , timezone ( ) ) ; open . year ( m . year ( ) ) . month ( m . month ( ) ) . date ( m . date ( ) ) . dayOfYear ( dayOfYear ) ; let close = moment . tz ( toTime , TIME_FORMAT , true , timezone ( ) ) ; close . year ( m . year ( ) ) . month ( m . month ( ) ) . date ( m . date ( ) ) . dayOfYear ( dayOfYear ) ; if ( close . isBefore ( open ) ) { close . add ( 1 , 'day' ) ; } return { open , close } ; }