tart

package module
v0.0.0-...-bd5d453 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 8 Imported by: 0

README

TART

tart = time and relative time(in time)

Tart is a utility library to juggle go language time.Time as you might need beyond the tools provided by standard time package.

indebted to the following:

https://github.com/karrick/tparse

https://github.com/araddon/dateparse

https://github.com/wlbr/feiertage

https://github.com/olebedev/when

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HolidaysBase

func HolidaysBase(t *Tart) error

HolidaysBase ...

Types

type Config

type Config func(*Tart) error

Config is a function taking a *Tart instance.

func SetTimeFmt

func SetTimeFmt(n string) Config

SetTimeFmt ...

type Relation

type Relation interface {
	Relative(*Tart) TimeFunc
}

Relation ...

func NominalDay

func NominalDay(t *Tart, d string) Relation

NominalDay returns a Relation. The subsequent TimeFunc returned generates local date for the specified day(monday, tuesday, etc), after today, with time 00:00:00.

func NominalMonth

func NominalMonth(t *Tart, m string) Relation

NominalMonth returns a RelativeFunc returning a subsequent TimeFunc for local date for the specified month(january, february, etc), 1st day, with time 00:00:00.

type RelativeFunc

type RelativeFunc func(*Tart) TimeFunc

RelativeFunc ...

type Tart

type Tart struct {
	time.Time
	// contains filtered or unexported fields
}

Tart is a a struct encapsulating functionality related to a specific, embedded time.Time instance. An acronym for "time and relative time(in time)".

func New

func New(cnf ...Config) (*Tart, error)

New builds a new Tart instance from the provided Config.

func (*Tart) Duration

func (t *Tart) Duration(in string) time.Duration

Duration returns the duration of the modifier of a parsed directive in relation to the tart time instance. e.g. ">7d>7d>7d+1h!" ==

">7d>7d>7d+1h" ==
">7d>7d>7d+1h!<any relation>" ==
"505h" ==
(time.Duration) 505h0m0s

func (*Tart) Establish

func (t *Tart) Establish(tt time.Time)

Establish sets the time of the instance to the provided time. This forces a reset to align the instance to the new time setting all relative funcs to defaults, removing cached time funcs, and erasing any set associations.

func (*Tart) Get

func (t *Tart) Get(in string) time.Time

Get attempts to return the time of the provided directive from the Tart instance.

A directive is a string of the form `modifiers ! point in time` where:

Modifiers are one or more signs followed by duration information:

	'>' = shift forward
 '<' = shift backward
 '+' = iter next
 '-' = iter last

 'iter' and 'shift' are functionally equivalent currently, use depending on
  your preference and need

Modifiers stack. Modifiers are collected by type. Duration is applied left wise to freestanding modifiers taking duration information.

	e.g.
		">>>>>>1h"        = shift forward 6 hours
     "<1d<2d<<<<3d"    = shift backward 15 days
     "+++++1h"         = iter forward 5 hours
     "------1h"        = iter back 6 hours
     "--3h>3h"         = iter back 6 hours, shifted ahead 3 hours

Point in time is an exclamation point optionally followed by a string. Point may be a defined keyword relation or a date construction of some form. When not followed by a string, '!' means the tart instance fixed time. When not modified, the dot may be omitted, i.e absence of a concrete dot is indicative of a statement of point with no modification. A null string is equivalent to single point("" == "!")

	e.g.'
	   "!july 4 1776"     = time of july 4, 1776
    "!tuesday"         = next tuesday
    "!eoq"             = end of quarter
    "!later"           = later

Construction of a directive is dependent on the output you desire. Common use is shifting time forward or backward, iteration from a specific point, and retrieving a specific point in time from a general specification. Order of application is to establish a point in time, iterate, then shift.

Examples:

     `>>>1h.`                       = 3 hours forward from the tart instance time
     `<<<1h.`                       = 3 hours backward from the tart instance time
		`>>1h!tuesday`                 = 2 hours forward from next tuesday relative to the tart instance time
     `<<1h!tuesday`                 = 2 hours backward from next tuesday relative to the tart instance time
     `->>1h!tuesday`                = 2 hours forward from last tuesday relative to the tart instance time
     `++<<1h!tuesday`               = 2nd tuesday from now shifted back 2 hours
     `>>>>>1y!`                     = 5 years from now (where now is tart instance time)
     `+++++!`                       = 5 years from now (where now is tart instance time)
     `>>>>>1y!tuesday`              = 5 years from next tuesday
     `<<<<<1y!oct 31 2025`          = now, if today is oct 31 2020
		`>.tuesday`, `!tuesday`        = next tuesday, relative to the tart instance time
     `<!tuesday`                    = last tuesday, relative to the tart instance time
     `>>>1w!tuesday`, `>>>!tuesday` = 3rd tuesday from tart instance time
     `<<<!july 4 2006`              = july 4th 2003
     `+!july 4`, `!july 4`          = the next july 4th
     `+!christmas`, `!christmas`    = the next christmas (where christmas is defined on the tart instance)
     `!october 31 1927`             = october 31 1927
     `!october 31`                  = the next instance of october 31
     `tomorrow`,`!tomorrow`         = time tomorrow, relative to today

