Documentation ¶
Index ¶
- Constants
- func AddDay(t time.Time, add int, loc *time.Location) time.Time
- func AllSwitch(int, *Switch) bool
- func AnyTask(sw *Switch) bool
- func HMSF(d time.Duration) (h, m, s int, f float64)
- func Infinite(d time.Duration) bool
- func IsATask(t *Task) func(*Switch) bool
- func LastDay(wd time.Weekday, from time.Time, loc *time.Location) time.Time
- func NextDay(wd time.Weekday, from time.Time, loc *time.Location) time.Time
- func NonNilTask(_ int, sw *Switch) bool
- func SameTask(t *Task) func(*Switch) bool
- func StartDay(t time.Time, add int, loc *time.Location) time.Time
- func StartMonth(t time.Time, add int, loc *time.Location) time.Time
- func Warning(n Note) bool
- func Write(w io.Writer, tl TimeLine) error
- type Clock
- type Date
- type Note
- type SelectSwitch
- type Switch
- func (s *Switch) AddNote(text string) (i int)
- func (s *Switch) AddWarning(sym rune, text string) (i int)
- func (s *Switch) DelNote(i int)
- func (s *Switch) Duration() time.Duration
- func (s *Switch) FilterNotes(f func(Note) bool)
- func (s *Switch) Next() *Switch
- func (s *Switch) Notes() []Note
- func (s *Switch) SelectNotes(idxs []int, f func(Note) bool) []int
- func (s *Switch) Task() *Task
- func (s *Switch) When() time.Time
- type Task
- func (t *Task) Find(tip bool, path ...string) *Task
- func (t *Task) FindString(p string) *Task
- func (t *Task) Get(path ...string) (*Task, error)
- func (t *Task) GetString(p string) (*Task, error)
- func (t *Task) Is(in *Task) bool
- func (t *Task) Match(tip bool, pattern ...string) (matches []*Task, err error)
- func (t *Task) MatchString(p string) ([]*Task, error)
- func (t *Task) Name() string
- func (t *Task) Path() []string
- func (t *Task) Root() *Task
- func (t *Task) SetTitle(s string)
- func (t *Task) String() string
- func (t *Task) Subtasks() []*Task
- func (t *Task) Title() string
- func (t *Task) Visit(pre bool, do func(*Task) error) error
- type TimeLine
- func (tl *TimeLine) Clip(start, end time.Time)
- func (tl *TimeLine) ClipAfter(t time.Time)
- func (tl *TimeLine) ClipBefore(t time.Time)
- func (tl *TimeLine) Del(at time.Time, pre, post SelectSwitch)
- func (tl *TimeLine) DelSwitch(i int) error
- func (tl TimeLine) Duration(from, to, now time.Time, f func(*Switch) bool) (d time.Duration, s, e time.Time)
- func (tl TimeLine) FirstTask() *Task
- func (tl *TimeLine) Insert(at time.Time, to *Task, dtPast time.Duration, swPast SelectSwitch, ...) int
- func (ts TimeLine) Pick(t time.Time) (int, *Switch)
- func (tl *TimeLine) Reschedule(i int, to time.Time) error
- func (tl TimeLine) RootTask() *Task
- func (tl *TimeLine) Switch(at time.Time, to *Task) int
Examples ¶
Constants ¶
View Source
const ( FileVersion = "1.0.0" IOTimeFmt = time.RFC3339 )
Variables ¶
This section is empty.
Functions ¶
func AddDay ¶
Example ¶
t := time.Date(1999, time.June, 25, 12, 33, 9, 0, time.UTC) fmt.Println(AddDay(t, 1, nil)) fmt.Println(AddDay(t, 10, nil)) fmt.Println(AddDay(t, -25, nil))
Output: 1999-06-26 12:33:09 +0000 UTC 1999-07-05 12:33:09 +0000 UTC 1999-05-31 12:33:09 +0000 UTC
func LastDay ¶
LastDay returns Time from shifted to the last Weekday wd not after from.
Example ¶
t := time.Date(1999, time.June, 25, 12, 33, 9, 0, time.UTC) fmt.Println(LastDay(time.Friday, t, nil)) fmt.Println(LastDay(time.Monday, t, nil)) fmt.Println(LastDay(time.Sunday, t, nil)) fmt.Println(LastDay(time.Saturday, t, nil))
Output: 1999-06-25 12:33:09 +0000 UTC 1999-06-21 12:33:09 +0000 UTC 1999-06-20 12:33:09 +0000 UTC 1999-06-19 12:33:09 +0000 UTC
func NextDay ¶
NextDay returns Time from shifted to the next Weekday wd after from.
Example ¶
t := time.Date(1999, time.June, 25, 12, 33, 9, 0, time.UTC) fmt.Println(NextDay(time.Sunday, t, nil)) fmt.Println(NextDay(time.Monday, t, nil)) fmt.Println(NextDay(time.Friday, t, nil))
Output: 1999-06-27 12:33:09 +0000 UTC 1999-06-28 12:33:09 +0000 UTC 1999-07-02 12:33:09 +0000 UTC
func NonNilTask ¶ added in v0.3.1
func StartDay ¶
Example ¶
t := time.Date(1999, time.June, 25, 12, 33, 9, 345876, time.UTC) fmt.Println(StartDay(t, 0, nil)) fmt.Println(StartDay(t, -1, nil)) fmt.Println(StartDay(t, 1, nil))
Output: 1999-06-25 00:00:00 +0000 UTC 1999-06-24 00:00:00 +0000 UTC 1999-06-26 00:00:00 +0000 UTC
func StartMonth ¶
Example ¶
t := time.Date(1999, time.June, 25, 12, 33, 9, 4711, time.UTC) fmt.Println(StartMonth(t, 0, nil)) fmt.Println(StartMonth(t, -1, nil)) fmt.Println(StartMonth(t, 1, nil))
Output: 1999-06-01 00:00:00 +0000 UTC 1999-05-01 00:00:00 +0000 UTC 1999-07-01 00:00:00 +0000 UTC
Types ¶
type SelectSwitch ¶ added in v0.3.1
type Switch ¶
type Switch struct {
// contains filtered or unexported fields
}
func (*Switch) AddWarning ¶ added in v0.3.0
func (*Switch) FilterNotes ¶ added in v0.3.0
func (*Switch) SelectNotes ¶ added in v0.3.0
type Task ¶
type Task struct {
// contains filtered or unexported fields
}
func (*Task) FindString ¶
type TimeLine ¶
type TimeLine []*Switch
Example ¶
root := new(Task) var tl TimeLine show := func(i int) { sw := tl[i] fmt.Printf("%d %s %s", i, sw.When(), sw.Task()) if n := sw.Next(); n != nil { fmt.Printf(" > %s", n.Task()) } fmt.Println() } t := time.Date(2023, time.April, 1, 12, 0, 0, 0, time.UTC) show(tl.Switch(t, catch.MustRet(root.Get("1")))) show(tl.Switch(t.Add(time.Hour), catch.MustRet(root.Get("2")))) show(tl.Switch(t.Add(-time.Hour), catch.MustRet(root.Get("3")))) show(tl.Switch(t.Add(-30*time.Minute), catch.MustRet(root.Get("4")))) show(tl.Switch(t.Add(30*time.Minute), catch.MustRet(root.Get("5"))))
Output: 0 2023-04-01 12:00:00 +0000 UTC /1 1 2023-04-01 13:00:00 +0000 UTC /2 0 2023-04-01 11:00:00 +0000 UTC /3 > /1 1 2023-04-01 11:30:00 +0000 UTC /4 > /1 3 2023-04-01 12:30:00 +0000 UTC /5 > /2
func Read ¶
Example ¶
ts, err := Read(strings.NewReader(`/3 Just to test titles # Sat, 01 Apr 2023 2023-04-01T12:00:00Z /1 2023-04-01T13:00:00Z /2 . A note 2023-04-01T11:00:00Z /3 !? A warning with the question symbol '?' 2023-04-01T11:30:00Z /4 2023-04-01T12:30:00Z /5`), nil) if err != nil { fmt.Println(err) return } Write(os.Stdout, ts)
Output: v1.0.0 tiktak time tracker /1 /2 /3 Just to test titles /4 /5 # Sat, 01 Apr 2023 2023-04-01T11:00:00Z /3 !? A warning with the question symbol '?' 2023-04-01T11:30:00Z /4 2023-04-01T12:00:00Z /1 2023-04-01T12:30:00Z /5 2023-04-01T13:00:00Z /2 . A note
func (*TimeLine) ClipBefore ¶
func (*TimeLine) Del ¶
func (tl *TimeLine) Del(at time.Time, pre, post SelectSwitch)
If at == start & pre != nil && post == nil => shift the past
func (TimeLine) Duration ¶
func (tl TimeLine) Duration(from, to, now time.Time, f func(*Switch) bool) (d time.Duration, s, e time.Time)
Duration computes the sum of durations of all time line switches filtered by f. If now switch was considered, s will be zero. Otherwise it is the time of the first switch.
Example ¶
root := new(Task) var tl TimeLine t := time.Date(2023, time.April, 1, 12, 0, 0, 0, time.UTC) tl.Switch(t, root) var d time.Duration var s, e time.Time print := func(name string) { fmt.Print(name, ": ", d) if s.IsZero() { fmt.Print(" -") } else { fmt.Print(" ", s.Format(time.TimeOnly)) } if e.IsZero() { fmt.Print(" -") } else { fmt.Print(" ", e.Format(time.TimeOnly)) } fmt.Println() } now := t.Add(20 * time.Minute) d, s, e = tl.Duration(t.Add(-time.Hour), t.Add(-30*time.Minute), now, AnyTask) print("open/before") d, s, e = tl.Duration(t.Add(-30*time.Minute), t, now, AnyTask) print("open/touch") d, s, e = tl.Duration(t.Add(-15*time.Minute), t.Add(15*time.Minute), now, AnyTask) print("open/x-start") d, s, e = tl.Duration(t, t.Add(30*time.Minute), now, AnyTask) print("open/at-start") d, s, e = tl.Duration(t, t.Add(30*time.Minute), t.Add(-10*time.Minute), AnyTask) print("open/future") d, s, e = tl.Duration(t.Add(15*time.Minute), t.Add(45*time.Minute), now, AnyTask) print("open/after") tl.Switch(t.Add(30*time.Minute), nil) d, s, e = tl.Duration(t.Add(-time.Hour), t.Add(-30*time.Minute), now, AnyTask) print("within/before") d, s, e = tl.Duration(t.Add(-30*time.Minute), t, now, AnyTask) print("within/touch") d, s, e = tl.Duration(t.Add(-15*time.Minute), t.Add(15*time.Minute), now, AnyTask) print("within/x-start") d, s, e = tl.Duration(t, t.Add(30*time.Minute), now, AnyTask) print("within/at-start") d, s, e = tl.Duration(t, t.Add(30*time.Minute), t.Add(-10*time.Minute), AnyTask) print("within/future") d, s, e = tl.Duration(t.Add(15*time.Minute), t.Add(45*time.Minute), now, AnyTask) print("within/after") now = t.Add(40 * time.Minute) d, s, e = tl.Duration(t.Add(-time.Hour), t.Add(-30*time.Minute), now, AnyTask) print("after/before") d, s, e = tl.Duration(t.Add(-30*time.Minute), t, now, AnyTask) print("after/touch") d, s, e = tl.Duration(t.Add(-15*time.Minute), t.Add(15*time.Minute), now, AnyTask) print("after/x-start") d, s, e = tl.Duration(t, t.Add(30*time.Minute), now, AnyTask) print("after/at-start") d, s, e = tl.Duration(t, t.Add(30*time.Minute), t.Add(-10*time.Minute), AnyTask) print("after/future") d, s, e = tl.Duration(t.Add(15*time.Minute), t.Add(45*time.Minute), now, AnyTask) print("after/after")
Output: open/before: 0s - - open/touch: 0s - - open/x-start: 15m0s 12:00:00 - open/at-start: 20m0s 12:00:00 - open/future: -10m0s 12:00:00 - open/after: 5m0s 12:15:00 - within/before: 0s - - within/touch: 0s - - within/x-start: 15m0s 12:00:00 12:15:00 within/at-start: 30m0s 12:00:00 12:30:00 within/future: 30m0s 12:00:00 12:30:00 within/after: 15m0s 12:15:00 12:30:00 after/before: 0s - - after/touch: 0s - - after/x-start: 15m0s 12:00:00 12:15:00 after/at-start: 30m0s 12:00:00 12:30:00 after/future: 30m0s 12:00:00 12:30:00 after/after: 15m0s 12:15:00 12:30:00
Click to show internal directories.
Click to hide internal directories.