Fix due dates with times when migrating from todoist

This commit is contained in:
kolaente 2021-02-04 21:06:01 +01:00
parent fb53322d40
commit 490ba2ea50
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 41 additions and 12 deletions

View file

@ -226,6 +226,18 @@ func (m *Migration) AuthURL() string {
"&state=" + utils.MakeRandomString(32) "&state=" + utils.MakeRandomString(32)
} }
func parseDate(dateString string) (date time.Time, err error) {
date, err = time.Parse("2006-01-02T15:04:05Z", dateString)
if err != nil {
date, err = time.Parse("2006-01-02T15:04:05", dateString)
}
if err != nil {
date, err = time.Parse("2006-01-02", dateString)
}
return date, err
}
func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.NamespaceWithLists, err error) { func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.NamespaceWithLists, err error) {
newNamespace := &models.NamespaceWithLists{ newNamespace := &models.NamespaceWithLists{
@ -299,7 +311,7 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
// Put the due date together // Put the due date together
if i.Due != nil { if i.Due != nil {
dueDate, err := time.Parse("2006-01-02", i.Due.Date) dueDate, err := parseDate(i.Due.Date)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -408,15 +420,7 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
log.Debugf("Could not find task %d for reminder %d while trying to resolve reminders", r.ItemID, r.ID) log.Debugf("Could not find task %d for reminder %d while trying to resolve reminders", r.ItemID, r.ID)
} }
var err error date, err := parseDate(r.Due.Date)
var date time.Time
date, err = time.Parse("2006-01-02T15:04:05Z", r.Due.Date)
if err != nil {
date, err = time.Parse("2006-01-02T15:04:05", r.Due.Date)
}
if err != nil {
date, err = time.Parse("2006-01-02", r.Due.Date)
}
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -42,6 +42,9 @@ func TestConvertTodoistToVikunja(t *testing.T) {
dueTime, err := time.Parse(time.RFC3339Nano, "2020-05-31T00:00:00Z") dueTime, err := time.Parse(time.RFC3339Nano, "2020-05-31T00:00:00Z")
assert.NoError(t, err) assert.NoError(t, err)
dueTime = dueTime.In(config.GetTimeZone()) dueTime = dueTime.In(config.GetTimeZone())
dueTimeWithTime, err := time.Parse(time.RFC3339Nano, "2021-01-31T19:00:00Z")
assert.NoError(t, err)
dueTimeWithTime = dueTimeWithTime.In(config.GetTimeZone())
nilTime, err := time.Parse(time.RFC3339Nano, "0001-01-01T00:00:00Z") nilTime, err := time.Parse(time.RFC3339Nano, "0001-01-01T00:00:00Z")
assert.NoError(t, err) assert.NoError(t, err)
exampleFile, err := ioutil.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg") exampleFile, err := ioutil.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg")
@ -140,7 +143,29 @@ func TestConvertTodoistToVikunja(t *testing.T) {
Checked: 0, Checked: 0,
DateAdded: time1, DateAdded: time1,
}, },
makeTestItem(400000106, 396936926, true, true, true), {
ID: 400000106,
UserID: 1855589,
ProjectID: 396936926,
Content: "Task400000106",
Priority: 1,
ParentID: 0,
ChildOrder: 1,
DateAdded: time1,
Checked: 1,
DateCompleted: time3,
Due: &dueDate{
Date: "2021-01-31T19:00:00Z",
Timezone: nil,
IsRecurring: false,
},
Labels: []int64{
80000,
80001,
80002,
80003,
},
},
makeTestItem(400000107, 396936926, false, false, true), makeTestItem(400000107, 396936926, false, false, true),
makeTestItem(400000108, 396936926, false, false, true), makeTestItem(400000108, 396936926, false, false, true),
{ {
@ -440,7 +465,7 @@ func TestConvertTodoistToVikunja(t *testing.T) {
{ {
Title: "Task400000106", Title: "Task400000106",
Done: true, Done: true,
DueDate: dueTime, DueDate: dueTimeWithTime,
Created: time1, Created: time1,
DoneAt: time3, DoneAt: time3,
Labels: vikunjaLabels, Labels: vikunjaLabels,