Module
Data.Intl.DateTimeFormat
- Package
- purescript-intl
- Repository
- coot/purescript-intl
#DateTimeComponents Source
type DateTimeComponents a = Variant (custom :: a, hourMinute :: HourMinute, hourMinuteSecond :: HourMinuteSecond, monthDay :: MonthDay, weekdayYearMonthDay :: WeekdayYearMonthDay, weekdayYearMonthDayHourMinuteSecond :: WeekdayYearMonthDayHourMinuteSecond, yearMonth :: YearMonth, yearMonthDay :: YearMonthDay)
#DateTimeFormatOptions Source
data DateTimeFormatOptions a
Constructors
DateTimeFormatOptions { formatMatcher :: Maybe FormatMatcher, hour12 :: Maybe Boolean, localeMatcher :: Maybe LocaleMatcher, timeZone :: Maybe TimeZone } (DateTimeComponents a)
#DateTimeFormat Source
data DateTimeFormat :: Type
#createDateTimeFormat Source
createDateTimeFormat :: forall a. FormatComponent a => LocalesOption -> DateTimeFormatOptions a -> F DateTimeFormat
Examples
import Data.Variant (inj)
fmtHourMinute = F DateTimeFormat
fmtHourMinute = createDateTimeFormat locale opts
where
locale = inj (SProxy :: SProxy "locale") "en-GB"
opts = (DateTimeFormatOptions
{ localeMatcher: Nothing
, timeZone: (Just (TimeZone "Europe/London"))
, hour12: Just false
, formatMatcher: Nothing
}
(inj (SProxy :: SProxy "hourMinute")
(HourMinute {hour: TwoDigit, minute: TwoDigit}))
fmtDate :: F DateTimeFormat
fmtDate = createDateTimeFormat locale opts
wher
locale = inj (SProxy :: SProxy "locale") "en-GB"
opts :: DateTimeFormatOptions'
opts =
(DateTimeFormatOptions
{ localeMatcher: Nothing
, timeZone: (Just (TimeZone "Europe/London"))
, hour12: Just true
, formatMatcher: Nothing
}
(inj
(SProxy :: SProxy "weekdayYearMonthDayHourMinuteSecond")
(WeekdayYearMonthDayHourMinuteSecond
{ weekday: Short
, year: Numeric
, month: MonthLong
, day: Numeric
, hour: Numeric
, minute: Numeric
, second: Numeric
}
)
)
)
You have predifined types: WeekdayYearMonthDayHourMinuteSecond
,
WeekdayYearMonthDay
, YearMonthDay
, YearMonth
, MonthDay
,
HourMinuteSecond
, HourMinute
. But you can also provide your own by
implementing FormatComponent
class (or by deriving it), e.g.
newtype EraYear = EraYear
{ era :: StringRep
, year :: NumericRep
}
derive instance genericEraYear :: Generic EraYear _
instance formatComponentEraYear :: FormatComponent EraYear where
formatComponent = genericFormatComponent
fmtEraYear :: F DateTimeFormat
fmtEraYear = createDateTimeFormat locales opts
where
locale = inj (SProxy :: SProxy "locale") "en-GB"
opts :: DateTimeFormatOptions EraYear
opts =
(DateTimeFormatOptions
{ localeMatcher: Nothing
, timeZone: (Just (TimeZone "Europe/London"))
, hour12: Just true
, formatMatcher: Nothing
}
(inj
(SProxy :: SProxy "custom")
(EraYear
{ era: Long
, year: Numeric
}
)
)
)
#formatJSDate Source
formatJSDate :: DateTimeFormat -> JSDate -> String
Examples
formatJSDate (either (const "") id $ runExcept fmtHourMinute) date -- "12:00"
formatJSDate (either (const "") id $ fmtDate) date -- "Tue, January 2, 2018, 12:00:00 PM"
formatJSDate (either (const "") id $ fmtEraYear) date -- "2018 Anno Domini"
#formatToParts Source
formatToParts :: DateTimeFormat -> JSDate -> F (Array FormatParts)
Re-exports from Data.Intl.DateTimeFormat.Types
#YearMonthDay Source
newtype YearMonthDay
Constructors
YearMonthDay { day :: NumericRep, month :: MonthRep, year :: NumericRep }
Instances
#YearMonth Source
#WeekdayYearMonthDayHourMinuteSecond Source
newtype WeekdayYearMonthDayHourMinuteSecond
Constructors
WeekdayYearMonthDayHourMinuteSecond { day :: NumericRep, hour :: NumericRep, minute :: NumericRep, month :: MonthRep, second :: NumericRep, weekday :: StringRep, year :: NumericRep }
Instances
#WeekdayYearMonthDay Source
newtype WeekdayYearMonthDay
Constructors
WeekdayYearMonthDay { day :: NumericRep, month :: MonthRep, weekday :: StringRep, year :: NumericRep }
Instances
#TimeZoneNameRep Source
#ResolvedOptions Source
newtype ResolvedOptions
Constructors
ResolvedOptions { calendar :: String, day :: Maybe String, era :: Maybe String, hour :: Maybe String, locale :: String, minute :: Maybe String, numberingSystem :: String, second :: Maybe String, timeZone :: String, timeZoneName :: Maybe String, weekday :: Maybe String, year :: Maybe String }
Instances
#MonthDay Source
#HourMinuteSecond Source
newtype HourMinuteSecond
Constructors
HourMinuteSecond { hour :: NumericRep, minute :: NumericRep, second :: NumericRep }
Instances
#HourMinute Source
#readFormatParts Source
readFormatParts :: Foreign -> F FormatParts