This module defines the Formatter
types. It is based on the Java's DateTimeFormatter
format.
Text
represents different text formatting styles.
- short : Std.Time.Text
Short form (e.g., "Tue")
- full : Std.Time.Text
Full form (e.g., "Tuesday")
- narrow : Std.Time.Text
Narrow form (e.g., "T")
Instances For
Equations
- Std.Time.instReprText = { reprPrec := Std.Time.reprText✝ }
Equations
- Std.Time.instInhabitedText = { default := Std.Time.Text.short }
classify
classifies the number of pattern letters into a Text
type.
Equations
- Std.Time.Text.classify num = if num < 4 then some Std.Time.Text.short else if num = 4 then some Std.Time.Text.full else if num = 5 then some Std.Time.Text.narrow else none
Instances For
Equations
- Std.Time.instReprNumber = { reprPrec := Std.Time.reprNumber✝ }
Equations
- Std.Time.instInhabitedNumber = { default := { padding := default } }
classifyNumberText
classifies the number of pattern letters into either a Number
or Text
.
Equations
- Std.Time.classifyNumberText x✝ = if x✝ < 3 then some (Sum.inl { padding := x✝ }) else Sum.inr <$> Std.Time.Text.classify x✝
Instances For
Fraction
represents the fraction of a second, which can either be full nanoseconds
or a truncated form with fewer digits.
- nano : Std.Time.Fraction
Nanosecond precision (up to 9 digits)
- truncated
(digits : Nat)
: Std.Time.Fraction
Fewer digits (truncated precision)
Instances For
Equations
- Std.Time.instReprFraction = { reprPrec := Std.Time.reprFraction✝ }
Equations
- Std.Time.instInhabitedFraction = { default := Std.Time.Fraction.nano }
classify
classifies the number of pattern letters into either a Fraction
. It's used for nano
.
Equations
- Std.Time.Fraction.classify nat = if nat < 9 then some (Std.Time.Fraction.truncated nat) else if nat = 9 then some Std.Time.Fraction.nano else none
Instances For
Year
represents different year formatting styles based on the number of pattern letters.
- twoDigit : Std.Time.Year
Two-digit year format (e.g., "23" for 2023)
- fourDigit : Std.Time.Year
Four-digit year format (e.g., "2023")
- extended
(num : Nat)
: Std.Time.Year
Extended year format for more than 4 digits (e.g., "002023")
Instances For
Equations
- Std.Time.instReprYear = { reprPrec := Std.Time.reprYear✝ }
Equations
- Std.Time.instInhabitedYear = { default := Std.Time.Year.twoDigit }
ZoneId
represents different time zone ID formats based on the number of pattern letters.
- short : Std.Time.ZoneId
Short form of time zone (e.g., "PST")
- full : Std.Time.ZoneId
Full form of time zone (e.g., "Pacific Standard Time")
Instances For
Equations
- Std.Time.instReprZoneId = { reprPrec := Std.Time.reprZoneId✝ }
Equations
- Std.Time.instInhabitedZoneId = { default := Std.Time.ZoneId.short }
classify
classifies the number of pattern letters into a ZoneId
format.
- If 2 letters, it returns the short form.
- If 4 letters, it returns the full form.
- Otherwise, it returns none.
Equations
- Std.Time.ZoneId.classify num = if num = 2 then some Std.Time.ZoneId.short else if num = 4 then some Std.Time.ZoneId.full else none
Instances For
ZoneName
represents different zone name formats based on the number of pattern letters and
whether daylight saving time is considered.
- short : Std.Time.ZoneName
Short form of zone name (e.g., "PST")
- full : Std.Time.ZoneName
Full form of zone name (e.g., "Pacific Standard Time")
Instances For
Equations
- Std.Time.instReprZoneName = { reprPrec := Std.Time.reprZoneName✝ }
Equations
- Std.Time.instInhabitedZoneName = { default := Std.Time.ZoneName.short }
classify
classifies the number of pattern letters and the letter type ('z' or 'v')
into a ZoneName
format.
- For 'z', if less than 4 letters, it returns the short form; if 4 letters, it returns the full form.
- For 'v', if 1 letter, it returns the short form; if 4 letters, it returns the full form.
- Otherwise, it returns none.
Equations
- One or more equations did not get rendered due to their size.
Instances For
OffsetX
represents different offset formats based on the number of pattern letters.
The output will vary between the number of pattern letters, whether it's the hour, minute, second,
and whether colons are used.
- hour : Std.Time.OffsetX
Only the hour is output (e.g., "+01")
- hourMinute : Std.Time.OffsetX
Hour and minute without colon (e.g., "+0130")
- hourMinuteColon : Std.Time.OffsetX
Hour and minute with colon (e.g., "+01:30")
- hourMinuteSecond : Std.Time.OffsetX
Hour, minute, and second without colon (e.g., "+013015")
- hourMinuteSecondColon : Std.Time.OffsetX
Hour, minute, and second with colon (e.g., "+01:30:15")
Instances For
Equations
- Std.Time.instReprOffsetX = { reprPrec := Std.Time.reprOffsetX✝ }
Equations
- Std.Time.instInhabitedOffsetX = { default := Std.Time.OffsetX.hour }
OffsetO
represents localized offset text formats based on the number of pattern letters.
- short : Std.Time.OffsetO
Short form of the localized offset (e.g., "GMT+8")
- full : Std.Time.OffsetO
Full form of the localized offset (e.g., "GMT+08:00")
Instances For
Equations
- Std.Time.instReprOffsetO = { reprPrec := Std.Time.reprOffsetO✝ }
Equations
- Std.Time.instInhabitedOffsetO = { default := Std.Time.OffsetO.short }
OffsetZ
represents different offset formats based on the number of pattern letters (capital 'Z').
- hourMinute : Std.Time.OffsetZ
Hour and minute without colon (e.g., "+0130")
- full : Std.Time.OffsetZ
Localized offset text in full form (e.g., "GMT+08:00")
- hourMinuteSecondColon : Std.Time.OffsetZ
Hour, minute, and second with colon (e.g., "+01:30:15")
Instances For
Equations
- Std.Time.instReprOffsetZ = { reprPrec := Std.Time.reprOffsetZ✝ }
Equations
- Std.Time.instInhabitedOffsetZ = { default := Std.Time.OffsetZ.hourMinute }
The Modifier
inductive type represents various formatting options for date and time components,
matching the format symbols used in date and time strings.
These modifiers can be applied in formatting functions to generate custom date and time outputs.
- G
(presentation : Std.Time.Text)
: Std.Time.Modifier
G
: Era (e.g., AD, Anno Domini, A). - y
(presentation : Std.Time.Year)
: Std.Time.Modifier
y
: Year of era (e.g., 2004, 04, 0002, 2). - u
(presentation : Std.Time.Year)
: Std.Time.Modifier
u
: Year (e.g., 2004, 04, -0001, -1). - D
(presentation : Std.Time.Number)
: Std.Time.Modifier
D
: Day of year (e.g., 189). - MorL
(presentation : Std.Time.Number ⊕ Std.Time.Text)
: Std.Time.Modifier
M
: Month of year as number or text (e.g., 7, 07, Jul, July, J). - d
(presentation : Std.Time.Number)
: Std.Time.Modifier
d
: Day of month (e.g., 10). - Qorq
(presentation : Std.Time.Number ⊕ Std.Time.Text)
: Std.Time.Modifier
Q
: Quarter of year as number or text (e.g., 3, 03, Q3, 3rd quarter). - w
(presentation : Std.Time.Number)
: Std.Time.Modifier
w
: Week of week-based year (e.g., 27). - W
(presentation : Std.Time.Number)
: Std.Time.Modifier
W
: Week of month (e.g., 4). - E
(presentation : Std.Time.Text)
: Std.Time.Modifier
E
: Day of week as text (e.g., Tue, Tuesday, T). - eorc
(presentation : Std.Time.Number ⊕ Std.Time.Text)
: Std.Time.Modifier
e
: Localized day of week as number or text (e.g., 2, 02, Tue, Tuesday, T). - F
(presentation : Std.Time.Number)
: Std.Time.Modifier
F
: Aligned week of month (e.g., 3). - a
(presentation : Std.Time.Text)
: Std.Time.Modifier
a
: AM/PM of day (e.g., PM). - h
(presentation : Std.Time.Number)
: Std.Time.Modifier
h
: Clock hour of AM/PM (1-12) (e.g., 12). - K
(presentation : Std.Time.Number)
: Std.Time.Modifier
K
: Hour of AM/PM (0-11) (e.g., 0). - k
(presentation : Std.Time.Number)
: Std.Time.Modifier
k
: Clock hour of day (1-24) (e.g., 24). - H
(presentation : Std.Time.Number)
: Std.Time.Modifier
H
: Hour of day (0-23) (e.g., 0). - m
(presentation : Std.Time.Number)
: Std.Time.Modifier
m
: Minute of hour (e.g., 30). - s
(presentation : Std.Time.Number)
: Std.Time.Modifier
s
: Second of minute (e.g., 55). - S
(presentation : Std.Time.Fraction)
: Std.Time.Modifier
S
: Fraction of second (e.g., 978). - A
(presentation : Std.Time.Number)
: Std.Time.Modifier
A
: Millisecond of day (e.g., 1234). - n
(presentation : Std.Time.Number)
: Std.Time.Modifier
n
: Nanosecond of second (e.g., 987654321). - N
(presentation : Std.Time.Number)
: Std.Time.Modifier
N
: Nanosecond of day (e.g., 1234000000). - V : Std.Time.Modifier
V
: Time zone ID (e.g., America/Los_Angeles, Z, -08:30). - z
(presentation : Std.Time.ZoneName)
: Std.Time.Modifier
z
: Time zone name (e.g., Pacific Standard Time, PST). - O
(presentation : Std.Time.OffsetO)
: Std.Time.Modifier
O
: Localized zone offset (e.g., GMT+8, GMT+08:00, UTC-08:00). - X
(presentation : Std.Time.OffsetX)
: Std.Time.Modifier
X
: Zone offset with 'Z' for zero (e.g., Z, -08, -0830, -08:30). - x
(presentation : Std.Time.OffsetX)
: Std.Time.Modifier
x
: Zone offset without 'Z' (e.g., +0000, -08, -0830, -08:30). - Z
(presentation : Std.Time.OffsetZ)
: Std.Time.Modifier
Z
: Zone offset with 'Z' for UTC (e.g., +0000, -0800, -08:00).
Instances For
Equations
- Std.Time.instReprModifier = { reprPrec := Std.Time.reprModifier✝ }
Equations
- Std.Time.instInhabitedModifier = { default := Std.Time.Modifier.G default }
The part of a formatting string. A string is just a text and a modifier is in the format described in
the Modifier
type.
- string
(val : String)
: Std.Time.FormatPart
A string literal.
- modifier
(modifier : Std.Time.Modifier)
: Std.Time.FormatPart
A modifier that renders some data into text.
Instances For
Equations
- Std.Time.instReprFormatPart = { reprPrec := Std.Time.reprFormatPart✝ }
Equations
The format of date and time string.
Equations
Instances For
If the format is aware of some timezone data it parses or if it parses any timezone.
- only : Std.Time.TimeZone → Std.Time.Awareness
The format only parses a single timezone.
- any : Std.Time.Awareness
The format parses any timezone.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
A specification on how to format a data or parse some string.
- string : Std.Time.FormatString
The format that is not aware of the timezone.
Instances For
Equations
- Std.Time.instInhabitedGenericFormat = { default := { string := default } }
Equations
- Std.Time.instReprGenericFormat = { reprPrec := Std.Time.reprGenericFormat✝ }
Parses a short value of a Month.Ordinal
Equations
- One or more equations did not get rendered due to their size.
Instances For
Constructs a new GenericFormat
specification for a date-time string. Modifiers can be combined to create
custom formats, such as "YYYY, MMMM, D".
Equations
- Std.Time.GenericFormat.spec input = do let string ← Std.Time.specParser✝.run input pure { string := string }
Instances For
Builds a GenericFormat
from the input string. If parsing fails, it will panic
Equations
- One or more equations did not get rendered due to their size.
Instances For
Formats a DateTime
value into a string using the given GenericFormat
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Parser for a format with a builder.
Equations
- Std.Time.GenericFormat.builderParser format func = Std.Time.GenericFormat.builderParser.go format func
Instances For
Equations
- Std.Time.GenericFormat.builderParser.go (Std.Time.FormatPart.modifier x :: xs) func_2 = do let res ← Std.Time.parseWith✝ x Std.Time.GenericFormat.builderParser.go xs (func_2 res)
- Std.Time.GenericFormat.builderParser.go (Std.Time.FormatPart.string s :: xs) func_2 = Std.Internal.Parsec.String.skipString s *> Std.Time.GenericFormat.builderParser.go xs func_2
- Std.Time.GenericFormat.builderParser.go [] (some res) = Std.Internal.Parsec.eof *> pure res
- Std.Time.GenericFormat.builderParser.go [] none = Std.Internal.Parsec.fail "invalid date."
Instances For
Parses the input string into a ZoneDateTime
.
Equations
- format.parse input = (Std.Time.GenericFormat.parser✝ format.string aw <* Std.Internal.Parsec.eof).run input
Instances For
Parses the input string into a ZoneDateTime
and panics if its wrong.
Equations
- format.parse! input = match format.parse input with | Except.ok res => res | Except.error err => panicWithPosWithDecl "Std.Time.Format.Basic" "Std.Time.GenericFormat.parse!" 1432 18 err
Instances For
Parses an input string using a builder function to produce a value.
Equations
- format.parseBuilder builder input = (Std.Time.GenericFormat.builderParser format.string builder).run input
Instances For
Parses an input string using a builder function, panicking on errors.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Formats the date using the format into a String, using a getInfo
function to get the information needed to build the String
.
Equations
- format.formatGeneric getInfo = Std.Time.GenericFormat.formatGeneric.go getInfo "" format.string
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Std.Time.GenericFormat.formatGeneric.go getInfo data (Std.Time.FormatPart.string val :: xs) = Std.Time.GenericFormat.formatGeneric.go getInfo (data ++ val) xs
- Std.Time.GenericFormat.formatGeneric.go getInfo data [] = some data
Instances For
Constructs a FormatType
function to format a date into a string using a GenericFormat
.
Equations
- format.formatBuilder = Std.Time.GenericFormat.formatBuilder.go "" format.string
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Std.Time.GenericFormat.formatBuilder.go data (Std.Time.FormatPart.string val :: xs) = Std.Time.GenericFormat.formatBuilder.go (data ++ val) xs
- Std.Time.GenericFormat.formatBuilder.go data [] = data
Instances For
Typeclass for formatting and parsing values with the given format type.
- format (fmt : f) : typ String fmt
Converts a format
f
into a string. Parses a string into a format using the provided format type
f
.