Migrate all timestamps to real iso dates (#594)
Fix query param name Add option to include null results when filtering Always set db time to gmt Fix null filter Fix timezone setting for todoist parsing Fix timezone setting for wunderlist parsing Fix import Fix caldav reminder parsing Use timezone from config Add error and test for invalid filter values Fix integration tests Remove task collection date hack Fix task filter Fix lint Fix tests and fixtures for date timezone stuff Properly set timezone Change fixtures time zone to gmt Set db timezone Set created and updated timestamps for all fixtures Fix lint Fix test fixtures Fix misspell Fix test fixtures Partially fix tests Remove timeutil package Remove adding _unix suffix hack Remove _unix suffix Move all timeutil.TimeStamp to time.Time Remove all Unix suffixes in field names Add better error messages when running migrations Make sure to not migrate 0 unix timestamps to 1970 iso dates Add migration script for sqlite Add converting sqlite values Convert 0 unix timestamps to null in postgres Convert 0 to null in timestamps Automatically rename _unix suffix Add all tables and columns for migration Fix sql migration query for mysql Fail with an error if trying to use an unsupported dbms Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/594
This commit is contained in:
@ -197,7 +197,7 @@ func (vcls *VikunjaCaldavListStorage) GetResource(rpath string) (*data.Resource,
|
||||
}
|
||||
|
||||
vcls.task = &task
|
||||
if updated > 0 {
|
||||
if updated.Unix() > 0 {
|
||||
vcls.task.Updated = updated
|
||||
}
|
||||
|
||||
@ -342,12 +342,12 @@ func (vlra *VikunjaListResourceAdapter) CalculateEtag() string {
|
||||
|
||||
// Return the etag of a task if we have one
|
||||
if vlra.task != nil {
|
||||
return `"` + strconv.FormatInt(vlra.task.ID, 10) + `-` + strconv.FormatInt(vlra.task.Updated.ToTime().Unix(), 10) + `"`
|
||||
return `"` + strconv.FormatInt(vlra.task.ID, 10) + `-` + strconv.FormatInt(vlra.task.Updated.Unix(), 10) + `"`
|
||||
}
|
||||
// This also returns the etag of the list, and not of the task,
|
||||
// which becomes problematic because the client uses this etag (= the one from the list) to make
|
||||
// Requests to update a task. These do not match and thus updating a task fails.
|
||||
return `"` + strconv.FormatInt(vlra.list.ID, 10) + `-` + strconv.FormatInt(vlra.list.Updated.ToTime().Unix(), 10) + `"`
|
||||
return `"` + strconv.FormatInt(vlra.list.ID, 10) + `-` + strconv.FormatInt(vlra.list.Updated.Unix(), 10) + `"`
|
||||
}
|
||||
|
||||
// GetContent returns the content string of a resource (a task in our case)
|
||||
@ -372,11 +372,11 @@ func (vlra *VikunjaListResourceAdapter) GetContentSize() int64 {
|
||||
// GetModTime returns when the resource was last modified
|
||||
func (vlra *VikunjaListResourceAdapter) GetModTime() time.Time {
|
||||
if vlra.task != nil {
|
||||
return time.Unix(vlra.task.Updated.ToTime().Unix(), 0)
|
||||
return vlra.task.Updated
|
||||
}
|
||||
|
||||
if vlra.list != nil {
|
||||
return time.Unix(vlra.list.Updated.ToTime().Unix(), 0)
|
||||
return vlra.list.Updated
|
||||
}
|
||||
|
||||
return time.Time{}
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"code.vikunja.io/api/pkg/caldav"
|
||||
"code.vikunja.io/api/pkg/log"
|
||||
"code.vikunja.io/api/pkg/models"
|
||||
"code.vikunja.io/api/pkg/timeutil"
|
||||
"github.com/laurent22/ical-go"
|
||||
"strconv"
|
||||
"time"
|
||||
@ -32,7 +31,7 @@ func getCaldavTodosForTasks(list *models.List) string {
|
||||
var caldavtodos []*caldav.Todo
|
||||
for _, t := range list.Tasks {
|
||||
|
||||
duration := t.EndDate.ToTime().Sub(t.StartDate.ToTime())
|
||||
duration := t.EndDate.Sub(t.StartDate)
|
||||
|
||||
caldavtodos = append(caldavtodos, &caldav.Todo{
|
||||
Timestamp: t.Updated,
|
||||
@ -104,22 +103,22 @@ func parseTaskFromVTODO(content string) (vTask *models.Task, err error) {
|
||||
vTask.Done = true
|
||||
}
|
||||
|
||||
if duration > 0 && vTask.StartDate > 0 {
|
||||
vTask.EndDate = timeutil.FromTime(vTask.StartDate.ToTime().Add(duration))
|
||||
if duration > 0 && !vTask.StartDate.IsZero() {
|
||||
vTask.EndDate = vTask.StartDate.Add(duration)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func caldavTimeToTimestamp(tstring string) timeutil.TimeStamp {
|
||||
func caldavTimeToTimestamp(tstring string) time.Time {
|
||||
if tstring == "" {
|
||||
return 0
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
t, err := time.Parse(caldav.DateFormat, tstring)
|
||||
if err != nil {
|
||||
log.Warningf("Error while parsing caldav time %s to TimeStamp: %s", tstring, err)
|
||||
return 0
|
||||
return time.Time{}
|
||||
}
|
||||
return timeutil.FromTime(t)
|
||||
return t
|
||||
}
|
||||
|
Reference in New Issue
Block a user