Unique directives are stored by key and reused within the scope of use.

func (Tart) GetRelation

func (r Tart) GetRelation(k string) Relation

GetRelation ...

func (*Tart) Set

func (t *Tart) Set(k, v string) error

Set ...

func (Tart) SetBatch

func (r Tart) SetBatch(in ...map[string]Relation) error

SetBatch ...

func (Tart) SetDirect

func (r Tart) SetDirect(k string, v time.Time) error

SetDirect ...

func (Tart) SetFloat

func (r Tart) SetFloat(k string, v float64) error

SetFloat ...

func (Tart) SetParsedDate

func (r Tart) SetParsedDate(k, v string) error

SetParsedDate ...

func (Tart) SetRelation

func (r Tart) SetRelation(k string, v Relation) error

SetRelation ...

type TimeFunc

type TimeFunc func() time.Time

TimeFunc ...

func Any

func Any(t *Tart) TimeFunc

Any returns TimeFunc that attempts to parse Tart.last to a valid time.

func EOD

func EOD(t *Tart) TimeFunc

EOD returns TimeFunc for "eod" where end of day is current local date, with time 23:59:59.

func EOM

func EOM(t *Tart) TimeFunc

EOM returns TimeFunc providing local date for the last day of the current month, with time 23:59:59.

func EOQ

func EOQ(t *Tart) TimeFunc

EOQ returns TimeFunc providing local date for the end of the current quarter (March, June, September, December), last day of the month, with time 23:59:59.

func EOW

func EOW(t *Tart) TimeFunc

EOW returns TimeFunc for local date for the end of the week, Saturday night, with time 00:00:00.

func EOWW

func EOWW(t *Tart) TimeFunc

EOWW returns TimeFunc for local date for the end of the work week, Friday night, with time 23:59:59.

func EOY

func EOY(t *Tart) TimeFunc

EOY returns TimeFunc providing local date for this year, December 31st, with time 00:00:00.

func Now

func Now(t *Tart) TimeFunc

Now returns TimeFunc for "now" from string "now" where "now" is tart.Time

func SOCM

func SOCM(t *Tart) TimeFunc

SOCM returns TimeFunc for local date for the 1st day of the current month, with time 00:00:00.

func SOCW

func SOCW(t *Tart) TimeFunc

SOCW returns TimeFunc providing local date for the last Sunday, with time 00:00:00.

func SOM

func SOM(t *Tart) TimeFunc

SOM returns TimeFunc providing local date for the 1st day of the next month, with time 00:00:00.

func SOQ

func SOQ(t *Tart) TimeFunc

SOQ returns TimeFunc providing local date for the start of the next quarter (January, April, July, October), 1st, with time 00:00:00.

func SOW

func SOW(t *Tart) TimeFunc

SOW returns TimeFunc providing local date for the next Sunday, with time 00:00:00.

func SOWW

func SOWW(t *Tart) TimeFunc

SOWW returns TimeFunc providing local date for the start of the work week, next Monday, with time 00:00:00.

func SOY

func SOY(t *Tart) TimeFunc

SOY returns TimeFunc providing local date for the next year, January 1st, with time 00:00:00.

func Today

func Today(t *Tart) TimeFunc

Today returns TimeFunc giving current local date, with time 00:00:00.

func Tomorrow

func Tomorrow(t *Tart) TimeFunc

Tomorrow returns TimeFunc for "tomorrow" as local date for tomorrow, with time 00:00:00. Same as sod(start of day).

func Whenever

func Whenever(t *Tart) TimeFunc

Whenever returns TimeFunc for "whenever", "later", "someday" mapped to local 2077-04-27, with time 14:37:00. A date far away.

func Yesterday

func Yesterday(t *Tart) TimeFunc

Yesterday returns TimeFunc giving local date for yesterday, with time 00:00:00.

Jump to

Keyboard shortcuts

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