timeperiod

package
v0.397.5 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimePeriod

type TimePeriod struct {
	Period   string
	Value    int
	Offset   int
	Complete bool
}

func Parse

func Parse(expression string) (TimePeriod, error)

Parse will return a TimePeriodStruct from the given expression. Expressions follow the following form

  • {this/last/next} {n}? {complete}? {second(s)/minute(s)/hour(s)/day(s)/week(s)/month(s)/year(s)}
  • or one of the supported shorthand values: now/today/tomorrow/yesterday

Expression rules: * if `this`, then there is no n and no complete; i.e. `this month`, `this day`, `this year` * n = positive integer * `complete“ is optional * period can be either plural or singular version

func (*TimePeriod) IsTimezoneRelative

func (tp *TimePeriod) IsTimezoneRelative() bool

IsTimezoneRelative determines if the user's timezone would have an impact for this time period.

When handling a date relative period, such as `last complete day`/`yesterday`, this will have an impact: Given a current time of 15/11/2024 01:15 in UTC * for America/Toronto UTC -5: date_trunc('day', NOW()) should be 14/11/2024 * for Europe/Rome UTC +1: date_trunc('day', NOW()) should be 15/11/2024

Jump to

Keyboard shortcuts

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