-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocessor.go
More file actions
41 lines (37 loc) · 893 Bytes
/
processor.go
File metadata and controls
41 lines (37 loc) · 893 Bytes
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 timewlib
import (
"time"
)
const isoLayout = "20060102T150405Z"
func parseIsoLocal(date string) (time.Time, error) {
t, err := time.Parse(isoLayout, date)
if err != nil {
return time.Time{}, err
}
return t.Local(), nil
}
func Process(rawIntervals []TimewarriorInterval) ([]Interval, error) {
var processedIntervals []Interval
for _, rawInterval := range rawIntervals {
start, err := parseIsoLocal(rawInterval.Start)
if err != nil {
return []Interval{}, err
}
var end time.Time
if rawInterval.End == "" {
end = time.Now().UTC()
} else {
end, err = parseIsoLocal(rawInterval.End)
if err != nil {
return []Interval{}, err
}
}
processedIntervals = append(processedIntervals, Interval{
start: start,
end: end,
Tags: rawInterval.Tags,
Annotation: rawInterval.Annotation,
})
}
return processedIntervals, nil
}