From fd0d462bf4dd8225c67ba34958e5148f6167d264 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 23 Nov 2021 22:29:53 +0100 Subject: [PATCH] fix: importing tasks from todoist without a due time set Resolves #897 --- pkg/modules/migration/todoist/todoist.go | 9 +++++++++ pkg/modules/migration/todoist/todoist_test.go | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/modules/migration/todoist/todoist.go b/pkg/modules/migration/todoist/todoist.go index e56dfd2e8..90548ff69 100644 --- a/pkg/modules/migration/todoist/todoist.go +++ b/pkg/modules/migration/todoist/todoist.go @@ -241,6 +241,15 @@ func (m *Migration) AuthURL() string { } func parseDate(dateString string) (date time.Time, err error) { + if len(dateString) == 10 { + // We're probably dealing with a date in the form of 2021-11-23 without a time + date, err = time.Parse("2006-01-02", dateString) + if err == nil { + // round the day to eod + return date.Add(time.Hour*23 + time.Minute*59), nil + } + } + date, err = time.Parse("2006-01-02T15:04:05Z", dateString) if err != nil { date, err = time.Parse("2006-01-02T15:04:05", dateString) diff --git a/pkg/modules/migration/todoist/todoist_test.go b/pkg/modules/migration/todoist/todoist_test.go index 24fa48b00..3b815280a 100644 --- a/pkg/modules/migration/todoist/todoist_test.go +++ b/pkg/modules/migration/todoist/todoist_test.go @@ -39,7 +39,7 @@ func TestConvertTodoistToVikunja(t *testing.T) { time3, err := time.Parse(time.RFC3339Nano, "2014-10-21T08:25:05Z") assert.NoError(t, err) time3 = time3.In(config.GetTimeZone()) - dueTime, err := time.Parse(time.RFC3339Nano, "2020-05-31T00:00:00Z") + dueTime, err := time.Parse(time.RFC3339Nano, "2020-05-31T23:59:00Z") assert.NoError(t, err) dueTime = dueTime.In(config.GetTimeZone()) dueTimeWithTime, err := time.Parse(time.RFC3339Nano, "2021-01-31T19:00:00Z") @@ -401,7 +401,7 @@ func TestConvertTodoistToVikunja(t *testing.T) { Done: false, Created: time1, Reminders: []time.Time{ - time.Date(2020, time.June, 15, 0, 0, 0, 0, time.UTC).In(config.GetTimeZone()), + time.Date(2020, time.June, 15, 23, 59, 0, 0, time.UTC).In(config.GetTimeZone()), time.Date(2020, time.June, 16, 7, 0, 0, 0, time.UTC).In(config.GetTimeZone()), }, },