fix(taskwarrior): parsing and convertion of times and contents
This commit is contained in:
@@ -59,7 +59,6 @@ func NewTask(description string, project string, git_id uint, git_type Type, tag
|
||||
}
|
||||
|
||||
func TaskTimeToGoTime(t string) time.Time {
|
||||
// TODO: apply required changes to the string for correct parsing
|
||||
splits := strings.Split(t, "T")
|
||||
if len(t) == 0 {
|
||||
return time.UnixMicro(0)
|
||||
@@ -78,6 +77,7 @@ func TaskTimeToGoTime(t string) time.Time {
|
||||
second = timestamp[2:4]
|
||||
third = timestamp[4 : len(timestamp)-1]
|
||||
timestamp = strings.Join([]string{first, second, third}, ":")
|
||||
// TODO: identify current timezone and use correct format string (works for Europe/Berlin)
|
||||
value := fmt.Sprintf("%sT%s+02:00", date, timestamp)
|
||||
result, err := time.Parse(time.RFC3339, value)
|
||||
if err != nil {
|
||||
@@ -88,13 +88,9 @@ func TaskTimeToGoTime(t string) time.Time {
|
||||
}
|
||||
|
||||
func GoTimeToTaskTime(t time.Time) string {
|
||||
result := t.Format(time.RFC3339)
|
||||
// TODO: apply changes to the result
|
||||
// go: 2023-10-10T19:57:22+02:00
|
||||
// task: 20231010T195722Z
|
||||
result := t.In(time.UTC).Format(time.RFC3339)
|
||||
result = strings.Replace(result, "-", "", 2)
|
||||
result = strings.Replace(result, ":", "", 2)
|
||||
result = strings.ReplaceAll(result, "+02:00", "Z")
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1,18 @@
|
||||
package taskwarrior
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTimeCoversions(t *testing.T) {
|
||||
current_time := time.Now()
|
||||
task_current_time := GoTimeToTaskTime(current_time)
|
||||
go_current_time := TaskTimeToGoTime(task_current_time)
|
||||
task_current_time = GoTimeToTaskTime(go_current_time)
|
||||
current_time = TaskTimeToGoTime(task_current_time)
|
||||
|
||||
if current_time.Compare(go_current_time) != 0 {
|
||||
t.Fatalf("conversion failed: Expected: `%s` but got: `%s`", current_time.String(), go_current_time.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user