Documentation ¶
Index ¶
- Constants
- Variables
- func AddMonthAndYearToTime(t time.Time, months, years int) time.Time
- func ChangedPartsOfDate(t time.Time, y int, m time.Month, d int) time.Time
- func ChangedPartsOfTime(t time.Time, h, m, s, ns int) time.Time
- func DaysInMonth(month time.Month, year int) int
- func DaysSince2000FromTime(t time.Time) int
- func DurSeconds(d time.Duration) float64
- func DurationFromString(str string) time.Duration
- func DurationToVerbal(d time.Duration, useSecs bool) string
- func Equal(a, b time.Time) bool
- func GetDurNice(d time.Duration, fractDigits int) string
- func GetDurationAsHMSString(duration time.Duration, hours, mins, secs bool, subdigits int) string
- func GetDurationHourMinSec(d time.Duration) (hours int, mins int, secs int, fract float64)
- func GetDurationString(d time.Duration, secs, mins, hours bool, subDigits int) (str string, overflow bool)
- func GetHourAndAM(t time.Time) (hour int, am bool)
- func GetNice(t time.Time, secs bool) string
- func GetNiceSubSecs(t time.Time, subSecs int) string
- func GetSecsFromHMSString(str string, hour, min, sec bool) (float64, error)
- func GetShort(t time.Time) string
- func GetStartOfDay(t time.Time) time.Time
- func GetStartOfToday() time.Time
- func GetTimeWithServerLocation(t time.Time) time.Time
- func IsBigTime(t time.Time) bool
- func IsSameDay(a, b time.Time) bool
- func IsToday(t time.Time) bool
- func Max(a, b time.Time) time.Time
- func Maximize(t *time.Time, with time.Time)
- func Min(a, b time.Time) time.Time
- func Minimize(t *time.Time, with time.Time)
- func Minutes(m int) time.Duration
- func MonthFromString(str string) (time.Month, bool)
- func MustParse(s string) time.Time
- func OnTheNextHour(t time.Time) time.Time
- func ParseISO8601(str string) (t time.Time, e error)
- func ReplaceOldUnixTimeZoneNamesWithNew(name string) string
- func SecondsDur(s float64) time.Duration
- func Since(t time.Time) float64
- func TimeOfDaysSince2000(days int, loc *time.Location) time.Time
- func TimeToNearestEmojii(t time.Time) rune
- func TimeToX(minX, maxX float64, t, start, end time.Time) float64
- func TimeZoneNameFromHourOffset(offset float32) string
- func WithIntegerSeconds(t time.Time) time.Time
- func XToTime(minX, maxX float64, x float64, start, end time.Time) time.Time
- type Differ
- type DurationStruct
- type EpochTime
- type FieldInc
- type JSONTime
- type SQLTime
- type TimeFieldFlags
Constants ¶
const ( ISO8601Format = "2006-01-02T15:04:05-0700" ISO8601NoZoneFormat = "2006-01-02T15:04:05" ISO8601DateFormat = "2006-01-02" ShortFormat = "2006-01-02 15:04" JavascriptFormat = "2006-01-02T15:04:05-07:00" JavascriptFormatWithSub = "2006-01-02T15:04:05.999-07:00" JavascriptISO = "2006-01-02T15:04:05.999Z" FullCompact = "06-Jan-02T15:04:05.9" NiceFormat = "15:04:05 02-Jan-2006" // MaxSize of GetNice() RFC3339NoZ = "2006-01-02T15:04:05-07:00" Day = time.Hour * time.Duration(24) Week = Day * time.Duration(7) )
Variables ¶
var ( Distant = time.Unix(1<<62, 0) BigTime = time.Date(2200, 12, 20, 0, 0, 0, 0, time.UTC) // time.Duration can max handle 290 years, so better than 3000. Setting to December 20th, so it is easily distinguishable from zero time TestTime = MustParse("2020-05-17T10:30:45.0+02:00") // Random time we can use in tests when it has to look normal and be a fixed time ServerTimezoneOffsetSecs int SundayFirstWeekdays = []time.Weekday{time.Sunday, time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday} Weekdays = []time.Weekday{time.Monday, time.Tuesday, time.Wednesday, time.Thursday, time.Friday, time.Saturday, time.Sunday} )
Distant is a very far-future time when you want to do things forever etc
var ISODurRegEx = regexp.MustCompile(`P((?P<year>\d+)Y)?((?P<month>\d+)M)?((?P<day>\d+)D)?(T((?P<hour>\d+)H)?((?P<minute>\d+)M)?((?P<second>[\d\.]+)S)?)?`)
Functions ¶
func AddMonthAndYearToTime ¶
AddMonthAndYearToTime adds months and years to a date. It increases/decreases month-count, not using 30 days. If the results day of year is outside current month it is truncated.
func ChangedPartsOfDate ¶
ChangedPartsOfDate changes the year, month or day part of a time Only non -1 parts changed.
func ChangedPartsOfTime ¶
ChangedPartsOfTime changes the hour, minute second or nanosecond part of a time Only non -1 parts changed.
func DaysInMonth ¶
DaysInMonth returns the number of days in a month for a given year
func DaysSince2000FromTime ¶
func DurSeconds ¶
func DurationFromString ¶
func GetDurationAsHMSString ¶
func GetDurationHourMinSec ¶
func GetDurationString ¶
func GetNiceSubSecs ¶
GetNiceSubSecs is like GetNice, but adds seconds is subSecs >= 0, and sub-second decimals if > 0
func GetSecsFromHMSString ¶
func GetStartOfToday ¶
func MustParse ¶
MustParse is ued to parse a RFC3339Nano time from string, typically for using in literals.
func SecondsDur ¶
func TimeToNearestEmojii ¶
Types ¶
type DurationStruct ¶
type DurationStruct struct { Years int Weeks int Months int Days int Hours int Minutes int Seconds float32 }
func DurationStructFromISO ¶
func DurationStructFromISO(dur string) (DurationStruct, error)
DurationStructFromISO reads an ISO 8601 dduration string.
func (DurationStruct) ToDuration ¶
func (d DurationStruct) ToDuration() time.Duration
type FieldInc ¶
type FieldInc struct { Field TimeFieldFlags Step int }
func NiceAxisIncrements ¶
func NiceAxisIncrements(start, stop time.Time, pixelLength int) (inc time.Duration, labelInc FieldInc, first time.Time)
NiceAxisIncrements returns a FieldInc for the smallest duration to increment ticks or markings. The increment is returned as a Field in seconds, minutes or hours and a step rather than just a single duration, to alow further choices to be made.
type JSONTime ¶
func (*JSONTime) UnmarshalJSON ¶
type TimeFieldFlags ¶
type TimeFieldFlags int
const ( TimeFieldNone TimeFieldFlags = 1 << iota TimeFieldSecs TimeFieldMins TimeFieldHours TimeFieldDays TimeFieldMonths TimeFieldYears TimeFieldAMPM TimeFieldDateOnly TimeFieldTimeOnly TimeFieldNoCalendar TimeFieldShortYear TimeFieldStatic TimeFieldNotFutureIfAmbiguous // day, month, year are not present, subtract 1 to make it in past if current makes it future )
func ParseDate ¶
func ParseDate(date string, location *time.Location, flags TimeFieldFlags) (t time.Time, faults []TimeFieldFlags, err error)
func (TimeFieldFlags) Duration ¶
func (f TimeFieldFlags) Duration() time.Duration
func (TimeFieldFlags) FieldValue ¶
func (f TimeFieldFlags) FieldValue(t time.Time) int
func (TimeFieldFlags) String ¶
func (f TimeFieldFlags) String() string