Documentation ¶
Index ¶
- Constants
- Variables
- func DateFromString(env Environment, str string) (dates.Date, error)
- func DateTimeFromString(env Environment, str string, fillTime bool) (time.Time, error)
- func IsPossibleLocationPath(str string) bool
- func TimeFromString(str string) (dates.TimeOfDay, error)
- type Country
- type DateFormat
- type Environment
- type EnvironmentBuilder
- func (b *EnvironmentBuilder) Build() Environment
- func (b *EnvironmentBuilder) WithAllowedLanguages(allowedLanguages []Language) *EnvironmentBuilder
- func (b *EnvironmentBuilder) WithDateFormat(dateFormat DateFormat) *EnvironmentBuilder
- func (b *EnvironmentBuilder) WithDefaultCountry(defaultCountry Country) *EnvironmentBuilder
- func (b *EnvironmentBuilder) WithMaxValueLength(maxValueLength int) *EnvironmentBuilder
- func (b *EnvironmentBuilder) WithNumberFormat(numberFormat *NumberFormat) *EnvironmentBuilder
- func (b *EnvironmentBuilder) WithRedactionPolicy(redactionPolicy RedactionPolicy) *EnvironmentBuilder
- func (b *EnvironmentBuilder) WithTimeFormat(timeFormat TimeFormat) *EnvironmentBuilder
- func (b *EnvironmentBuilder) WithTimezone(timezone *time.Location) *EnvironmentBuilder
- type Language
- type Locale
- type Location
- type LocationHierarchy
- type LocationLevel
- type LocationPath
- type LocationResolver
- type NumberFormat
- type RedactionPolicy
- type TimeFormat
Constants ¶
const ( DateFormatYearMonthDay DateFormat = "YYYY-MM-DD" DateFormatMonthDayYear DateFormat = "MM-DD-YYYY" DateFormatDayMonthYear DateFormat = "DD-MM-YYYY" TimeFormatHourMinute TimeFormat = "tt:mm" TimeFormatHourMinuteAmPm TimeFormat = "h:mm aa" TimeFormatHourMinuteSecond TimeFormat = "tt:mm:ss" TimeFormatHourMinuteSecondAmPm TimeFormat = "h:mm:ss aa" )
standard date and time formats
const (
LocationPathSeparator = ">"
)
Variables ¶
var DefaultNumberFormat = &NumberFormat{DecimalSymbol: `.`, DigitGroupingSymbol: `,`}
DefaultNumberFormat is the default number formatting, e.g. 1,234.567
var NilCountry = Country("")
NilCountry represents our nil, or unknown country
var NilLanguage = Language("")
NilLanguage represents our nil, or unknown language
var NilLocale = Locale{}
var ZeroDateTime = time.Time{}
ZeroDateTime is our uninitialized datetime value
Functions ¶
func DateFromString ¶
func DateFromString(env Environment, str string) (dates.Date, error)
DateFromString returns a date constructed from the passed in string, or an error if we are unable to extract one
func DateTimeFromString ¶
DateTimeFromString returns a datetime constructed from the passed in string, or an error if we are unable to extract one
func IsPossibleLocationPath ¶ added in v0.94.0
IsPossibleLocationPath returns whether the given string could be a location path
Types ¶
type Country ¶
type Country string
Country is a ISO 3166-1 alpha-2 country code
func DeriveCountryFromTel ¶ added in v0.77.0
DeriveCountryFromTel attempts to derive a country code (e.g. RW) from a phone number
type DateFormat ¶
type DateFormat string
DateFormat a date format string
func (DateFormat) String ¶
func (df DateFormat) String() string
type Environment ¶
type Environment interface { DateFormat() DateFormat TimeFormat() TimeFormat Timezone() *time.Location AllowedLanguages() []Language DefaultCountry() Country NumberFormat() *NumberFormat RedactionPolicy() RedactionPolicy MaxValueLength() int DefaultLanguage() Language DefaultLocale() Locale LocationResolver() LocationResolver // Convenience method to get the current time in the env timezone Now() time.Time Equal(Environment) bool }
Environment defines the environment that the Excellent function is running in, this includes the timezone the user is in as well as the preferred date and time formats.
func ReadEnvironment ¶
func ReadEnvironment(data json.RawMessage) (Environment, error)
ReadEnvironment reads an environment from the given JSON
type EnvironmentBuilder ¶
type EnvironmentBuilder struct {
// contains filtered or unexported fields
}
EnvironmentBuilder is a builder for environments
func NewBuilder ¶ added in v0.54.0
func NewBuilder() *EnvironmentBuilder
NewEnvironmentBuilder creates a new environment builder
func (*EnvironmentBuilder) Build ¶
func (b *EnvironmentBuilder) Build() Environment
Build returns the final environment
func (*EnvironmentBuilder) WithAllowedLanguages ¶
func (b *EnvironmentBuilder) WithAllowedLanguages(allowedLanguages []Language) *EnvironmentBuilder
func (*EnvironmentBuilder) WithDateFormat ¶
func (b *EnvironmentBuilder) WithDateFormat(dateFormat DateFormat) *EnvironmentBuilder
WithDateFormat sets the date format
func (*EnvironmentBuilder) WithDefaultCountry ¶
func (b *EnvironmentBuilder) WithDefaultCountry(defaultCountry Country) *EnvironmentBuilder
func (*EnvironmentBuilder) WithMaxValueLength ¶
func (b *EnvironmentBuilder) WithMaxValueLength(maxValueLength int) *EnvironmentBuilder
func (*EnvironmentBuilder) WithNumberFormat ¶
func (b *EnvironmentBuilder) WithNumberFormat(numberFormat *NumberFormat) *EnvironmentBuilder
func (*EnvironmentBuilder) WithRedactionPolicy ¶
func (b *EnvironmentBuilder) WithRedactionPolicy(redactionPolicy RedactionPolicy) *EnvironmentBuilder
func (*EnvironmentBuilder) WithTimeFormat ¶
func (b *EnvironmentBuilder) WithTimeFormat(timeFormat TimeFormat) *EnvironmentBuilder
WithTimeFormat sets the time format
func (*EnvironmentBuilder) WithTimezone ¶
func (b *EnvironmentBuilder) WithTimezone(timezone *time.Location) *EnvironmentBuilder
type Language ¶
type Language string
Language is our internal representation of a language
func ParseLanguage ¶
ParseLanguage returns a new Language for the passed in language string, or an error if not found
type Locale ¶ added in v0.89.0
Locale is the combination of a language and country, e.g. US English, Brazilian Portuguese
type Location ¶ added in v0.94.0
type Location struct {
// contains filtered or unexported fields
}
Location represents a single Location
func NewLocation ¶ added in v0.94.0
func NewLocation(level LocationLevel, name string) *Location
NewLocation creates a new location object
func (*Location) Level ¶ added in v0.94.0
func (l *Location) Level() LocationLevel
Level gets the level of this location
func (*Location) Path ¶ added in v0.94.0
func (l *Location) Path() LocationPath
Path gets the full path of this location
type LocationHierarchy ¶ added in v0.94.0
type LocationHierarchy struct {
// contains filtered or unexported fields
}
LocationHierarchy is a hierarical tree of locations
func NewLocationHierarchy ¶ added in v0.94.0
func NewLocationHierarchy(root *Location, numLevels int) *LocationHierarchy
NewLocationHierarchy cretes a new location hierarchy
func ReadLocationHierarchy ¶ added in v0.94.0
func ReadLocationHierarchy(data json.RawMessage) (*LocationHierarchy, error)
ReadLocationHierarchy reads a location hierarchy from the given JSON
func (*LocationHierarchy) FindByName ¶ added in v0.94.0
func (h *LocationHierarchy) FindByName(name string, level LocationLevel, parent *Location) []*Location
FindByName looks for all locations in the hierarchy with the given level and name or alias
func (*LocationHierarchy) FindByPath ¶ added in v0.94.0
func (h *LocationHierarchy) FindByPath(path LocationPath) *Location
FindByPath looks for a location in the hierarchy with the given path
func (*LocationHierarchy) Root ¶ added in v0.94.0
func (h *LocationHierarchy) Root() *Location
Root gets the root location of this hierarchy (typically a country)
func (*LocationHierarchy) UnmarshalJSON ¶ added in v0.94.0
func (h *LocationHierarchy) UnmarshalJSON(data []byte) error
type LocationLevel ¶ added in v0.94.0
type LocationLevel int
LocationLevel is a numeric level, e.g. 0 = country, 1 = state
type LocationPath ¶ added in v0.94.0
type LocationPath string
LocationPath is a location described by a path Country > State ...
func NewLocationPath ¶ added in v0.94.0
func NewLocationPath(parts ...string) LocationPath
func (LocationPath) Name ¶ added in v0.94.0
func (p LocationPath) Name() string
Name returns the name of the location referenced
func (LocationPath) Normalize ¶ added in v0.94.0
func (p LocationPath) Normalize() LocationPath
Normalize normalizes this location path
type LocationResolver ¶ added in v0.94.0
type LocationResolver interface { FindLocations(string, LocationLevel, *Location) []*Location FindLocationsFuzzy(string, LocationLevel, *Location) []*Location LookupLocation(LocationPath) *Location }
LocationResolver is used to resolve locations from names or hierarchical paths
type NumberFormat ¶
type NumberFormat struct { DecimalSymbol string `json:"decimal_symbol"` DigitGroupingSymbol string `json:"digit_grouping_symbol"` }
NumberFormat describes how numbers should be parsed and formatted
type RedactionPolicy ¶
type RedactionPolicy string
const ( RedactionPolicyNone RedactionPolicy = "none" RedactionPolicyURNs RedactionPolicy = "urns" )
type TimeFormat ¶
type TimeFormat string
TimeFormat a time format string
func (TimeFormat) String ¶
func (tf TimeFormat) String() string