import { DateTime as LuxonDateTime } from 'luxon' ; import { CalendarIntervalUnit , CalendarObj , DateTime , FixedIntervalUnit , Minutes , UnixTimestamp } from './types' ; internal export const timeObjFromCalendarObj = ( yearMonthDayHour , timeZone = 'local' ) : LuxonDateTime => LuxonDateTime . fromObject ( { ... yearMonthDayHour , zone : timeZone } ) ; internal export const timeObjFromUnixTimestamp = ( unixTimestamp , timeZone = 'local' ) : LuxonDateTime => LuxonDateTime . fromMillis ( unixTimestamp , { zone : timeZone } ) ; internal export const timeObjFromDate = ( date , timeZone = 'local' ) : LuxonDateTime => LuxonDateTime . fromJSDate ( date , { zone : timeZone } ) ; internal export const timeObjFromAny = ( time , timeZone = 'local' ) : LuxonDateTime => { return typeof time === 'number' ? timeObjFromUnixTimestamp ( time , timeZone ) : time instanceof Date ? timeObjFromDate ( time , timeZone ) : timeObjFromCalendarObj ( time , timeZone ) ; } ; internal export const timeObjToSeconds = ( t ) => t . toSeconds ( ) ; internal export const timeObjToUnixTimestamp = ( t ) : UnixTimestamp => t . toMillis ( ) ; internal export const timeObjToWeekday = ( t ) => t . weekday ; internal export const timeObjToYear = ( t ) => t . year ; internal export const addTimeToObj = ( obj , unit , count ) => obj . plus ( { [ unit ] : count } ) ; internal export const subtractTimeToObj = ( obj , unit , count ) => obj . minus ( { [ unit ] : count } ) ; internal export const startTimeOfObj = ( obj , unit ) => obj . startOf ( unit ) ; internal export const endTimeOfObj = ( obj , unit ) => obj . endOf ( unit ) ; internal export const timeObjToUTCOffset = ( obj ) : Minutes => obj . offset ; internal export const formatTimeObj = ( obj , format ) : string => obj . toFormat ( format ) ; internal export const diffTimeObjs = ( obj1 , obj2 , unit ) : number => obj1 . diff ( obj2 , unit ) . as ( unit ) ;