import addLeadingZeros from '../../addLeadingZeros/index' ; const formatters = { y ( date , token ) { const signedYear = date . getUTCFullYear ( ) ; const year = signedYear > 0 ? signedYear : 1 - signedYear ; return addLeadingZeros ( token === 'yy' ? year % 100 : year , token . length ) ; } , M ( date , token ) { const month = date . getUTCMonth ( ) ; return token === 'M' ? String ( month + 1 ) : addLeadingZeros ( month + 1 , 2 ) ; } , d ( date , token ) { return addLeadingZeros ( date . getUTCDate ( ) , token . length ) ; } , a ( date , token ) { const dayPeriodEnumValue = date . getUTCHours ( ) / 12 >= 1 ? 'pm' : 'am' ; switch ( token ) { case 'a' : case 'aa' : return dayPeriodEnumValue . toUpperCase ( ) ; case 'aaa' : return dayPeriodEnumValue ; case 'aaaaa' : return dayPeriodEnumValue [ 0 ] ; case 'aaaa' : default : return dayPeriodEnumValue === 'am' ? 'a.m.' : 'p.m.' ; } } , h ( date , token ) { return addLeadingZeros ( date . getUTCHours ( ) % 12 || 12 , token . length ) ; } , H ( date , token ) { return addLeadingZeros ( date . getUTCHours ( ) , token . length ) ; } , m ( date , token ) { return addLeadingZeros ( date . getUTCMinutes ( ) , token . length ) ; } , s ( date , token ) { return addLeadingZeros ( date . getUTCSeconds ( ) , token . length ) ; } , S ( date , token ) { const numberOfDigits = token . length ; const milliseconds = date . getUTCMilliseconds ( ) ; const fractionalSeconds = Math . floor ( milliseconds * Math . pow ( 10 , numberOfDigits - 3 ) ) ; return addLeadingZeros ( fractionalSeconds , token . length ) ; } , } ; export default formatters ;