import moment from 'moment' ; const JANUARY_MOMENT_CONFIG = { M : 0 , d : 1 } ; function getFormat ( interval , rules = [ ] ) { for ( let i = rules . length - 1 ; i >= 0 ; i -- ) { const rule = rules [ i ] ; if ( ! rule [ 0 ] || interval >= Number ( moment . duration ( rule [ 0 ] ) ) ) { return rule [ 1 ] ; } } } export function createIntervalBasedFormatter ( interval , rules , dateFormat , ignoreDaylightTime ) { const fixedOffset = moment ( JANUARY_MOMENT_CONFIG ) . utcOffset ( ) ; return ( val ) => { const momentVal = moment ( val ) ; if ( ignoreDaylightTime ) { momentVal . utcOffset ( fixedOffset ) ; } return momentVal . format ( getFormat ( interval , rules ) ?? dateFormat ) ; } ; }