Documentation
¶
Overview ¶
Package answer parses and evaluates the launcher's inline answers beyond arithmetic: currency conversions over the ECB's reference rates, times across time zones, and calendar date arithmetic.
Index ¶
Constants ¶
const FeedURL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
FeedURL is the ECB's daily euro foreign exchange reference rates.
Variables ¶
This section is empty.
Functions ¶
func FormatAmount ¶
FormatAmount writes an amount with two decimals, or with as many as it takes (up to six) to show a non-zero amount below a cent.
Types ¶
type Currency ¶
type Currency uint8
Currency is one of the currencies the ECB publishes a reference rate for, plus the euro the rates are quoted against.
type CurrencyParser ¶
type CurrencyParser struct {
// contains filtered or unexported fields
}
CurrencyParser reads currency conversions. Kroner is what "kr" names in the session's language (DKK in Danish); outside the Nordic languages "kr" is ambiguous and names nothing.
func NewCurrencyParser ¶
func NewCurrencyParser(language string) CurrencyParser
NewCurrencyParser reads "kr" as the kroner of language, an ISO 639 code.
func (CurrencyParser) Parse ¶
func (p CurrencyParser) Parse(query string) (CurrencyQuery, bool)
Parse reads "<amount> <currency> in <currency>", the source currency before or after the amount ("$100 to €", "100 dollars in euros").
type CurrencyQuery ¶
CurrencyQuery is a parsed "100 usd in eur": Amount is the decimal text as typed.
type DateAnswer ¶
DateAnswer is an evaluated date query: a calendar day (Day, midnight UTC) or a number of days.
type RateTable ¶
type RateTable struct {
// Date is the reference day, midnight UTC.
Date time.Time
// contains filtered or unexported fields
}
RateTable is one day of reference rates, each currency's units per euro.
type Rates ¶
type Rates struct {
// contains filtered or unexported fields
}
Rates keeps the reference rates: read from the cache file, fetched from the feed at most once per calendar day, retried an hour after a failure. Snapshot never waits; Refresh does the I/O on its caller's goroutine.
type Snapshot ¶
Snapshot is the rates in use and when they were fetched.
type TimeAnswer ¶
TimeAnswer is an evaluated time query: At in the target zone, named Place ("" for the local zone), DayOffset days after the source's day.
type TimeQuery ¶
type TimeQuery struct {
// contains filtered or unexported fields
}
TimeQuery is a parsed "15:00 PST in Copenhagen" or "time in Tokyo".