08205008e7
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
124 lines
3.2 KiB
Go
124 lines
3.2 KiB
Go
// Vikunja is a to-do list application to facilitate your life.
|
|
// Copyright 2018-2020 Vikunja and contributors. All rights reserved.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
package caldav
|
|
|
|
import (
|
|
"code.vikunja.io/api/pkg/caldav"
|
|
"code.vikunja.io/api/pkg/log"
|
|
"code.vikunja.io/api/pkg/models"
|
|
"github.com/laurent22/ical-go"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func getCaldavTodosForTasks(list *models.List) string {
|
|
|
|
// Make caldav todos from Vikunja todos
|
|
var caldavtodos []*caldav.Todo
|
|
for _, t := range list.Tasks {
|
|
|
|
duration := t.EndDate.Sub(t.StartDate)
|
|
|
|
caldavtodos = append(caldavtodos, &caldav.Todo{
|
|
Timestamp: t.Updated,
|
|
UID: t.UID,
|
|
Summary: t.Title,
|
|
Description: t.Description,
|
|
Completed: t.DoneAt,
|
|
// Organizer: &t.CreatedBy, // Disabled until we figure out how this works
|
|
Priority: t.Priority,
|
|
Start: t.StartDate,
|
|
End: t.EndDate,
|
|
Created: t.Created,
|
|
Updated: t.Updated,
|
|
DueDate: t.DueDate,
|
|
Duration: duration,
|
|
})
|
|
}
|
|
|
|
caldavConfig := &caldav.Config{
|
|
Name: list.Title,
|
|
ProdID: "Vikunja Todo App",
|
|
}
|
|
|
|
return caldav.ParseTodos(caldavConfig, caldavtodos)
|
|
}
|
|
|
|
func parseTaskFromVTODO(content string) (vTask *models.Task, err error) {
|
|
parsed, err := ical.ParseCalendar(content)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// We put the task details in a map to be able to handle them more easily
|
|
task := make(map[string]string)
|
|
for _, c := range parsed.Children {
|
|
if c.Name == "VTODO" {
|
|
for _, entry := range c.Children {
|
|
task[entry.Name] = entry.Value
|
|
}
|
|
// Breaking, to only process the first task
|
|
break
|
|
}
|
|
}
|
|
|
|
// Parse the UID
|
|
var priority int64
|
|
if _, ok := task["PRIORITY"]; ok {
|
|
priority, err = strconv.ParseInt(task["PRIORITY"], 10, 64)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
// Parse the enddate
|
|
duration, _ := time.ParseDuration(task["DURATION"])
|
|
|
|
vTask = &models.Task{
|
|
UID: task["UID"],
|
|
Title: task["SUMMARY"],
|
|
Description: task["DESCRIPTION"],
|
|
Priority: priority,
|
|
DueDate: caldavTimeToTimestamp(task["DUE"]),
|
|
Updated: caldavTimeToTimestamp(task["DTSTAMP"]),
|
|
StartDate: caldavTimeToTimestamp(task["DTSTART"]),
|
|
DoneAt: caldavTimeToTimestamp(task["COMPLETED"]),
|
|
}
|
|
|
|
if task["STATUS"] == "COMPLETED" {
|
|
vTask.Done = true
|
|
}
|
|
|
|
if duration > 0 && !vTask.StartDate.IsZero() {
|
|
vTask.EndDate = vTask.StartDate.Add(duration)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func caldavTimeToTimestamp(tstring string) time.Time {
|
|
if tstring == "" {
|
|
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 time.Time{}
|
|
}
|
|
return t
|
|
}
|