Browse Source

Fix timezone offset, fix last worklog of the day already processed

master
Riyyi 5 months ago
parent
commit
cd3ca50a22
  1. 7
      src/api.go
  2. 7
      src/process.go

7
src/api.go

@ -25,7 +25,7 @@ func (api) CallApi(date string, from_time string, to_time string, item_id string
if item_id == "break" || item_id == "lunch" || item_id == "pauze" { return nil }
if date == "" || from_time == "" || to_time == "" || item_id == "" {
return fmt.Error("incomplete log entry: %s, %s-%s, %s, %s", date, from_time, to_time, item_id, description)
return fmt.Errorf("incomplete log entry: %s, %s-%s, %s, %s", date, from_time, to_time, item_id, description)
}
time1, err := time.Parse("15:04", from_time)
@ -34,6 +34,11 @@ func (api) CallApi(date string, from_time string, to_time string, item_id string
time2, err := time.Parse("15:04", to_time)
if err != nil { return fmt.Errorf("error parsing to_time: %s", err) }
// Convert local timezone to UTC time
_, offset := time.Now().Zone()
time1.Add(-time.Duration(offset) * time.Second);
time2.Add(-time.Duration(offset) * time.Second);
duration := time2.Sub(time1)
seconds := int(duration.Seconds())
if seconds < 0 { return fmt.Errorf("from_time is later than to_time: %s > %s", from_time, to_time) }

7
src/process.go

@ -19,6 +19,7 @@ type Date struct {
last_time string
last_item_id string
last_description string
last_was_processed bool
}
type Process struct {
@ -84,7 +85,7 @@ func (self *Process) parseTask(line string, line_number int) error {
}
// Call API for the previous task
if date.last_time != "" && date.last_item_id != "" {
if !date.last_was_processed && date.last_time != "" && date.last_item_id != "" {
err = Api.CallApi(data[0], date.last_time, data[1], date.last_item_id, date.last_description)
}
@ -95,10 +96,12 @@ func (self *Process) parseTask(line string, line_number int) error {
date.last_time = data[1]
date.last_item_id = data[2]
date.last_description = data[4]
date.last_was_processed = false
} else { // "V", task is already processed
date.last_time = ""
date.last_item_id = ""
date.last_description = ""
date.last_was_processed = true
}
self.dates[data[0]] = date
@ -114,7 +117,7 @@ func (self *Process) parseClockOut(line string, line_number int) error {
date.clock_out = data[2]
self.dates[data[0]] = date
if date.last_time == "" || date.last_item_id == "" || date.last_description == "" {
if !date.last_was_processed && date.last_time == "" || date.last_item_id == "" {
return errors.New("no previous task to use clock-out on")
}

Loading…
Cancel
Save