import { DateEnv } from './datelib/env' ; import { createFormatter } from './datelib/formatting' ; import { NativeFormatterOptions } from './datelib/formatting-native' ; import { organizeRawLocales , buildLocale } from './datelib/locale' ; import { BASE_OPTION_DEFAULTS } from './options' ; import { DateInput } from './api-type-deps' ; export interface FormatDateOptions extends NativeFormatterOptions { locale ? : string ; } export interface FormatRangeOptions extends FormatDateOptions { separator ? : string ; isEndExclusive ? : boolean ; } export function formatDate ( dateInput , options = { } ) { let dateEnv = buildDateEnv ( options ) ; let formatter = createFormatter ( options ) ; let dateMeta = dateEnv . createMarkerMeta ( dateInput ) ; if ( ! dateMeta ) { return '' ; } return dateEnv . format ( dateMeta . marker , formatter , { forcedTzo : dateMeta . forcedTzo , } ) ; } export function formatRange ( startInput , endInput , options ) { let dateEnv = buildDateEnv ( typeof options === 'object' && options ? options : { } ) ; let formatter = createFormatter ( options ) ; let startMeta = dateEnv . createMarkerMeta ( startInput ) ; let endMeta = dateEnv . createMarkerMeta ( endInput ) ; if ( ! startMeta || ! endMeta ) { return '' ; } return dateEnv . formatRange ( startMeta . marker , endMeta . marker , formatter , { forcedStartTzo : startMeta . forcedTzo , forcedEndTzo : endMeta . forcedTzo , isEndExclusive : options . isEndExclusive , defaultSeparator : BASE_OPTION_DEFAULTS . defaultRangeSeparator , } ) ; } function buildDateEnv ( settings ) { let locale = buildLocale ( settings . locale || 'en' , organizeRawLocales ( [ ] ) . map ) ; return new DateEnv ( { timeZone : BASE_OPTION_DEFAULTS . timeZone , calendarSystem : 'gregory' , ... settings , locale , } ) ; }