Documentation ¶
Index ¶
- type DateTimeParser
- func (service DateTimeParser) DaysAgo(numDays int) (time.Time, error)
- func (service DateTimeParser) GetUTCLocation() *time.Location
- func (service DateTimeParser) IsDateOlderThanNumDaysAgo(t time.Time, numDays int) bool
- func (service DateTimeParser) NowUTC() time.Time
- func (service DateTimeParser) Parse(dateString string) (time.Time, error)
- func (service DateTimeParser) ParseDateTime(dateString string) time.Time
- func (service DateTimeParser) ParseISO8601(dateString string) time.Time
- func (service DateTimeParser) ParseISO8601SqlUtc(dateString string) time.Time
- func (service DateTimeParser) ParseShortDate(dateString string) time.Time
- func (service DateTimeParser) ParseUSDate(dateString string) time.Time
- func (service DateTimeParser) ParseUSDateTime(dateString string) time.Time
- func (service DateTimeParser) Pretty(t time.Time) string
- func (service DateTimeParser) ToISO8601(t time.Time) string
- func (service DateTimeParser) ToSQLString(t time.Time) string
- func (service DateTimeParser) ToUSDate(t time.Time) string
- func (service DateTimeParser) ToUSDateTime(t time.Time) string
- func (service DateTimeParser) ToUSTime(t time.Time) string
- func (service DateTimeParser) ValidDateTime(dateString string) bool
- func (service DateTimeParser) ValidISO8601(dateString string) bool
- func (service DateTimeParser) ValidISO8601SqlUtc(dateString string) bool
- func (service DateTimeParser) ValidShortDate(dateString string) bool
- func (service DateTimeParser) ValidUSDate(dateString string) bool
- func (service DateTimeParser) ValidUSDateTime(dateString string) bool
- type IDateTimeParser
- type MockDateTimeParser
- func (m MockDateTimeParser) DaysAgo(numDays int) (time.Time, error)
- func (m MockDateTimeParser) GetUTCLocation() *time.Location
- func (m MockDateTimeParser) IsDateOlderThanNumDaysAgo(t time.Time, numDays int) bool
- func (m MockDateTimeParser) NowUTC() time.Time
- func (m MockDateTimeParser) Parse(dateString string) (time.Time, error)
- func (m MockDateTimeParser) ParseDateTime(dateString string) time.Time
- func (m MockDateTimeParser) ParseISO8601(dateString string) time.Time
- func (m MockDateTimeParser) ParseISO8601SqlUtc(dateString string) time.Time
- func (m MockDateTimeParser) ParseShortDate(dateString string) time.Time
- func (m MockDateTimeParser) ParseUSDateTime(dateString string) time.Time
- func (m MockDateTimeParser) Pretty(t time.Time) string
- func (m MockDateTimeParser) ToISO8601(t time.Time) string
- func (m MockDateTimeParser) ToSQLString(t time.Time) string
- func (m MockDateTimeParser) ToUSDate(t time.Time) string
- func (m MockDateTimeParser) ToUSDateTime(t time.Time) string
- func (m MockDateTimeParser) ToUSTime(t time.Time) string
- func (m MockDateTimeParser) ValidDateTime(dateString string) bool
- func (m MockDateTimeParser) ValidISO8601(dateString string) bool
- func (m MockDateTimeParser) ValidISO8601SqlUtc(dateString string) bool
- func (m MockDateTimeParser) ValidShortDate(dateString string) bool
- func (m MockDateTimeParser) ValidUSDateTime(dateString string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DateTimeParser ¶
type DateTimeParser struct{}
DateTimeParser provides methods for parsing and formatting dates
func (DateTimeParser) DaysAgo ¶
func (service DateTimeParser) DaysAgo(numDays int) (time.Time, error)
DaysAgo returns the current date minus the number of specified days
func (DateTimeParser) GetUTCLocation ¶
func (service DateTimeParser) GetUTCLocation() *time.Location
GetUTCLocation returns location information for the UTC timezone
func (DateTimeParser) IsDateOlderThanNumDaysAgo ¶
func (service DateTimeParser) IsDateOlderThanNumDaysAgo(t time.Time, numDays int) bool
IsDateOlderThanNumDaysAgo returns true if the provided date is older than today minus the specified number of days. All times are UTC
func (DateTimeParser) NowUTC ¶
func (service DateTimeParser) NowUTC() time.Time
NowUTC returns the current date/time in UTC
func (DateTimeParser) Parse ¶
func (service DateTimeParser) Parse(dateString string) (time.Time, error)
Parse is a general purposes method for parsing a date string. This will attempt to parse the string in the following formats:
- SQL (with full milliseconds and UTC indicator)
- SQL (YYYY-MM-DDTHH:MM:SS)
- Short Date (YYYY-MM-DD)
- US Date/Time (MM/DD/YYYY H:MM A)
func (DateTimeParser) ParseDateTime ¶
func (service DateTimeParser) ParseDateTime(dateString string) time.Time
ParseDateTime parses a string as a basic SQL date YYYY-MM-DDTHH:MM:SS
func (DateTimeParser) ParseISO8601 ¶
func (service DateTimeParser) ParseISO8601(dateString string) time.Time
ParseISO8601 parses a string as an ISO 8601 format YYYY-MM-DDTHH:MM:SS-07:00. The string must have the timezone indicated as an offset.
func (DateTimeParser) ParseISO8601SqlUtc ¶
func (service DateTimeParser) ParseISO8601SqlUtc(dateString string) time.Time
ParseISO8601SqlUtc parses a string in SQL format with milliseconds and the UTC indicator YYYY-MM-DDTHH:MM:SS.000Z
func (DateTimeParser) ParseShortDate ¶
func (service DateTimeParser) ParseShortDate(dateString string) time.Time
ParseShortDate parses a short date YYYY-MM-DD
func (DateTimeParser) ParseUSDate ¶
func (service DateTimeParser) ParseUSDate(dateString string) time.Time
ParseUSDate parses a standard US date MM/DD/YYYY
func (DateTimeParser) ParseUSDateTime ¶
func (service DateTimeParser) ParseUSDateTime(dateString string) time.Time
ParseUSDateTime parses a standard US date/time MM/DD/YYYY H:MM A
func (DateTimeParser) Pretty ¶
func (service DateTimeParser) Pretty(t time.Time) string
Pretty returns a date/time formatted Jan 1 2010 at H:MMAM
func (DateTimeParser) ToISO8601 ¶
func (service DateTimeParser) ToISO8601(t time.Time) string
ToISO8601 formats a time as YYYY-MM-DDTHH:MM:SS-07:00, using an offset to indicate timezone
func (DateTimeParser) ToSQLString ¶
func (service DateTimeParser) ToSQLString(t time.Time) string
ToSQLString formats a time as YYYY-MM-DD HH:MM:SS. This is useful for inserting into a database
func (DateTimeParser) ToUSDate ¶
func (service DateTimeParser) ToUSDate(t time.Time) string
ToUSDate formats a time as MM/DD/YYYY
func (DateTimeParser) ToUSDateTime ¶
func (service DateTimeParser) ToUSDateTime(t time.Time) string
ToUSDateTime formats a time as MM/DD/YYYY H:MM AM
func (DateTimeParser) ToUSTime ¶
func (service DateTimeParser) ToUSTime(t time.Time) string
ToUSTime formats a time as H:MM AM
func (DateTimeParser) ValidDateTime ¶
func (service DateTimeParser) ValidDateTime(dateString string) bool
ValidDateTime returns true if the string is YYYY-MM-DDTHH:MM:SS
func (DateTimeParser) ValidISO8601 ¶
func (service DateTimeParser) ValidISO8601(dateString string) bool
ValidISO8601 returns true if the string is YYYY-MM-DDTHH:MM:SS-07:00
func (DateTimeParser) ValidISO8601SqlUtc ¶
func (service DateTimeParser) ValidISO8601SqlUtc(dateString string) bool
ValidISO8601SqlUtc returns true if the string is YYYY-MM-DDTHH:MM:SS.000Z
func (DateTimeParser) ValidShortDate ¶
func (service DateTimeParser) ValidShortDate(dateString string) bool
ValidShortDate returns true if the string is YYYY-MM-DD
func (DateTimeParser) ValidUSDate ¶
func (service DateTimeParser) ValidUSDate(dateString string) bool
ValidUSDate returns true if the string is MM/DD/YYYY
func (DateTimeParser) ValidUSDateTime ¶
func (service DateTimeParser) ValidUSDateTime(dateString string) bool
ValidUSDateTime returns true if the string is MM/DD/YYYY H:MM AM
type IDateTimeParser ¶
type IDateTimeParser interface { DaysAgo(numDays int) (time.Time, error) GetUTCLocation() *time.Location NowUTC() time.Time IsDateOlderThanNumDaysAgo(t time.Time, numDays int) bool Parse(dateString string) (time.Time, error) ParseDateTime(dateString string) time.Time ParseISO8601(dateString string) time.Time ParseISO8601SqlUtc(dateString string) time.Time ParseShortDate(dateString string) time.Time ParseUSDateTime(dateString string) time.Time ParseUSDate(dateString string) time.Time Pretty(t time.Time) string ToISO8601(t time.Time) string ToSQLString(t time.Time) string ToUSDate(t time.Time) string ToUSDateTime(t time.Time) string ToUSTime(t time.Time) string ValidDateTime(dateString string) bool ValidISO8601(dateString string) bool ValidShortDate(dateString string) bool ValidISO8601SqlUtc(dateString string) bool ValidUSDateTime(dateString string) bool ValidUSDate(dateString string) bool }
IDateTimeParser is an interface describing methods that parse and format dates and times
type MockDateTimeParser ¶
type MockDateTimeParser struct { DaysAgoFunc func(numDays int) (time.Time, error) GetUTCLocationFunc func() *time.Location NowUTCFunc func() time.Time IsDateOlderThanNumDaysAgoFunc func(t time.Time, numDays int) bool ParseFunc func(dateString string) (time.Time, error) ParseDateTimeFunc func(dateString string) time.Time ParseISO8601Func func(dateString string) time.Time ParseISO8601SqlUtcFunc func(dateString string) time.Time ParseShortDateFunc func(dateString string) time.Time ParseUSDateTimeFunc func(dateString string) time.Time PrettyFunc func(t time.Time) string ToISO8601Func func(t time.Time) string ToSQLStringFunc func(t time.Time) string ToUSDateFunc func(t time.Time) string ToUSDateTimeFunc func(t time.Time) string ToUSTimeFunc func(t time.Time) string ValidDateTimeFunc func(dateString string) bool ValidISO8601Func func(dateString string) bool ValidShortDateFunc func(dateString string) bool ValidISO8601SqlUtcFunc func(dateString string) bool ValidUSDateTimeFunc func(dateString string) bool }
func (MockDateTimeParser) DaysAgo ¶
func (m MockDateTimeParser) DaysAgo(numDays int) (time.Time, error)
func (MockDateTimeParser) GetUTCLocation ¶
func (m MockDateTimeParser) GetUTCLocation() *time.Location
func (MockDateTimeParser) IsDateOlderThanNumDaysAgo ¶
func (m MockDateTimeParser) IsDateOlderThanNumDaysAgo(t time.Time, numDays int) bool
func (MockDateTimeParser) NowUTC ¶
func (m MockDateTimeParser) NowUTC() time.Time
func (MockDateTimeParser) Parse ¶
func (m MockDateTimeParser) Parse(dateString string) (time.Time, error)
func (MockDateTimeParser) ParseDateTime ¶
func (m MockDateTimeParser) ParseDateTime(dateString string) time.Time
func (MockDateTimeParser) ParseISO8601 ¶
func (m MockDateTimeParser) ParseISO8601(dateString string) time.Time
func (MockDateTimeParser) ParseISO8601SqlUtc ¶
func (m MockDateTimeParser) ParseISO8601SqlUtc(dateString string) time.Time
func (MockDateTimeParser) ParseShortDate ¶
func (m MockDateTimeParser) ParseShortDate(dateString string) time.Time
func (MockDateTimeParser) ParseUSDateTime ¶
func (m MockDateTimeParser) ParseUSDateTime(dateString string) time.Time
func (MockDateTimeParser) ToSQLString ¶
func (m MockDateTimeParser) ToSQLString(t time.Time) string
func (MockDateTimeParser) ToUSDateTime ¶
func (m MockDateTimeParser) ToUSDateTime(t time.Time) string
func (MockDateTimeParser) ValidDateTime ¶
func (m MockDateTimeParser) ValidDateTime(dateString string) bool
func (MockDateTimeParser) ValidISO8601 ¶
func (m MockDateTimeParser) ValidISO8601(dateString string) bool
func (MockDateTimeParser) ValidISO8601SqlUtc ¶
func (m MockDateTimeParser) ValidISO8601SqlUtc(dateString string) bool
func (MockDateTimeParser) ValidShortDate ¶
func (m MockDateTimeParser) ValidShortDate(dateString string) bool
func (MockDateTimeParser) ValidUSDateTime ¶
func (m MockDateTimeParser) ValidUSDateTime(dateString string) bool