import { DateMarker } from './marker' ; import { padStart } from '../util/misc' ; export function buildIsoString ( marker , timeZoneOffset ? , stripZeroTime = false ) { let s = marker . toISOString ( ) ; s = s . replace ( '.000' , '' ) ; if ( stripZeroTime ) { s = s . replace ( 'T00:00:00Z' , '' ) ; } if ( s . length > 10 ) { if ( timeZoneOffset == null ) { s = s . replace ( 'Z' , '' ) ; } else if ( timeZoneOffset !== 0 ) { s = s . replace ( 'Z' , formatTimeZoneOffset ( timeZoneOffset , true ) ) ; } } return s ; } export function formatDayString ( marker ) { return marker . toISOString ( ) . replace ( /T.*$/ , '' ) ; } export function formatIsoTimeString ( marker ) { return padStart ( marker . getUTCHours ( ) , 2 ) + ':' + padStart ( marker . getUTCMinutes ( ) , 2 ) + ':' + padStart ( marker . getUTCSeconds ( ) , 2 ) ; } export function formatTimeZoneOffset ( minutes , doIso = false ) { let sign = minutes < 0 ? '-' : '+' ; let abs = Math . abs ( minutes ) ; let hours = Math . floor ( abs / 60 ) ; let mins = Math . round ( abs % 60 ) ; if ( doIso ) { return `${ sign + padStart ( hours , 2 ) }:${ padStart ( mins , 2 ) }` ; } return `GMT${ sign }${ hours }${ mins ? `:${ padStart ( mins , 2 ) }` : '' }` ; }