-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
break.go
41 lines (35 loc) · 960 Bytes
/
break.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"time"
)
func (a *app) addBreakEntry(start, end time.Time) {
entry := period{
Start: start,
End: end,
}
// Avoid duplicate breaks.
length := len(a.breaks)
if length > 0 {
lastBreak := a.breaks[length-1]
if entry.Start.Truncate(time.Minute) == lastBreak.Start.Truncate(time.Minute) {
if entry.End.After(lastBreak.End) {
a.breaks[length-1] = entry
}
} else {
a.breaks = append(a.breaks, entry)
}
} else {
a.breaks = append(a.breaks, entry)
}
fmt.Println("----------")
fmt.Printf("New break added: start = %v, end =%v , duration = %v.\n", entry.Start, entry.End, entry.duration())
fmt.Printf("string: %v\n", entry.string())
fmt.Println("current time:", time.Now())
fmt.Println("----------")
a.updateBreakMenuItems()
a.savePeriodsToStorage(breaksKey, a.breaks)
}
func (a *app) updateBreakMenuItems() {
a.breakMenuItems = updatePeriodMenuItems(a.breaks, a.mBreaks, a.breakMenuItems)
}