Fix due dates with times when migrating from todoist
This commit is contained in:
parent
fb53322d40
commit
490ba2ea50
2 changed files with 41 additions and 12 deletions
|
@ -226,6 +226,18 @@ func (m *Migration) AuthURL() string {
|
|||
"&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) {
|
||||
|
||||
newNamespace := &models.NamespaceWithLists{
|
||||
|
@ -299,7 +311,7 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
|
|||
|
||||
// Put the due date together
|
||||
if i.Due != nil {
|
||||
dueDate, err := time.Parse("2006-01-02", i.Due.Date)
|
||||
dueDate, err := parseDate(i.Due.Date)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
var err error
|
||||
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)
|
||||
}
|
||||
date, err := parseDate(r.Due.Date)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -42,6 +42,9 @@ func TestConvertTodoistToVikunja(t *testing.T) {
|
|||
dueTime, err := time.Parse(time.RFC3339Nano, "2020-05-31T00:00:00Z")
|
||||
assert.NoError(t, err)
|
||||
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")
|
||||
assert.NoError(t, err)
|
||||
exampleFile, err := ioutil.ReadFile(config.ServiceRootpath.GetString() + "/pkg/modules/migration/wunderlist/testimage.jpg")
|
||||
|
@ -140,7 +143,29 @@ func TestConvertTodoistToVikunja(t *testing.T) {
|
|||
Checked: 0,
|
||||
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(400000108, 396936926, false, false, true),
|
||||
{
|
||||
|
@ -440,7 +465,7 @@ func TestConvertTodoistToVikunja(t *testing.T) {
|
|||
{
|
||||
Title: "Task400000106",
|
||||
Done: true,
|
||||
DueDate: dueTime,
|
||||
DueDate: dueTimeWithTime,
|
||||
Created: time1,
|
||||
DoneAt: time3,
|
||||
Labels: vikunjaLabels,
|
||||
|
|
Loading…
Reference in a new issue