fix: importing tasks from todoist without a due time set

Resolves #897
This commit is contained in:
kolaente 2021-11-23 22:29:53 +01:00
parent 86480ad969
commit fd0d462bf4
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 11 additions and 2 deletions

View file

@ -241,6 +241,15 @@ func (m *Migration) AuthURL() string {
} }
func parseDate(dateString string) (date time.Time, err error) { 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) date, err = time.Parse("2006-01-02T15:04:05Z", dateString)
if err != nil { if err != nil {
date, err = time.Parse("2006-01-02T15:04:05", dateString) date, err = time.Parse("2006-01-02T15:04:05", dateString)

View file

@ -39,7 +39,7 @@ func TestConvertTodoistToVikunja(t *testing.T) {
time3, err := time.Parse(time.RFC3339Nano, "2014-10-21T08:25:05Z") time3, err := time.Parse(time.RFC3339Nano, "2014-10-21T08:25:05Z")
assert.NoError(t, err) assert.NoError(t, err)
time3 = time3.In(config.GetTimeZone()) 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) 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") dueTimeWithTime, err := time.Parse(time.RFC3339Nano, "2021-01-31T19:00:00Z")
@ -401,7 +401,7 @@ func TestConvertTodoistToVikunja(t *testing.T) {
Done: false, Done: false,
Created: time1, Created: time1,
Reminders: []time.Time{ 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()), time.Date(2020, time.June, 16, 7, 0, 0, 0, time.UTC).In(config.GetTimeZone()),
}, },
}, },