import moment from 'moment-timezone' ; import { CalendarIntervalUnit , CalendarObj , DateTime , FixedIntervalUnit , Minutes , UnixTimestamp } from './types' ; internal export const timeObjFromCalendarObj = ( yearMonthDayHour , timeZone = 'browser' ) : moment . Moment => timeZone ? moment . tz ( { ... yearMonthDayHour , month : typeof yearMonthDayHour . month === 'number' ? yearMonthDayHour . month - 1 : undefined , } , timeZone ) : moment ( { ... yearMonthDayHour , month : typeof yearMonthDayHour . month === 'number' ? yearMonthDayHour . month - 1 : undefined , } ) ; internal export const timeObjFromUnixTimestamp = ( unixTimestamp , timeZone ? ) : moment . Moment => timeZone ? moment . tz ( unixTimestamp , timeZone ) : moment ( unixTimestamp ) ; internal export const timeObjFromDate = ( date , timeZone ? ) : moment . Moment => timeZone ? moment . tz ( date , timeZone ) : moment ( date ) ; internal export const timeObjFromAny = ( time , timeZone ? ) : moment . Moment => { return typeof time === 'number' ? timeObjFromUnixTimestamp ( time , timeZone ) : time instanceof Date ? timeObjFromDate ( time , timeZone ) : timeObjFromCalendarObj ( time , timeZone ) ; } ; internal export const timeObjToSeconds = ( t ) => t . unix ( ) ; internal export const timeObjToUnixTimestamp = ( t ) : UnixTimestamp => t . valueOf ( ) ; internal export const timeObjToWeekday = ( t ) => t . isoWeekday ( ) ; internal export const timeObjToYear = ( t ) => t . year ( ) ; internal export const addTimeToObj = ( obj , unit , count ) => obj . add ( count , unit ) ; internal export const subtractTimeToObj = ( obj , unit , count ) => obj . subtract ( count , unit ) ; internal export const startTimeOfObj = ( obj , unit ) => obj . startOf ( unit === 'week' ? 'isoWeek' : unit ) ; internal export const endTimeOfObj = ( obj , unit ) => obj . endOf ( unit === 'week' ? 'isoWeek' : unit ) ; internal export const timeObjToUTCOffset = ( obj ) : Minutes => obj . utcOffset ( ) ; internal export const formatTimeObj = ( obj , format ) : string => obj . format ( format ) ; internal export const diffTimeObjs = ( obj1 , obj2 , unit ) : number => obj1 . diff ( obj2 , unit ) ; internal export const TOKENS = { year : 'Y' , year2DGT : 'YY' , year4DGT : 'YYYY' , monthNPD : 'M' , monthORD : 'Mo' , monthPD : 'MM' , monthAbr : 'MMM' , monthFull : 'MMMM' , dayOfMonthNP : 'D' , dayOfMonthORD : 'Do' , dayOfMonthPD : 'DD' , dayOfYNP : 'DDD' , dayOfYORD : 'DDDo' , dayOfYPD : 'DDDD' , } ;