timeext

package
v0.0.644 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TimezoneBerlin *time.Location

Functions

func AddYears

func AddYears(t time.Time, yearCount float64, tz *time.Location) time.Time

func Avg added in v0.0.585

func Avg(v ...time.Time) time.Time

func CombineDateAndTime

func CombineDateAndTime(d time.Time, t time.Time) time.Time

CombineDateAndTime returns a timestamp with the date-part (`yyyy`, `MM`, `dd`) from the d parameter and the time (`HH`, `mm`, `ss`) from the t parameter

func DaysInMonth

func DaysInMonth(t time.Time) int

func DurationFromTime

func DurationFromTime(hours int, minutes int, seconds int) time.Duration

func FloorTime

func FloorTime(t time.Time) time.Time

func FormatDurationGerman added in v0.0.576

func FormatDurationGerman(iv time.Duration) string

func FormatNaturalDurationEnglish

func FormatNaturalDurationEnglish(iv time.Duration) string

func FromDays

func FromDays[T langext.NumberConstraint](v T) time.Duration

func FromHours

func FromHours[T langext.NumberConstraint](v T) time.Duration

func FromMicroseconds

func FromMicroseconds[T langext.NumberConstraint](v T) time.Duration

func FromMilliseconds

func FromMilliseconds[T langext.NumberConstraint](v T) time.Duration

func FromMinutes

func FromMinutes[T langext.NumberConstraint](v T) time.Duration

func FromNanoseconds

func FromNanoseconds[T langext.NumberConstraint](v T) time.Duration

func FromSeconds

func FromSeconds[T langext.NumberConstraint](v T) time.Duration

func GetAggregateIsoWeekCount

func GetAggregateIsoWeekCount(year int) int

func GetGlobalWeeknumber

func GetGlobalWeeknumber(t time.Time) int

func GetIsoWeekCount

func GetIsoWeekCount(year int) int

func IsDatePartEqual

func IsDatePartEqual(a time.Time, b time.Time, tz *time.Location) bool

IsDatePartEqual returns true if a and b have the same date part (`yyyy`, `MM` and `dd`)

func IsSameDayIncludingDateBoundaries

func IsSameDayIncludingDateBoundaries(t1 time.Time, t2 time.Time, tz *time.Location) bool

IsSameDayIncludingDateBoundaries returns true if t1 and t2 are part of the same day (TZ/Berlin), the boundaries of the day are inclusive, this means 2021-09-15T00:00:00 is still part of the day 2021-09-14

func IsSunday

func IsSunday(t time.Time, tz *time.Location) bool

IsSunday returns true if t is a sunday (in TZ/Berlin)

func Max

func Max(a time.Time, b time.Time) time.Time

func Median added in v0.0.585

func Median(v ...time.Time) time.Time

func Min

func Min(a time.Time, b time.Time) time.Time

func MonthDifference

func MonthDifference(t1 time.Time, t2 time.Time) float64

MonthDifference calculates the difference between two timestamps in months. = t1 - t2 returns a float value

func MonthNameGermanLong

func MonthNameGermanLong(v time.Month) string

func MonthNameGermanShort3

func MonthNameGermanShort3(v time.Month) string

func ParseDurationShortString

func ParseDurationShortString(s string) (time.Duration, error)

ParseDurationShortString parses a duration in string format to a time.Duration Examples for allowed formats:

  • '10m'
  • '10min'
  • '1minute'
  • '10minutes'
  • '10.5minutes'
  • '50s'
  • '50sec'
  • '1second'
  • '50seconds'
  • '100ms'
  • '100millisseconds'
  • '1h'
  • '1hour'
  • '2hours'
  • '1d'
  • '1day'
  • '10days'
  • '1d10m'
  • '1d10m200sec'
  • '1d:10m'
  • '1d 10m'
  • '1d,10m'

func SubtractYears

func SubtractYears(t time.Time, yearCount float64, tz *time.Location) time.Time

func TimeToDatePart

func TimeToDatePart(t time.Time, tz *time.Location) time.Time

TimeToDatePart returns a timestamp at the start of the day which contains t (= 00:00:00)

func TimeToDayEnd

func TimeToDayEnd(t time.Time, tz *time.Location) time.Time

TimeToDayEnd returns a timestamp at the end of the day which contains t (= 23:59:59)

func TimeToDayStart

func TimeToDayStart(t time.Time, tz *time.Location) time.Time

TimeToDayStart returns a timestamp at the start of the day which contains t (= 00:00:00)

func TimeToMonthEnd

func TimeToMonthEnd(t time.Time, tz *time.Location) time.Time

TimeToMonthEnd returns a timestamp at the end of the month which contains t (= yyyy-MM-31 23:59:59.999999999)

func TimeToMonthStart

func TimeToMonthStart(t time.Time, tz *time.Location) time.Time

TimeToMonthStart returns a timestamp at the start of the month which contains t (= yyyy-MM-00 00:00:00)

func TimeToNextYearStart

func TimeToNextYearStart(t time.Time, tz *time.Location) time.Time

func TimeToWeekStart

func TimeToWeekStart(t time.Time, tz *time.Location) time.Time

TimeToWeekStart returns a timestamp at the start of the week which contains t (= Monday 00:00:00)

func TimeToYearEnd

func TimeToYearEnd(t time.Time, tz *time.Location) time.Time

TimeToYearEnd returns a timestamp at the end of the month which contains t (= yyyy-12-31 23:59:59.999999999)

func TimeToYearStart

func TimeToYearStart(t time.Time, tz *time.Location) time.Time

TimeToYearStart returns a timestamp at the start of the year which contains t (= yyyy-01-01 00:00:00)

func UnixFloatSeconds

func UnixFloatSeconds(v float64) time.Time

func WeekEnd

func WeekEnd(year, week int) time.Time

func WeekStart

func WeekStart(year, week int) time.Time

func WeekdayNameGerman

func WeekdayNameGerman(d time.Weekday) string

func WithTimePart

func WithTimePart(base time.Time, hour, minute, second int) time.Time

WithTimePart returns a timestamp with the date-part (`yyyy`, `MM`, `dd`) from base and the time (`HH`, `mm`, `ss`) from the parameter

func YearDifference

func YearDifference(t1 time.Time, t2 time.Time, tz *time.Location) float64

YearDifference calculates the difference between two timestamps in years. = t1 - t2 returns a float value

Types

type OpenTimeRange

type OpenTimeRange struct {
	From *time.Time
	To   *time.Time
}

func NewOpenTimeRange

func NewOpenTimeRange(from *time.Time, to *time.Time) *OpenTimeRange

func (*OpenTimeRange) AppendToMongoPipeline

func (r *OpenTimeRange) AppendToMongoPipeline(pipeline []any, key string) []any

func (OpenTimeRange) Contains

func (r OpenTimeRange) Contains(v time.Time) bool

func (OpenTimeRange) String

func (r OpenTimeRange) String() string

func (OpenTimeRange) ToMongoPipeline

func (r OpenTimeRange) ToMongoPipeline(key string) []any

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL