import { range } from 'lodash' ; /**
 * Utility function for dealing with time, specifically for the timetable
 * where we divide classes up into chunks of 30 minute blocks
 */ export const SGT_OFFSET = - 8 * 60 ; export const ISO8601_DATE_FORMAT = 'yyyy-MM-dd' ; param { string } time example returns { number } const timeIndexMap = { '00' : 0 , '30' : 1 , '59' : 2 } ; export function convertTimeToIndex ( time ) { const hour = parseInt ( time . substring ( 0 , 2 ) , 10 ) ; const minute = time . substring ( 2 ) ; return hour * 2 + timeIndexMap [ minute ] ; } param { number } index example returns { string } export function convertIndexToTime ( index ) { const hour = Math . floor ( index / 2 ) ; const minute = index % 2 === 0 ? '00' : '30' ; return ( hour < 10 ? `0${ hour }` : hour . toString ( ) ) + minute ; } param { string } startTime param { string } endTime example returns { Array } export function getTimeRange ( startTime , endTime ) { const timeRange = range ( convertTimeToIndex ( startTime ) , convertTimeToIndex ( endTime ) ) ; return timeRange . map ( convertIndexToTime ) ; } example export function toSingaporeTime ( date ) { const localDate = new Date ( date ) ; return new Date ( localDate . getTime ( ) + ( localDate . getTimezoneOffset ( ) - SGT_OFFSET ) * 60 * 1000 ) ; }