import { addYears , addMonths , addDays , addWeeks , addQuarters , getUnixTime , startOfDay , startOfWeek , startOfMonth , startOfQuarter , startOfYear , endOfDay , endOfWeek , endOfMonth , endOfQuarter , endOfYear , format , fromUnixTime , getDaysInMonth , addSeconds , setDate , addMinutes , addHours , differenceInCalendarDays , isWeekend , getWeek , isToday , differenceInDays , differenceInCalendarQuarters , eachMonthOfInterval , eachWeekOfInterval , eachDayOfInterval } from 'date-fns' ; export { addYears , addMonths , addDays , addWeeks , addQuarters , getUnixTime , startOfDay , startOfWeek , startOfMonth , startOfQuarter , startOfYear , endOfDay , endOfWeek , endOfMonth , endOfQuarter , endOfYear , format , fromUnixTime , getDaysInMonth , addSeconds , setDate , addMinutes , addHours , differenceInCalendarDays , isWeekend , getWeek , isToday , differenceInDays , differenceInCalendarQuarters , eachMonthOfInterval , eachWeekOfInterval , eachDayOfInterval } from 'date-fns' ; export type GanttDateUtil = 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year' ; export class GanttDate { value : Date ; constructor ( date ? ) { if ( date ) { if ( date instanceof Date ) { this . value = date ; } else if ( typeof date === 'string' || typeof date === 'number' ) { if ( date . toString ( ) . length < 13 ) { this . value = fromUnixTime ( + date ) ; } else { this . value = new Date ( date ) ; } } else { throw new Error ( `The input date type is not supported expect Date | string
                     | number | { date: number; with_time: 0 | 1}, actual ${ JSON . stringify ( date ) }` ) ; } } else { this . value = new Date ( ) ; } } getYear ( ) { return this . value . getFullYear ( ) ; } getMonth ( ) { return this . value . getMonth ( ) ; } getDay ( ) { return this . value . getDay ( ) ; } getTime ( ) { return this . value . getTime ( ) ; } getDate ( ) { return this . value . getDate ( ) ; } getHours ( ) { return this . value . getHours ( ) ; } getMinutes ( ) { return this . value . getMinutes ( ) ; } getSeconds ( ) { return this . value . getSeconds ( ) ; } getMilliseconds ( ) { return this . value . getMilliseconds ( ) ; } getWeek ( options = { weekStartsOn : 1 } ) { return getWeek ( this . value , options ) ; } getDaysInMonth ( ) { return getDaysInMonth ( this . value ) ; } getDaysInQuarter ( ) { return differenceInCalendarDays ( this . endOfQuarter ( ) . addSeconds ( 1 ) . value , this . startOfQuarter ( ) . value ) ; } getDaysInYear ( ) { return differenceInCalendarDays ( this . endOfYear ( ) . addSeconds ( 1 ) . value , this . startOfYear ( ) . value ) ; } setDate ( dayOfMonth ) { return new GanttDate ( setDate ( this . value , dayOfMonth ) ) ; } clone ( ) { return new GanttDate ( new Date ( this . value ) ) ; } add ( amount , unit ? ) { switch ( unit ) { case 'second' : return new GanttDate ( this . value ) . addSeconds ( amount ) ; case 'minute' : return new GanttDate ( this . value ) . addMinutes ( amount ) ; case 'hour' : return new GanttDate ( this . value ) . addHours ( amount ) ; case 'day' : return new GanttDate ( this . value ) . addDays ( amount ) ; case 'week' : return new GanttDate ( this . value ) . addWeeks ( amount ) ; case 'month' : return new GanttDate ( this . value ) . addMonths ( amount ) ; case 'quarter' : return new GanttDate ( this . value ) . addQuarters ( amount ) ; case 'year' : return new GanttDate ( this . value ) . addYears ( amount ) ; default : return new GanttDate ( this . value ) . addSeconds ( amount ) ; } } addSeconds ( amount ) { return new GanttDate ( addSeconds ( this . value , amount ) ) ; } addMinutes ( amount ) { return new GanttDate ( addMinutes ( this . value , amount ) ) ; } addHours ( amount ) { return new GanttDate ( addHours ( this . value , amount ) ) ; } addDays ( amount ) { return new GanttDate ( addDays ( this . value , amount ) ) ; } addWeeks ( amount ) { return new GanttDate ( addWeeks ( this . value , amount ) ) ; } addMonths ( amount ) { return new GanttDate ( addMonths ( this . value , amount ) ) ; } addQuarters ( amount ) { return new GanttDate ( addQuarters ( this . value , amount ) ) ; } addYears ( amount ) { return new GanttDate ( addYears ( this . value , amount ) ) ; } startOfDay ( ) { return new GanttDate ( startOfDay ( this . value ) ) ; } startOfWeek ( options ? ) { return new GanttDate ( startOfWeek ( this . value , options ) ) ; } startOfMonth ( ) { return new GanttDate ( startOfMonth ( this . value ) ) ; } startOfQuarter ( ) { return new GanttDate ( startOfQuarter ( this . value ) ) ; } startOfYear ( ) { return new GanttDate ( startOfYear ( this . value ) ) ; } endOfDay ( ) { return new GanttDate ( endOfDay ( this . value ) ) ; } endOfWeek ( options ? ) { return new GanttDate ( endOfWeek ( this . value , options ) ) ; } endOfMonth ( ) { return new GanttDate ( endOfMonth ( this . value ) ) ; } endOfQuarter ( ) { return new GanttDate ( endOfQuarter ( this . value ) ) ; } endOfYear ( ) { return new GanttDate ( endOfYear ( this . value ) ) ; } getUnixTime ( ) { return getUnixTime ( this . value ) ; } format ( mat , options ? ) { return format ( this . value , mat , options ) ; } isWeekend ( ) { return isWeekend ( this . value ) ; } isToday ( ) { return isToday ( this . value ) ; } }