Add reminders for overdue tasks (#832)

Co-authored-by: kolaente <k@knt.li>
Reviewed-on: https://kolaente.dev/vikunja/api/pulls/832
Co-authored-by: konrad <konrad@kola-entertainments.de>
Co-committed-by: konrad <konrad@kola-entertainments.de>
This commit is contained in:
konrad 2021-04-11 15:08:43 +00:00
parent b3c604fd2f
commit d07b284ee3
20 changed files with 992 additions and 428 deletions

View file

@ -346,3 +346,12 @@
index: 2
created: 2018-12-01 01:12:04
updated: 2018-12-01 01:12:04
- id: 38
title: 'task #37 done with due date'
done: true
created_by_id: 1
list_id: 22
index: 2
created: 2018-12-01 01:12:04
updated: 2018-12-01 01:12:04
due_date: 2018-10-30 22:25:24

View file

@ -93,6 +93,7 @@ func FullInit() {
// Start the cron
cron.Init()
models.RegisterReminderCron()
models.RegisterOverdueReminderCron()
// Start processing events
go func() {

View file

@ -0,0 +1,43 @@
// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-2021 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 Affero General Public Licensee 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 Affero General Public Licensee for more details.
//
// You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package migration
import (
"src.techknowlogick.com/xormigrate"
"xorm.io/xorm"
)
type users20210411161337 struct {
OverdueTasksRemindersEnabled bool `xorm:"bool default true index" json:"-"`
}
func (users20210411161337) TableName() string {
return "users"
}
func init() {
migrations = append(migrations, &xormigrate.Migration{
ID: "20210411161337",
Description: "Add overdue notifications enabled setting to users",
Migrate: func(tx *xorm.Engine) error {
return tx.Sync2(users20210411161337{})
},
Rollback: func(tx *xorm.Engine) error {
return nil
},
})
}

View file

@ -74,6 +74,7 @@ func TestLabelTask_ReadAll(t *testing.T) {
Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.",
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
},

View file

@ -54,6 +54,7 @@ func TestLabel_ReadAll(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -103,6 +104,7 @@ func TestLabel_ReadAll(t *testing.T) {
Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.",
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
},
@ -167,6 +169,7 @@ func TestLabel_ReadOne(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -227,6 +230,7 @@ func TestLabel_ReadOne(t *testing.T) {
Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.",
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
},

View file

@ -183,6 +183,7 @@ func TestListUser_ReadAll(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
},
@ -195,6 +196,7 @@ func TestListUser_ReadAll(t *testing.T) {
Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.",
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
},

View file

@ -182,6 +182,7 @@ func TestNamespaceUser_ReadAll(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
},
@ -194,6 +195,7 @@ func TestNamespaceUser_ReadAll(t *testing.T) {
Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.",
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
},

View file

@ -20,6 +20,7 @@ import (
"bufio"
"strconv"
"strings"
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/notifications"
@ -184,3 +185,29 @@ func (n *TeamMemberAddedNotification) ToDB() interface{} {
func (n *TeamMemberAddedNotification) Name() string {
return "team.member.added"
}
// UndoneTaskOverdueNotification represents a UndoneTaskOverdueNotification notification
type UndoneTaskOverdueNotification struct {
User *user.User
Task *Task
}
// ToMail returns the mail notification for UndoneTaskOverdueNotification
func (n *UndoneTaskOverdueNotification) ToMail() *notifications.Mail {
return notifications.NewMail().
Subject(`Task "`+n.Task.Title+`" is overdue`).
Greeting("Hi "+n.User.GetName()+",").
Line(`This is a friendly reminder of the task "`+n.Task.Title+`" which is overdue since `+time.Until(n.Task.DueDate).String()+` and not yet done.`).
Action("Open Task", config.ServiceFrontendurl.GetString()+"tasks/"+strconv.FormatInt(n.Task.ID, 10)).
Line("Have a nice day!")
}
// ToDB returns the UndoneTaskOverdueNotification notification in a format which can be saved in the db
func (n *UndoneTaskOverdueNotification) ToDB() interface{} {
return nil
}
// Name returns the name of the notification
func (n *UndoneTaskOverdueNotification) Name() string {
return "task.undone.overdue"
}

View file

@ -37,6 +37,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -46,6 +47,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.",
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -56,6 +58,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Issuer: "local",
IsActive: true,
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}

View file

@ -0,0 +1,99 @@
// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-2021 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 Affero General Public Licensee 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 Affero General Public Licensee for more details.
//
// You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package models
import (
"time"
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/cron"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/notifications"
"code.vikunja.io/api/pkg/utils"
"xorm.io/builder"
"xorm.io/xorm"
)
func getUndoneOverdueTasks(s *xorm.Session, now time.Time) (taskIDs []int64, err error) {
now = utils.GetTimeWithoutNanoSeconds(now)
var tasks []*Task
err = s.
Where("due_date is not null and due_date < ?", now.Format(dbTimeFormat)).
And("done = false").
Find(&tasks)
if err != nil {
return
}
for _, task := range tasks {
taskIDs = append(taskIDs, task.ID)
}
return
}
// RegisterOverdueReminderCron registers a function which checks once a day for tasks that are overdue and not done.
func RegisterOverdueReminderCron() {
if !config.ServiceEnableEmailReminders.GetBool() {
return
}
if !config.MailerEnabled.GetBool() {
log.Info("Mailer is disabled, not sending overdue per mail")
return
}
err := cron.Schedule("0 8 * * *", func() {
s := db.NewSession()
defer s.Close()
now := time.Now()
taskIDs, err := getUndoneOverdueTasks(s, now)
if err != nil {
log.Errorf("[Undone Overdue Tasks Reminder] Could not get tasks with reminders in the next minute: %s", err)
return
}
users, err := getTaskUsersForTasks(s, taskIDs, builder.Eq{"users.overdue_tasks_reminders_enabled": true})
if err != nil {
log.Errorf("[Undone Overdue Tasks Reminder] Could not get task users to send them reminders: %s", err)
return
}
log.Debugf("[Undone Overdue Tasks Reminder] Sending reminders to %d users", len(users))
for _, u := range users {
n := &UndoneTaskOverdueNotification{
User: u.User,
Task: u.Task,
}
err = notifications.Notify(u.User, n)
if err != nil {
log.Errorf("[Undone Overdue Tasks Reminder] Could not notify user %d: %s", u.User.ID, err)
return
}
log.Debugf("[Undone Overdue Tasks Reminder] Sent reminder email for task %d to user %d", u.Task.ID, u.User.ID)
}
})
if err != nil {
log.Fatalf("Could not register undone overdue tasks reminder cron: %s", err)
}
}

View file

@ -0,0 +1,62 @@
// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-2021 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 Affero General Public Licensee 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 Affero General Public Licensee for more details.
//
// You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package models
import (
"testing"
"time"
"code.vikunja.io/api/pkg/db"
"github.com/stretchr/testify/assert"
)
func TestGetUndoneOverDueTasks(t *testing.T) {
t.Run("no undone tasks", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
now, err := time.Parse(time.RFC3339Nano, "2018-01-01T01:13:00Z")
assert.NoError(t, err)
taskIDs, err := getUndoneOverdueTasks(s, now)
assert.NoError(t, err)
assert.Len(t, taskIDs, 0)
})
t.Run("undone overdue", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
now, err := time.Parse(time.RFC3339Nano, "2018-12-01T01:13:00Z")
assert.NoError(t, err)
taskIDs, err := getUndoneOverdueTasks(s, now)
assert.NoError(t, err)
assert.Len(t, taskIDs, 1)
assert.Equal(t, int64(6), taskIDs[0])
})
t.Run("done overdue", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
now, err := time.Parse(time.RFC3339Nano, "2018-11-01T01:13:00Z")
assert.NoError(t, err)
taskIDs, err := getUndoneOverdueTasks(s, now)
assert.NoError(t, err)
assert.Len(t, taskIDs, 0)
})
}

View file

@ -19,6 +19,9 @@ package models
import (
"time"
"code.vikunja.io/api/pkg/utils"
"xorm.io/builder"
"code.vikunja.io/api/pkg/notifications"
"code.vikunja.io/api/pkg/db"
@ -48,7 +51,9 @@ type taskUser struct {
User *user.User `xorm:"extends"`
}
func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUser, err error) {
const dbTimeFormat = `2006-01-02 15:04:05`
func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64, cond builder.Cond) (taskUsers []*taskUser, err error) {
if len(taskIDs) == 0 {
return
}
@ -59,7 +64,7 @@ func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUs
Select("users.id, users.username, users.email, users.name").
Join("LEFT", "tasks", "tasks.created_by_id = users.id").
In("tasks.id", taskIDs).
Where("users.email_reminders_enabled = true").
Where(cond).
GroupBy("tasks.id, users.id, users.username, users.email, users.name").
Find(&creators)
if err != nil {
@ -84,15 +89,18 @@ func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUs
})
}
assignees, err := getRawTaskAssigneesForTasks(s, taskIDs)
var assignees []*TaskAssigneeWithUser
err = s.Table("task_assignees").
Select("task_id, users.*").
In("task_id", taskIDs).
Join("INNER", "users", "task_assignees.user_id = users.id").
Where(cond).
Find(&assignees)
if err != nil {
return
}
for _, assignee := range assignees {
if !assignee.EmailRemindersEnabled { // Can't filter that through a query directly since we're using another function
continue
}
taskUsers = append(taskUsers, &taskUser{
Task: taskMap[assignee.TaskID],
User: &assignee.User,
@ -103,13 +111,8 @@ func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUs
}
func getTasksWithRemindersInTheNextMinute(s *xorm.Session, now time.Time) (taskIDs []int64, err error) {
now = utils.GetTimeWithoutNanoSeconds(now)
tz := config.GetTimeZone()
const dbFormat = `2006-01-02 15:04:05`
// By default, time.Now() includes nanoseconds which we don't save. That results in getting the wrong dates,
// so we make sure the time we use to get the reminders don't contain nanoseconds.
now = time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), 0, 0, now.Location()).In(tz)
nextMinute := now.Add(1 * time.Minute)
log.Debugf("[Task Reminder Cron] Looking for reminders between %s and %s to send...", now, nextMinute)
@ -117,7 +120,7 @@ func getTasksWithRemindersInTheNextMinute(s *xorm.Session, now time.Time) (taskI
reminders := []*TaskReminder{}
err = s.
Join("INNER", "tasks", "tasks.id = task_reminders.task_id").
Where("reminder >= ? and reminder < ?", now.Format(dbFormat), nextMinute.Format(dbFormat)).
Where("reminder >= ? and reminder < ?", now.Format(dbTimeFormat), nextMinute.Format(dbTimeFormat)).
And("tasks.done = false").
Find(&reminders)
if err != nil {
@ -154,9 +157,9 @@ func RegisterReminderCron() {
log.Debugf("[Task Reminder Cron] Timezone is %s", tz)
s := db.NewSession()
err := cron.Schedule("* * * * *", func() {
s := db.NewSession()
defer s.Close()
now := time.Now()
taskIDs, err := getTasksWithRemindersInTheNextMinute(s, now)
@ -169,7 +172,7 @@ func RegisterReminderCron() {
return
}
users, err := getTaskUsersForTasks(s, taskIDs)
users, err := getTaskUsersForTasks(s, taskIDs, builder.Eq{"users.email_reminders_enabled": true})
if err != nil {
log.Errorf("[Task Reminder Cron] Could not get task users to send them reminders: %s", err)
return

View file

@ -32,6 +32,7 @@ func TestListUsersFromList(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -41,6 +42,7 @@ func TestListUsersFromList(t *testing.T) {
Password: "$2a$14$dcadBoMBL9jQoOcZK8Fju.cy0Ptx2oZECkKLnaa8ekRoTFe1w7To.",
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -51,6 +53,7 @@ func TestListUsersFromList(t *testing.T) {
PasswordResetToken: "passwordresettesttoken",
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -62,6 +65,7 @@ func TestListUsersFromList(t *testing.T) {
EmailConfirmToken: "tiepiQueed8ahc7zeeFe1eveiy4Ein8osooxegiephauph2Ael",
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -73,6 +77,7 @@ func TestListUsersFromList(t *testing.T) {
EmailConfirmToken: "tiepiQueed8ahc7zeeFe1eveiy4Ein8osooxegiephauph2Ael",
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -83,6 +88,7 @@ func TestListUsersFromList(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -94,6 +100,7 @@ func TestListUsersFromList(t *testing.T) {
Issuer: "local",
EmailRemindersEnabled: true,
DiscoverableByEmail: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -104,6 +111,7 @@ func TestListUsersFromList(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -114,6 +122,7 @@ func TestListUsersFromList(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -124,6 +133,7 @@ func TestListUsersFromList(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -135,6 +145,7 @@ func TestListUsersFromList(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -147,6 +158,7 @@ func TestListUsersFromList(t *testing.T) {
Issuer: "local",
EmailRemindersEnabled: true,
DiscoverableByName: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}
@ -157,6 +169,7 @@ func TestListUsersFromList(t *testing.T) {
IsActive: true,
Issuer: "local",
EmailRemindersEnabled: true,
OverdueTasksRemindersEnabled: true,
Created: testCreatedTime,
Updated: testUpdatedTime,
}

View file

@ -43,6 +43,8 @@ type UserSettings struct {
DiscoverableByName bool `json:"discoverable_by_name"`
// If true, the user can be found when searching for their exact email.
DiscoverableByEmail bool `json:"discoverable_by_email"`
// If enabled, the user will get an email for their overdue tasks each morning.
OverdueTasksRemindersEnabled bool `json:"overdue_tasks_reminders_enabled"`
}
// GetUserAvatarProvider returns the currently set user avatar
@ -167,6 +169,7 @@ func UpdateGeneralUserSettings(c echo.Context) error {
user.EmailRemindersEnabled = us.EmailRemindersEnabled
user.DiscoverableByEmail = us.DiscoverableByEmail
user.DiscoverableByName = us.DiscoverableByName
user.OverdueTasksRemindersEnabled = us.OverdueTasksRemindersEnabled
_, err = user2.UpdateUser(s, user)
if err != nil {

View file

@ -67,6 +67,7 @@ func UserShow(c echo.Context) error {
EmailRemindersEnabled: u.EmailRemindersEnabled,
DiscoverableByName: u.DiscoverableByName,
DiscoverableByEmail: u.DiscoverableByEmail,
OverdueTasksRemindersEnabled: u.OverdueTasksRemindersEnabled,
},
}

View file

@ -8570,6 +8570,10 @@ var doc = `{
"name": {
"description": "The new name of the current user.",
"type": "string"
},
"overdue_tasks_reminders_enabled": {
"description": "If enabled, the user will get an email for their overdue tasks each morning.",
"type": "boolean"
}
}
},

View file

@ -8553,6 +8553,10 @@
"name": {
"description": "The new name of the current user.",
"type": "string"
},
"overdue_tasks_reminders_enabled": {
"description": "If enabled, the user will get an email for their overdue tasks each morning.",
"type": "boolean"
}
}
},

File diff suppressed because it is too large Load diff

View file

@ -67,11 +67,10 @@ type User struct {
Issuer string `xorm:"text null" json:"-"`
Subject string `xorm:"text null" json:"-"`
// If enabled, sends email reminders of tasks to the user.
EmailRemindersEnabled bool `xorm:"bool default true" json:"-"`
DiscoverableByName bool `xorm:"bool default false index" json:"-"`
DiscoverableByEmail bool `xorm:"bool default false index" json:"-"`
OverdueTasksRemindersEnabled bool `xorm:"bool default true index" json:"-"`
// A timestamp when this task was created. You cannot change this value.
Created time.Time `xorm:"created not null" json:"created"`
@ -371,6 +370,7 @@ func UpdateUser(s *xorm.Session, user *User) (updatedUser *User, err error) {
"email_reminders_enabled",
"discoverable_by_name",
"discoverable_by_email",
"overdue_tasks_reminders_enabled",
).
Update(user)
if err != nil {

32
pkg/utils/time.go Normal file
View file

@ -0,0 +1,32 @@
// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-2021 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 Affero General Public Licensee 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 Affero General Public Licensee for more details.
//
// You should have received a copy of the GNU Affero General Public Licensee
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package utils
import (
"time"
"code.vikunja.io/api/pkg/config"
)
// GetTimeWithoutNanoSeconds returns a time.Time without the nanoseconds.
func GetTimeWithoutNanoSeconds(t time.Time) time.Time {
tz := config.GetTimeZone()
// By default, time.Now() includes nanoseconds which we don't save. That results in getting the wrong dates,
// so we make sure the time we use to get the reminders don't contain nanoseconds.
return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), 0, t.Location()).In(tz)
}