fix(taskwarrior): parsing and convertion of times and contents

This commit is contained in:
2023-10-22 12:32:53 +02:00
parent ce2a4769c9
commit 5764a32f02
5 changed files with 103 additions and 26 deletions

View File

@@ -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
}