Return iso dates for everything date related from the api #130

Merged
konrad merged 15 commits from feature/datetime into master 2020-02-08 12:48:51 +00:00
4 changed files with 14 additions and 6 deletions
Showing only changes of commit f7d6eae956 - Show all commits

View File

@ -205,7 +205,7 @@ func makeCalDavTimeFromTimeStamp(ts timeutil.TimeStamp) (caldavtime string) {
return ts.ToTime().In(tz).Format(DateFormat)
}
func calcAlarmDateFromReminder(eventStartUnix, reminderUnix int64) (alarmTime string) {
func calcAlarmDateFromReminder(eventStartUnix, reminderUnix timeutil.TimeStamp) (alarmTime string) {
if eventStartUnix > reminderUnix {
alarmTime += `-`
}

View File

@ -17,6 +17,7 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"fmt"
"reflect"
"sort"
@ -117,6 +118,13 @@ func mustMakeComparator(fieldName string) taskComparator {
return reflect.ValueOf(task).Elem().FieldByIndex(field.Index).Interface()
}
// Special case for handling TimeStamp types
if field.Type.Name() == "TimeStamp" {
return func(lhs, rhs *Task) int64 {
return int64(extractProp(lhs).(timeutil.TimeStamp)) - int64(extractProp(rhs).(timeutil.TimeStamp))
}
}
switch field.Type.Kind() {
case reflect.Int64:
return func(lhs, rhs *Task) int64 {

View File

@ -18,6 +18,7 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"github.com/stretchr/testify/assert"
"testing"
@ -127,14 +128,14 @@ func TestUpdateDone(t *testing.T) {
oldTask := &Task{Done: false}
newTask := &Task{Done: true}
updateDone(oldTask, newTask)
assert.NotEqual(t, int64(0), oldTask.DoneAt)
assert.NotEqual(t, timeutil.TimeStamp(0), oldTask.DoneAt)
})
t.Run("unmarking a task as done", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
oldTask := &Task{Done: true}
newTask := &Task{Done: false}
updateDone(oldTask, newTask)
assert.Equal(t, int64(0), oldTask.DoneAt)
assert.Equal(t, timeutil.TimeStamp(0), oldTask.DoneAt)
})
}

View File

@ -32,8 +32,7 @@ func getCaldavTodosForTasks(list *models.List) string {
var caldavtodos []*caldav.Todo
for _, t := range list.Tasks {
durationString := t.EndDate - t.StartDate
duration, _ := time.ParseDuration(strconv.FormatInt(durationString, 10) + `s`)
duration := t.EndDate.ToTime().Sub(t.StartDate.ToTime())
caldavtodos = append(caldavtodos, &caldav.Todo{
Timestamp: t.Updated,
@ -106,7 +105,7 @@ func parseTaskFromVTODO(content string) (vTask *models.Task, err error) {
}
if duration > 0 && vTask.StartDate > 0 {
vTask.EndDate = vTask.StartDate + int64(duration.Seconds())
vTask.EndDate = timeutil.FromTime(vTask.StartDate.ToTime().Add(duration))
}
return