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 TimeFromString(str string) (dates.TimeOfDay, error)
- func ToGoDateFormat(format string, mode FormattingMode) (string, 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) WithDefaultLanguage(defaultLanguage Language) *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 FormattingMode
- type Language
- 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
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 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 TimeFromString ¶
TimeFromString returns a time of day constructed from the passed in string, or an error if we are unable to extract one
func ToGoDateFormat ¶
func ToGoDateFormat(format string, mode FormattingMode) (string, error)
ToGoDateFormat converts the passed in format to a GoLang format string.
If mode is DateOnlyFormatting or DateTimeFormatting, the following sequences are accepted:
`YY` - last two digits of year 0-99 `YYYY` - four digits of your 0000-9999 `M` - month 1-12 `MM` - month 01-12 `D` - day of month, 1-31 `DD` - day of month, zero padded 0-31
If mode is TimeOnlyFormatting or DateTimeFormatting, the following sequences are accepted:
`h` - hour of the day 1-12 `hh` - hour of the day 01-12 `tt` - twenty four hour of the day 01-23 `m` - minute 0-59 `mm` - minute 00-59 `s` - second 0-59 `ss` - second 00-59 `fff` - milliseconds `ffffff` - microseconds `fffffffff` - nanoseconds `aa` - am or pm `AA` - AM or PM `Z` - hour and minute offset from UTC, or Z for UTC `ZZZ` - hour and minute offset from UTC
ignored chars: ' ', ':', ',', 'T', '-', '_', '/'
Types ¶
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 DefaultLanguage() Language AllowedLanguages() []Language DefaultCountry() Country NumberFormat() *NumberFormat RedactionPolicy() RedactionPolicy MaxValueLength() int // 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) WithDefaultLanguage ¶
func (b *EnvironmentBuilder) WithDefaultLanguage(defaultLanguage Language) *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 FormattingMode ¶
type FormattingMode int
FormattingMode describe a mode of formatting dates, times, datetimes
const ( DateOnlyFormatting FormattingMode = iota TimeOnlyFormatting DateTimeFormatting )
supported formatting modes
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 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