import dayjs from 'dayjs' ; export class HsDimensionDescriptor { public type : string ; public value : any ; public modelValue : any ; public label ? : string ; public values ? : Array < any > ; public format : string ; public modelTimeValue : { hour : any ; minute : any ; } ; constructor ( public name , public originalDimension ) { this . type = this . originalDimension . type ; this . value = this . originalDimension . value ?? this . originalDimension . default ; this . modelValue = this . originalDimension . value ?? this . originalDimension . default ; if ( typeof this . value ?. getMonth == 'function' ) { if ( this . type == 'datetime' ) { this . modelValue = { year : this . value . getFullYear ( ) , month : this . value . getMonth ( ) + 1 , day : this . value . getDate ( ) , } ; this . modelTimeValue = { hour : this . value . getHours ( ) , minute : this . value . getMinutes ( ) , } ; } if ( this . type == 'date' ) { this . modelValue = { year : this . value . getFullYear ( ) , month : this . value . getMonth ( ) + 1 , day : this . value . getDate ( ) , } ; } } this . label = this . originalDimension . label ; this . values = this . originalDimension . values ; this . format = this . originalDimension . format ; } postProcessDimensionValue ( ) { if ( this . modelValue . year && this . modelValue . month ) { this . originalDimension . value = new Date ( this . modelValue . year , this . modelValue . month - 1 , this . modelValue . day , this . modelTimeValue ?. hour , this . modelTimeValue ?. minute ) ; } else { this . originalDimension . value = this . modelValue ; } if ( [ 'datetime' , 'date' ] . includes ( this . type ) && this . format ) { this . originalDimension . value = dayjs ( this . originalDimension . value ) . format ( this . format ) ; } this . value = this . originalDimension . value ; } }