Move all timeutil.TimeStamp to time.Time

This commit is contained in:
kolaente 2020-06-26 17:29:29 +02:00
parent 01c2b57950
commit e34ebfdee9
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
45 changed files with 348 additions and 381 deletions

View File

@ -17,7 +17,6 @@
package caldav
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils"
"fmt"
@ -35,37 +34,37 @@ type Event struct {
UID string
Alarms []Alarm
Timestamp timeutil.TimeStamp
Start timeutil.TimeStamp
End timeutil.TimeStamp
Timestamp time.Time
Start time.Time
End time.Time
}
// Todo holds a single VTODO
type Todo struct {
// Required
Timestamp timeutil.TimeStamp
Timestamp time.Time
UID string
// Optional
Summary string
Description string
Completed timeutil.TimeStamp
Completed time.Time
Organizer *user.User
Priority int64 // 0-9, 1 is highest
RelatedToUID string
Start timeutil.TimeStamp
End timeutil.TimeStamp
DueDate timeutil.TimeStamp
Start time.Time
End time.Time
DueDate time.Time
Duration time.Duration
Created timeutil.TimeStamp
Updated timeutil.TimeStamp // last-mod
Created time.Time
Updated time.Time // last-mod
}
// Alarm holds infos about an alarm from a caldav event
type Alarm struct {
Time timeutil.TimeStamp
Time time.Time
Description string
}
@ -141,11 +140,11 @@ UID:` + t.UID + `
DTSTAMP:` + makeCalDavTimeFromTimeStamp(t.Timestamp) + `
SUMMARY:` + t.Summary
if t.Start != 0 {
if t.Start.Unix() > 0 {
caldavtodos += `
DTSTART: ` + makeCalDavTimeFromTimeStamp(t.Start)
}
if t.End != 0 {
if t.End.Unix() > 0 {
caldavtodos += `
DTEND: ` + makeCalDavTimeFromTimeStamp(t.End)
}
@ -153,7 +152,7 @@ DTEND: ` + makeCalDavTimeFromTimeStamp(t.End)
caldavtodos += `
DESCRIPTION:` + t.Description
}
if t.Completed != 0 {
if t.Completed.Unix() > 0 {
caldavtodos += `
COMPLETED: ` + makeCalDavTimeFromTimeStamp(t.Completed)
}
@ -167,12 +166,12 @@ ORGANIZER;CN=:` + t.Organizer.Username
RELATED-TO:` + t.RelatedToUID
}
if t.DueDate != 0 {
if t.DueDate.Unix() > 0 {
caldavtodos += `
DUE:` + makeCalDavTimeFromTimeStamp(t.DueDate)
}
if t.Created != 0 {
if t.Created.Unix() > 0 {
caldavtodos += `
CREATED:` + makeCalDavTimeFromTimeStamp(t.Created)
}
@ -200,20 +199,15 @@ END:VCALENDAR` // Need a line break
return
}
func makeCalDavTimeFromTimeStamp(ts timeutil.TimeStamp) (caldavtime string) {
func makeCalDavTimeFromTimeStamp(ts time.Time) (caldavtime string) {
tz, _ := time.LoadLocation("UTC")
return ts.ToTime().In(tz).Format(DateFormat)
return ts.In(tz).Format(DateFormat)
}
func calcAlarmDateFromReminder(eventStart, reminder timeutil.TimeStamp) (alarmTime string) {
if eventStart > reminder {
func calcAlarmDateFromReminder(eventStart, reminder time.Time) (alarmTime string) {
if reminder.Sub(eventStart) < 0 {
alarmTime += `-`
}
alarmTime += `PT`
diff := eventStart - reminder
if diff < 0 { // Make it positive
diff = diff * -1
}
alarmTime += strconv.Itoa(int(diff/60)) + "M"
alarmTime += `PT` + (eventStart.Sub(reminder) * time.Minute).String() + "M"
return
}

View File

@ -18,7 +18,6 @@ package files
import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/web"
"github.com/c2h5oh/datasize"
"github.com/spf13/afero"
@ -34,10 +33,8 @@ type File struct {
Mime string `xorm:"text null" json:"mime"`
Size uint64 `xorm:"int(11) not null" json:"size"`
Created time.Time `xorm:"-" json:"created"`
Created timeutil.TimeStamp `xorm:"created" json:"-"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
Created time.Time `xorm:"created" json:"created"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
File afero.File `xorm:"-" json:"-"`
// This ReadCloser is only used for migration purposes. Use with care!
@ -66,7 +63,6 @@ func (f *File) LoadFileMetaByID() (err error) {
if !exists {
return ErrFileDoesNotExist{FileID: f.ID}
}
f.Created = f.Created.ToTime()
return
}

View File

@ -17,7 +17,6 @@
package migration
import (
"code.vikunja.io/api/pkg/timeutil"
"src.techknowlogick.com/xormigrate"
"xorm.io/xorm"
)
@ -28,8 +27,8 @@ type taskComments20200219183248 struct {
AuthorID int64 `xorm:"not null" json:"-"`
TaskID int64 `xorm:"not null" json:"-" param:"task"`
Created timeutil.TimeStamp `xorm:"created"`
Updated timeutil.TimeStamp `xorm:"updated"`
Created int64 `xorm:"created"`
Updated int64 `xorm:"updated"`
}
func (s taskComments20200219183248) TableName() string {

View File

@ -17,18 +17,17 @@
package migration
import (
"code.vikunja.io/api/pkg/timeutil"
"src.techknowlogick.com/xormigrate"
"xorm.io/xorm"
)
type bucket20200418230605 struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"`
Title string `xorm:"text not null"`
ListID int64 `xorm:"int(11) not null"`
Created timeutil.TimeStamp `xorm:"created not null"`
Updated timeutil.TimeStamp `xorm:"updated not null"`
CreatedByID int64 `xorm:"int(11) not null"`
ID int64 `xorm:"int(11) autoincr not null unique pk"`
Title string `xorm:"text not null"`
ListID int64 `xorm:"int(11) not null"`
Created int64 `xorm:"created not null"`
Updated int64 `xorm:"updated not null"`
CreatedByID int64 `xorm:"int(11) not null"`
}
func (b *bucket20200418230605) TableName() string {

View File

@ -17,7 +17,6 @@
package migration
import (
"code.vikunja.io/api/pkg/timeutil"
"src.techknowlogick.com/xormigrate"
"xorm.io/xorm"
)
@ -32,10 +31,10 @@ func (l *list20200425182634) TableName() string {
}
type task20200425182634 struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"listtask"`
ListID int64 `xorm:"int(11) INDEX not null" json:"list_id" param:"list"`
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
BucketID int64 `xorm:"int(11) null" json:"bucket_id"`
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"listtask"`
ListID int64 `xorm:"int(11) INDEX not null" json:"list_id" param:"list"`
Updated int64 `xorm:"updated not null" json:"updated"`
BucketID int64 `xorm:"int(11) null" json:"bucket_id"`
}
func (t *task20200425182634) TableName() string {
@ -43,12 +42,12 @@ func (t *task20200425182634) TableName() string {
}
type bucket20200425182634 struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"bucket"`
Title string `xorm:"text not null" valid:"required" minLength:"1" json:"title"`
ListID int64 `xorm:"int(11) not null" json:"list_id" param:"list"`
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"bucket"`
Title string `xorm:"text not null" valid:"required" minLength:"1" json:"title"`
ListID int64 `xorm:"int(11) not null" json:"list_id" param:"list"`
Created int64 `xorm:"created not null" json:"created"`
Updated int64 `xorm:"updated not null" json:"updated"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
}
func (b *bucket20200425182634) TableName() string {

View File

@ -17,23 +17,22 @@
package migration
import (
"code.vikunja.io/api/pkg/timeutil"
"src.techknowlogick.com/xormigrate"
"strings"
"xorm.io/xorm"
)
type list20200516123847 struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"list"`
Title string `xorm:"varchar(250) not null" json:"title" valid:"required,runelength(3|250)" minLength:"3" maxLength:"250"`
Description string `xorm:"longtext null" json:"description"`
Identifier string `xorm:"varchar(10) null" json:"identifier" valid:"runelength(0|10)" minLength:"0" maxLength:"10"`
HexColor string `xorm:"varchar(6) null" json:"hex_color" valid:"runelength(0|6)" maxLength:"6"`
OwnerID int64 `xorm:"int(11) INDEX not null" json:"-"`
NamespaceID int64 `xorm:"int(11) INDEX not null" json:"-" param:"namespace"`
IsArchived bool `xorm:"not null default false" json:"is_archived" query:"is_archived"`
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"list"`
Title string `xorm:"varchar(250) not null" json:"title" valid:"required,runelength(3|250)" minLength:"3" maxLength:"250"`
Description string `xorm:"longtext null" json:"description"`
Identifier string `xorm:"varchar(10) null" json:"identifier" valid:"runelength(0|10)" minLength:"0" maxLength:"10"`
HexColor string `xorm:"varchar(6) null" json:"hex_color" valid:"runelength(0|6)" maxLength:"6"`
OwnerID int64 `xorm:"int(11) INDEX not null" json:"-"`
NamespaceID int64 `xorm:"int(11) INDEX not null" json:"-" param:"namespace"`
IsArchived bool `xorm:"not null default false" json:"is_archived" query:"is_archived"`
Created int64 `xorm:"created not null" json:"created"`
Updated int64 `xorm:"updated not null" json:"updated"`
}
func (l *list20200516123847) TableName() string {

View File

@ -18,9 +18,9 @@ package models
import (
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// Bucket represents a kanban bucket
@ -35,9 +35,9 @@ type Bucket struct {
Tasks []*Task `xorm:"-" json:"tasks"`
// A timestamp when this bucket was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this bucket was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
// The user who initially created the bucket.
CreatedBy *user.User `xorm:"-" json:"created_by" valid:"-"`

View File

@ -17,9 +17,9 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// Label represents a label
@ -38,9 +38,9 @@ type Label struct {
CreatedBy *user.User `xorm:"-" json:"created_by"`
// A timestamp when this label was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this label was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -17,9 +17,9 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
"xorm.io/builder"
)
@ -31,7 +31,7 @@ type LabelTask struct {
// The label id you want to associate with a task.
LabelID int64 `xorm:"int(11) INDEX not null" json:"label_id" param:"label"`
// A timestamp when this task was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -2,7 +2,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"gopkg.in/d4l3k/messagediff.v1"
"reflect"
@ -17,7 +16,7 @@ func TestLabelTask_ReadAll(t *testing.T) {
ID int64
TaskID int64
LabelID int64
Created timeutil.TimeStamp
Created time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -113,7 +112,7 @@ func TestLabelTask_Create(t *testing.T) {
ID int64
TaskID int64
LabelID int64
Created timeutil.TimeStamp
Created time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -207,7 +206,7 @@ func TestLabelTask_Delete(t *testing.T) {
ID int64
TaskID int64
LabelID int64
Created timeutil.TimeStamp
Created time.Time
CRUDable web.CRUDable
Rights web.Rights
}

View File

@ -18,7 +18,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"gopkg.in/d4l3k/messagediff.v1"
"reflect"
@ -36,8 +35,8 @@ func TestLabel_ReadAll(t *testing.T) {
HexColor string
CreatedByID int64
CreatedBy *user.User
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -138,8 +137,8 @@ func TestLabel_ReadOne(t *testing.T) {
HexColor string
CreatedByID int64
CreatedBy *user.User
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -248,8 +247,8 @@ func TestLabel_Create(t *testing.T) {
HexColor string
CreatedByID int64
CreatedBy *user.User
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -308,8 +307,8 @@ func TestLabel_Update(t *testing.T) {
HexColor string
CreatedByID int64
CreatedBy *user.User
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -390,8 +389,8 @@ func TestLabel_Delete(t *testing.T) {
HexColor string
CreatedByID int64
CreatedBy *user.User
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}

View File

@ -18,11 +18,11 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils"
"code.vikunja.io/web"
"github.com/dgrijalva/jwt-go"
"time"
)
// SharingType holds the sharing type
@ -54,9 +54,9 @@ type LinkSharing struct {
SharedByID int64 `xorm:"int(11) INDEX not null" json:"-"`
// A timestamp when this list was shared. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this share was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -19,10 +19,10 @@ package models
import (
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"strings"
"time"
"xorm.io/builder"
"xorm.io/xorm"
)
@ -58,9 +58,9 @@ type List struct {
BackgroundInformation interface{} `xorm:"-" json:"background_information"`
// A timestamp when this list was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this list was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -17,8 +17,8 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/web"
"time"
)
// TeamList defines the relation between a team and a list
@ -33,9 +33,9 @@ type TeamList struct {
Right Right `xorm:"int(11) INDEX not null default 0" json:"right" valid:"length(0|2)" maximum:"2" default:"0"`
// A timestamp when this relation was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this relation was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -18,7 +18,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"github.com/stretchr/testify/assert"
@ -121,8 +120,8 @@ func TestTeamList_Update(t *testing.T) {
TeamID int64
ListID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}

View File

@ -17,9 +17,9 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// ListUser represents a list <-> user relation
@ -36,9 +36,9 @@ type ListUser struct {
Right Right `xorm:"int(11) INDEX not null default 0" json:"right" valid:"length(0|2)" maximum:"2" default:"0"`
// A timestamp when this relation was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this relation was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -18,7 +18,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"testing"
@ -31,8 +30,8 @@ func TestListUser_CanDoSomething(t *testing.T) {
UserID int64
ListID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}

View File

@ -18,7 +18,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"gopkg.in/d4l3k/messagediff.v1"
"reflect"
@ -35,8 +34,8 @@ func TestListUser_Create(t *testing.T) {
Username string
ListID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -136,8 +135,8 @@ func TestListUser_ReadAll(t *testing.T) {
UserID int64
ListID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -228,8 +227,8 @@ func TestListUser_Update(t *testing.T) {
Username string
ListID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -305,8 +304,8 @@ func TestListUser_Delete(t *testing.T) {
Username string
ListID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}

View File

@ -18,7 +18,6 @@ package models
import (
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"github.com/imdario/mergo"
@ -46,9 +45,9 @@ type Namespace struct {
Owner *user.User `xorm:"-" json:"owner" valid:"-"`
// A timestamp when this namespace was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this namespace was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`
@ -59,8 +58,8 @@ var PseudoNamespace = Namespace{
ID: -1,
Title: "Shared Lists",
Description: "Lists of other users shared with you via teams or directly.",
Created: timeutil.FromTime(time.Now()),
Updated: timeutil.FromTime(time.Now()),
Created: time.Now(),
Updated: time.Now(),
}
// TableName makes beautiful table names

View File

@ -17,8 +17,8 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/web"
"time"
)
// TeamNamespace defines the relationship between a Team and a Namespace
@ -33,9 +33,9 @@ type TeamNamespace struct {
Right Right `xorm:"int(11) INDEX not null default 0" json:"right" valid:"length(0|2)" maximum:"2" default:"0"`
// A timestamp when this relation was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this relation was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -18,7 +18,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"testing"
@ -31,8 +30,8 @@ func TestTeamNamespace_CanDoSomething(t *testing.T) {
TeamID int64
NamespaceID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}

View File

@ -18,7 +18,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"github.com/stretchr/testify/assert"
@ -113,8 +112,8 @@ func TestTeamNamespace_Update(t *testing.T) {
TeamID int64
NamespaceID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}

View File

@ -17,9 +17,9 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
user2 "code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// NamespaceUser represents a namespace <-> user relation
@ -35,9 +35,9 @@ type NamespaceUser struct {
Right Right `xorm:"int(11) INDEX not null default 0" json:"right" valid:"length(0|2)" maximum:"2" default:"0"`
// A timestamp when this relation was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this relation was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -18,7 +18,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"testing"
@ -31,8 +30,8 @@ func TestNamespaceUser_CanDoSomething(t *testing.T) {
UserID int64
NamespaceID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}

View File

@ -18,7 +18,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"gopkg.in/d4l3k/messagediff.v1"
@ -33,8 +32,8 @@ func TestNamespaceUser_Create(t *testing.T) {
Username string
NamespaceID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -133,8 +132,8 @@ func TestNamespaceUser_ReadAll(t *testing.T) {
UserID int64
NamespaceID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -226,8 +225,8 @@ func TestNamespaceUser_Update(t *testing.T) {
Username string
NamespaceID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}
@ -303,8 +302,8 @@ func TestNamespaceUser_Delete(t *testing.T) {
Username string
NamespaceID int64
Right Right
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}

View File

@ -17,17 +17,17 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// TaskAssginee represents an assignment of a user to a task
type TaskAssginee struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"-"`
TaskID int64 `xorm:"int(11) INDEX not null" json:"-" param:"listtask"`
UserID int64 `xorm:"int(11) INDEX not null" json:"user_id" param:"user"`
Created timeutil.TimeStamp `xorm:"created not null"`
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"-"`
TaskID int64 `xorm:"int(11) INDEX not null" json:"-" param:"listtask"`
UserID int64 `xorm:"int(11) INDEX not null" json:"user_id" param:"user"`
Created time.Time `xorm:"created not null"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -18,10 +18,10 @@ package models
import (
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"io"
"time"
)
// TaskAttachment is the definition of a task attachment
@ -35,7 +35,7 @@ type TaskAttachment struct {
File *files.File `xorm:"-" json:"file"`
Created timeutil.TimeStamp `xorm:"created" json:"created"`
Created time.Time `xorm:"created" json:"created"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`
@ -149,7 +149,6 @@ func (ta *TaskAttachment) ReadAll(a web.Auth, search string, page int, perPage i
continue
}
r.File = fs[r.FileID]
r.File.Created = r.File.Created.ToTime()
r.CreatedBy = us[r.CreatedByID]
}

View File

@ -19,7 +19,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"gopkg.in/d4l3k/messagediff.v1"
@ -432,7 +431,7 @@ func TestTaskCollection_ReadAll(t *testing.T) {
Index: 12,
CreatedByID: 1,
CreatedBy: user1,
Reminders: []timeutil.TimeStamp{1543626724, 1543626824},
Reminders: []time.Time{1543626724, 1543626824},
ListID: 1,
BucketID: 1,
RelatedTasks: map[RelationKind][]*Task{},

View File

@ -18,9 +18,9 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// TaskComment represents a task comment
@ -31,8 +31,8 @@ type TaskComment struct {
Author *user.User `xorm:"-" json:"author"`
TaskID int64 `xorm:"not null" json:"-" param:"task"`
Created timeutil.TimeStamp `xorm:"created" json:"created"`
Updated timeutil.TimeStamp `xorm:"updated" json:"updated"`
Created time.Time `xorm:"created" json:"created"`
Updated time.Time `xorm:"updated" json:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -18,9 +18,9 @@
package models
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
)
// RelationKind represents a kind of relation between to tasks
@ -88,7 +88,7 @@ type TaskRelation struct {
CreatedBy *user.User `xorm:"-" json:"created_by"`
// A timestamp when this label was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -20,7 +20,6 @@ import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/files"
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils"
"code.vikunja.io/web"
@ -44,12 +43,12 @@ type Task struct {
// Whether a task is done or not.
Done bool `xorm:"INDEX null" json:"done"`
// The time when a task was marked as done.
DoneAt timeutil.TimeStamp `xorm:"INDEX null 'done_at_unix'" json:"done_at"`
DoneAt time.Time `xorm:"INDEX null 'done_at_unix'" json:"done_at"`
// The time when the task is due.
DueDate timeutil.TimeStamp `xorm:"int(11) INDEX null 'due_date_unix'" json:"due_date"`
DueDate time.Time `xorm:"int(11) INDEX null 'due_date_unix'" json:"due_date"`
// An array of datetimes when the user wants to be reminded of the task.
Reminders []timeutil.TimeStamp `xorm:"-" json:"reminder_dates"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"` // ID of the user who put that task on the list
Reminders []time.Time `xorm:"-" json:"reminder_dates"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"` // ID of the user who put that task on the list
// The list this task belongs to.
ListID int64 `xorm:"int(11) INDEX not null" json:"list_id" param:"list"`
// An amount in seconds this task repeats itself. If this is set, when marking the task as done, it will mark itself as "undone" and then increase all remindes and the due date by its amount.
@ -59,9 +58,9 @@ type Task struct {
// The task priority. Can be anything you want, it is possible to sort by this later.
Priority int64 `xorm:"int(11) null" json:"priority"`
// When this task starts.
StartDate timeutil.TimeStamp `xorm:"int(11) INDEX null 'start_date_unix'" json:"start_date" query:"-"`
StartDate time.Time `xorm:"int(11) INDEX null 'start_date_unix'" json:"start_date" query:"-"`
// When this task ends.
EndDate timeutil.TimeStamp `xorm:"int(11) INDEX null 'end_date_unix'" json:"end_date" query:"-"`
EndDate time.Time `xorm:"int(11) INDEX null 'end_date_unix'" json:"end_date" query:"-"`
// An array of users who are assigned to this task
Assignees []*user.User `xorm:"-" json:"assignees"`
// An array of labels which are associated with this task.
@ -86,9 +85,9 @@ type Task struct {
Attachments []*TaskAttachment `xorm:"-" json:"attachments"`
// A timestamp when this task was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this task was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
// BucketID is the ID of the kanban bucket this task belongs to.
BucketID int64 `xorm:"int(11) null" json:"bucket_id"`
@ -115,10 +114,10 @@ func (Task) TableName() string {
// TaskReminder holds a reminder on a task
type TaskReminder struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"`
TaskID int64 `xorm:"int(11) not null INDEX"`
Reminder timeutil.TimeStamp `xorm:"int(11) not null INDEX 'reminder_unix'"`
Created timeutil.TimeStamp `xorm:"created not null"`
ID int64 `xorm:"int(11) autoincr not null unique pk"`
TaskID int64 `xorm:"int(11) not null INDEX"`
Reminder time.Time `xorm:"int(11) not null INDEX 'reminder_unix'"`
Created time.Time `xorm:"created not null"`
}
// TableName returns a pretty table name
@ -471,7 +470,7 @@ func addMoreInfoToTasks(taskMap map[int64]*Task) (err error) {
return
}
taskReminders := make(map[int64][]timeutil.TimeStamp)
taskReminders := make(map[int64][]time.Time)
for _, r := range reminders {
taskReminders[r.TaskID] = append(taskReminders[r.TaskID], r.Reminder)
}
@ -663,7 +662,7 @@ func (t *Task) Update() (err error) {
return
}
ot.Reminders = make([]timeutil.TimeStamp, len(reminders))
ot.Reminders = make([]time.Time, len(reminders))
for i, r := range reminders {
ot.Reminders[i] = r.Reminder
}
@ -737,20 +736,20 @@ func (t *Task) Update() (err error) {
ot.Description = ""
}
// Due date
if t.DueDate == 0 {
ot.DueDate = 0
if t.DueDate.IsZero() {
ot.DueDate = time.Time{}
}
// Repeat after
if t.RepeatAfter == 0 {
ot.RepeatAfter = 0
}
// Start date
if t.StartDate == 0 {
ot.StartDate = 0
if t.StartDate.IsZero() {
ot.StartDate = time.Time{}
}
// End date
if t.EndDate == 0 {
ot.EndDate = 0
if t.EndDate.IsZero() {
ot.EndDate = time.Time{}
}
// Color
if t.HexColor == "" {
@ -810,16 +809,16 @@ func updateDone(oldTask *Task, newTask *Task) {
now := time.Now()
// assuming we'll merge the new task over the old task
if oldTask.DueDate > 0 {
if !oldTask.DueDate.IsZero() {
if oldTask.RepeatFromCurrentDate {
newTask.DueDate = timeutil.FromTime(now.Add(repeatDuration))
newTask.DueDate = now.Add(repeatDuration)
} else {
// Always add one instance of the repeating interval to catch cases where a due date is already in the future
// but not the repeating interval
newTask.DueDate = timeutil.FromTime(oldTask.DueDate.ToTime().Add(repeatDuration))
newTask.DueDate = oldTask.DueDate.Add(repeatDuration)
// Add the repeating interval until the new due date is in the future
for !newTask.DueDate.ToTime().After(now) {
newTask.DueDate = timeutil.FromTime(newTask.DueDate.ToTime().Add(repeatDuration))
for !newTask.DueDate.After(now) {
newTask.DueDate = newTask.DueDate.Add(repeatDuration)
}
}
}
@ -830,47 +829,47 @@ func updateDone(oldTask *Task, newTask *Task) {
if len(oldTask.Reminders) > 0 {
if oldTask.RepeatFromCurrentDate {
sort.Slice(oldTask.Reminders, func(i, j int) bool {
return oldTask.Reminders[i] < oldTask.Reminders[j]
return oldTask.Reminders[i].Unix() < oldTask.Reminders[j].Unix()
})
first := oldTask.Reminders[0]
for in, r := range oldTask.Reminders {
diff := time.Duration(r-first) * time.Second
newTask.Reminders[in] = timeutil.FromTime(now.Add(repeatDuration + diff))
diff := r.Sub(first)
newTask.Reminders[in] = now.Add(repeatDuration + diff)
}
} else {
for in, r := range oldTask.Reminders {
newTask.Reminders[in] = timeutil.FromTime(r.ToTime().Add(repeatDuration))
for !newTask.Reminders[in].ToTime().After(now) {
newTask.Reminders[in] = timeutil.FromTime(newTask.Reminders[in].ToTime().Add(repeatDuration))
newTask.Reminders[in] = r.Add(repeatDuration)
for !newTask.Reminders[in].After(now) {
newTask.Reminders[in] = newTask.Reminders[in].Add(repeatDuration)
}
}
}
}
// If a task has a start and end date, the end date should keep the difference to the start date when setting them as new
if oldTask.RepeatFromCurrentDate && oldTask.StartDate > 0 && oldTask.EndDate > 0 {
diff := time.Duration(oldTask.EndDate-oldTask.StartDate) * time.Second
newTask.StartDate = timeutil.FromTime(now.Add(repeatDuration))
newTask.EndDate = timeutil.FromTime(now.Add(repeatDuration + diff))
if oldTask.RepeatFromCurrentDate && !oldTask.StartDate.IsZero() && !oldTask.EndDate.IsZero() {
diff := oldTask.EndDate.Sub(oldTask.StartDate)
newTask.StartDate = now.Add(repeatDuration)
newTask.EndDate = now.Add(repeatDuration + diff)
} else {
if oldTask.StartDate > 0 {
if !oldTask.StartDate.IsZero() {
if oldTask.RepeatFromCurrentDate {
newTask.StartDate = timeutil.FromTime(now.Add(repeatDuration))
newTask.StartDate = now.Add(repeatDuration)
} else {
newTask.StartDate = timeutil.FromTime(oldTask.StartDate.ToTime().Add(repeatDuration))
for !newTask.StartDate.ToTime().After(now) {
newTask.StartDate = timeutil.FromTime(newTask.StartDate.ToTime().Add(repeatDuration))
newTask.StartDate = oldTask.StartDate.Add(repeatDuration)
for !newTask.StartDate.After(now) {
newTask.StartDate = newTask.StartDate.Add(repeatDuration)
}
}
}
if oldTask.EndDate > 0 {
if !oldTask.EndDate.IsZero() {
if oldTask.RepeatFromCurrentDate {
newTask.EndDate = timeutil.FromTime(now.Add(repeatDuration))
newTask.EndDate = now.Add(repeatDuration)
} else {
newTask.EndDate = timeutil.FromTime(oldTask.EndDate.ToTime().Add(repeatDuration))
for !newTask.EndDate.ToTime().After(now) {
newTask.EndDate = timeutil.FromTime(newTask.EndDate.ToTime().Add(repeatDuration))
newTask.EndDate = oldTask.EndDate.Add(repeatDuration)
for !newTask.EndDate.After(now) {
newTask.EndDate = newTask.EndDate.Add(repeatDuration)
}
}
}
@ -881,17 +880,17 @@ func updateDone(oldTask *Task, newTask *Task) {
// Update the "done at" timestamp
if !oldTask.Done && newTask.Done {
newTask.DoneAt = timeutil.FromTime(time.Now())
newTask.DoneAt = time.Now()
}
// When unmarking a task as done, reset the timestamp
if oldTask.Done && !newTask.Done {
newTask.DoneAt = 0
newTask.DoneAt = time.Time{}
}
}
// Creates or deletes all necessary reminders without unneded db operations.
// The parameter is a slice with unix dates which holds the new reminders.
func (t *Task) updateReminders(reminders []timeutil.TimeStamp) (err error) {
func (t *Task) updateReminders(reminders []time.Time) (err error) {
// Load the current reminders
taskReminders, err := getRemindersForTasks([]int64{t.ID})
@ -899,7 +898,7 @@ func (t *Task) updateReminders(reminders []timeutil.TimeStamp) (err error) {
return err
}
t.Reminders = make([]timeutil.TimeStamp, 0, len(taskReminders))
t.Reminders = make([]time.Time, 0, len(taskReminders))
for _, reminder := range taskReminders {
t.Reminders = append(t.Reminders, reminder.Reminder)
}
@ -918,15 +917,15 @@ func (t *Task) updateReminders(reminders []timeutil.TimeStamp) (err error) {
}
// Make a hashmap of the new reminders for easier comparison
newReminders := make(map[timeutil.TimeStamp]*TaskReminder, len(reminders))
newReminders := make(map[time.Time]*TaskReminder, len(reminders))
for _, newReminder := range reminders {
newReminders[newReminder] = &TaskReminder{Reminder: newReminder}
}
// Get old reminders to delete
var found bool
var remindersToDelete []timeutil.TimeStamp
oldReminders := make(map[timeutil.TimeStamp]*TaskReminder, len(t.Reminders))
var remindersToDelete []time.Time
oldReminders := make(map[time.Time]*TaskReminder, len(t.Reminders))
for _, oldReminder := range t.Reminders {
found = false
// If a new reminder is already in the list with old reminders

View File

@ -131,21 +131,21 @@ func TestUpdateDone(t *testing.T) {
oldTask := &Task{Done: false}
newTask := &Task{Done: true}
updateDone(oldTask, newTask)
assert.NotEqual(t, timeutil.TimeStamp(0), newTask.DoneAt)
assert.NotEqual(t, time.Time(0), newTask.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, timeutil.TimeStamp(0), newTask.DoneAt)
assert.Equal(t, time.Time(0), newTask.DoneAt)
})
t.Run("repeating interval", func(t *testing.T) {
t.Run("normal", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
DueDate: timeutil.TimeStamp(1550000000),
DueDate: time.Time(1550000000),
}
newTask := &Task{
Done: true,
@ -153,30 +153,30 @@ func TestUpdateDone(t *testing.T) {
updateDone(oldTask, newTask)
var expected int64 = 1550008600
for expected < time.Now().() {
for expected < time.Now().{
expected += oldTask.RepeatAfter
}
assert.Equal(t, timeutil.TimeStamp(expected), newTask.DueDate)
assert.Equal(t, time.Time(expected), newTask.DueDate)
})
t.Run("don't update if due date is zero", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
DueDate: timeutil.TimeStamp(0),
DueDate: time.Time(0),
}
newTask := &Task{
Done: true,
DueDate: timeutil.TimeStamp(1543626724),
DueDate: time.Time(1543626724),
}
updateDone(oldTask, newTask)
assert.Equal(t, timeutil.TimeStamp(1543626724), newTask.DueDate)
assert.Equal(t, time.Time(1543626724), newTask.DueDate)
})
t.Run("update reminders", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
Reminders: []timeutil.TimeStamp{
Reminders: []time.Time{
1550000000,
1555000000,
},
@ -188,22 +188,22 @@ func TestUpdateDone(t *testing.T) {
var expected1 int64 = 1550008600
var expected2 int64 = 1555008600
for expected1 < time.Now().() {
for expected1 < time.Now().{
expected1 += oldTask.RepeatAfter
}
for expected2 < time.Now().() {
for expected2 < time.Now().{
expected2 += oldTask.RepeatAfter
}
assert.Len(t, newTask.Reminders, 2)
assert.Equal(t, timeutil.TimeStamp(expected1), newTask.Reminders[0])
assert.Equal(t, timeutil.TimeStamp(expected2), newTask.Reminders[1])
assert.Equal(t, time.Time(expected1), newTask.Reminders[0])
assert.Equal(t, time.Time(expected2), newTask.Reminders[1])
})
t.Run("update start date", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
StartDate: timeutil.TimeStamp(1550000000),
StartDate: time.Time(1550000000),
}
newTask := &Task{
Done: true,
@ -211,17 +211,17 @@ func TestUpdateDone(t *testing.T) {
updateDone(oldTask, newTask)
var expected int64 = 1550008600
for expected < time.Now().() {
for expected < time.Now().{
expected += oldTask.RepeatAfter
}
assert.Equal(t, timeutil.TimeStamp(expected), newTask.StartDate)
assert.Equal(t, time.Time(expected), newTask.StartDate)
})
t.Run("update end date", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
EndDate: timeutil.TimeStamp(1550000000),
EndDate: time.Time(1550000000),
}
newTask := &Task{
Done: true,
@ -229,24 +229,24 @@ func TestUpdateDone(t *testing.T) {
updateDone(oldTask, newTask)
var expected int64 = 1550008600
for expected < time.Now().() {
for expected < time.Now().{
expected += oldTask.RepeatAfter
}
assert.Equal(t, timeutil.TimeStamp(expected), newTask.EndDate)
assert.Equal(t, time.Time(expected), newTask.EndDate)
})
t.Run("ensure due date is repeated even if the original one is in the future", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
DueDate: timeutil.FromTime(time.Now().Add(time.Hour)),
DueDate: time.Now().Add(time.Hour),
}
newTask := &Task{
Done: true,
}
updateDone(oldTask, newTask)
expected := int64(oldTask.DueDate) + oldTask.RepeatAfter
assert.Equal(t, timeutil.TimeStamp(expected), newTask.DueDate)
assert.Equal(t, time.Time(expected), newTask.DueDate)
})
t.Run("repeat from current date", func(t *testing.T) {
t.Run("due date", func(t *testing.T) {
@ -254,21 +254,21 @@ func TestUpdateDone(t *testing.T) {
Done: false,
RepeatAfter: 8600,
RepeatFromCurrentDate: true,
DueDate: timeutil.TimeStamp(1550000000),
DueDate: time.Time(1550000000),
}
newTask := &Task{
Done: true,
}
updateDone(oldTask, newTask)
assert.Equal(t, timeutil.FromTime(time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second)), newTask.DueDate)
assert.Equal(t, time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second), newTask.DueDate)
})
t.Run("reminders", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
RepeatFromCurrentDate: true,
Reminders: []timeutil.TimeStamp{
Reminders: []time.Time{
1550000000,
1555000000,
},
@ -281,44 +281,44 @@ func TestUpdateDone(t *testing.T) {
diff := time.Duration(oldTask.Reminders[1]-oldTask.Reminders[0]) * time.Second
assert.Len(t, newTask.Reminders, 2)
assert.Equal(t, timeutil.FromTime(time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second)), newTask.Reminders[0])
assert.Equal(t, timeutil.FromTime(time.Now().Add(diff+time.Duration(oldTask.RepeatAfter)*time.Second)), newTask.Reminders[1])
assert.Equal(t, time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second), newTask.Reminders[0])
assert.Equal(t, time.Now().Add(diff+time.Duration(oldTask.RepeatAfter)*time.Second), newTask.Reminders[1])
})
t.Run("start date", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
RepeatFromCurrentDate: true,
StartDate: timeutil.TimeStamp(1550000000),
StartDate: time.Time(1550000000),
}
newTask := &Task{
Done: true,
}
updateDone(oldTask, newTask)
assert.Equal(t, timeutil.FromTime(time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second)), newTask.StartDate)
assert.Equal(t, time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second), newTask.StartDate)
})
t.Run("end date", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
RepeatFromCurrentDate: true,
EndDate: timeutil.TimeStamp(1560000000),
EndDate: time.Time(1560000000),
}
newTask := &Task{
Done: true,
}
updateDone(oldTask, newTask)
assert.Equal(t, timeutil.FromTime(time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second)), newTask.EndDate)
assert.Equal(t, time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second), newTask.EndDate)
})
t.Run("start and end date", func(t *testing.T) {
oldTask := &Task{
Done: false,
RepeatAfter: 8600,
RepeatFromCurrentDate: true,
StartDate: timeutil.TimeStamp(1550000000),
EndDate: timeutil.TimeStamp(1560000000),
StartDate: time.Time(1550000000),
EndDate: time.Time(1560000000),
}
newTask := &Task{
Done: true,
@ -327,8 +327,8 @@ func TestUpdateDone(t *testing.T) {
diff := time.Duration(oldTask.EndDate-oldTask.StartDate) * time.Second
assert.Equal(t, timeutil.FromTime(time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second)), newTask.StartDate)
assert.Equal(t, timeutil.FromTime(time.Now().Add(diff+time.Duration(oldTask.RepeatAfter)*time.Second)), newTask.EndDate)
assert.Equal(t, time.Now().Add(time.Duration(oldTask.RepeatAfter)*time.Second), newTask.StartDate)
assert.Equal(t, time.Now().Add(diff+time.Duration(oldTask.RepeatAfter)*time.Second), newTask.EndDate)
})
})
})

View File

@ -18,9 +18,9 @@ package models
import (
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/web"
"time"
"xorm.io/builder"
)
@ -40,9 +40,9 @@ type Team struct {
Members []*TeamUser `xorm:"-" json:"members"`
// A timestamp when this relation was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created" json:"created"`
Created time.Time `xorm:"created" json:"created"`
// A timestamp when this relation was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated" json:"updated"`
Updated time.Time `xorm:"updated" json:"updated"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`
@ -71,7 +71,7 @@ type TeamMember struct {
Admin bool `xorm:"null" json:"admin"`
// A timestamp when this relation was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
web.CRUDable `xorm:"-" json:"-"`
web.Rights `xorm:"-" json:"-"`

View File

@ -18,7 +18,6 @@ package models
import (
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"testing"
@ -33,8 +32,8 @@ func TestTeam_CanDoSomething(t *testing.T) {
CreatedByID int64
CreatedBy *user.User
Members []*TeamUser
Created timeutil.TimeStamp
Updated timeutil.TimeStamp
Created time.Time
Updated time.Time
CRUDable web.CRUDable
Rights web.Rights
}

View File

@ -17,16 +17,16 @@
package migration
import (
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"time"
)
// Status represents this migration status
type Status struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
UserID int64 `xorm:"int(11) not null" json:"-"`
MigratorName string `xorm:"varchar(255)" json:"migrator_name"`
Created timeutil.TimeStamp `xorm:"created not null 'created_unix'" json:"time_unix"`
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id"`
UserID int64 `xorm:"int(11) not null" json:"-"`
MigratorName string `xorm:"varchar(255)" json:"migrator_name"`
Created time.Time `xorm:"created not null 'created_unix'" json:"time_unix"`
}
// TableName holds the table name for the migration status table

View File

@ -23,7 +23,6 @@ import (
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/migration"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils"
"encoding/json"
@ -267,14 +266,14 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
for _, i := range sync.Items {
task := &models.Task{
Title: i.Content,
Created: timeutil.FromTime(i.DateAdded),
Created: i.DateAdded,
Done: i.Checked == 1,
}
// Only try to parse the task done at date if the task is actually done
// Sometimes weired things happen if we try to parse nil dates.
if task.Done {
task.DoneAt = timeutil.FromTime(i.DateCompleted)
task.DoneAt = i.DateCompleted
}
// Todoist priorities only range from 1 (lowest) and max 4 (highest), so we need to make slight adjustments
@ -288,7 +287,7 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
if err != nil {
return nil, err
}
task.DueDate = timeutil.FromTime(dueDate)
task.DueDate = dueDate
}
// Put all labels together from earlier
@ -345,13 +344,12 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
Mime: n.FileAttachment.FileType,
Size: uint64(n.FileAttachment.FileSize),
Created: n.Posted,
Created: timeutil.FromTime(n.Posted),
// We directly pass the file contents here to have a way to link the attachment to the file later.
// Because we don't have an ID for our task at this point of the migration, we cannot just throw all
// attachments in a slice and do the work of downloading and properly storing them later.
FileContent: buf.Bytes(),
},
Created: timeutil.FromTime(n.Posted),
Created: n.Posted,
})
}
@ -375,7 +373,7 @@ func convertTodoistToVikunja(sync *sync) (fullVikunjaHierachie []*models.Namespa
return nil, err
}
tasks[r.ItemID].Reminders = append(tasks[r.ItemID].Reminders, timeutil.FromTime(date))
tasks[r.ItemID].Reminders = append(tasks[r.ItemID].Reminders, date)
}
return []*models.NamespaceWithLists{

View File

@ -344,68 +344,68 @@ func TestConvertTodoistToVikunja(t *testing.T) {
Title: "Task400000000",
Description: "Lorem Ipsum dolor sit amet",
Done: false,
Created: timeutil.FromTime(time1),
Reminders: []timeutil.TimeStamp{
timeutil.FromTime(time.Date(2020, time.June, 15, 0, 0, 0, 0, time.UTC)),
timeutil.FromTime(time.Date(2020, time.June, 16, 0, 0, 0, 0, time.UTC)),
Created: time1,
Reminders: []time.Time{
time.Date(2020, time.June, 15, 0, 0, 0, 0, time.UTC),
time.Date(2020, time.June, 16, 0, 0, 0, 0, time.UTC),
},
},
{
Title: "Task400000001",
Description: "Lorem Ipsum dolor sit amet",
Done: false,
Created: timeutil.FromTime(time1),
Created: time1,
},
{
Title: "Task400000002",
Done: false,
Created: timeutil.FromTime(time1),
Reminders: []timeutil.TimeStamp{
timeutil.FromTime(time.Date(2020, time.July, 15, 0, 0, 0, 0, time.UTC)),
Created: time1,
Reminders: []time.Time{
time.Date(2020, time.July, 15, 0, 0, 0, 0, time.UTC),
},
},
{
Title: "Task400000003",
Description: "Lorem Ipsum dolor sit amet",
Done: true,
DueDate: timeutil.FromTime(dueTime),
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(time3),
DueDate: dueTime,
Created: time1,
DoneAt: time3,
Labels: vikunjaLabels,
Reminders: []timeutil.TimeStamp{
timeutil.FromTime(time.Date(2020, time.June, 15, 0, 0, 0, 0, time.UTC)),
Reminders: []time.Time{
time.Date(2020, time.June, 15, 0, 0, 0, 0, time.UTC),
},
},
{
Title: "Task400000004",
Done: false,
Created: timeutil.FromTime(time1),
Created: time1,
Labels: vikunjaLabels,
},
{
Title: "Task400000005",
Done: true,
DueDate: timeutil.FromTime(dueTime),
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(time3),
Reminders: []timeutil.TimeStamp{
timeutil.FromTime(time.Date(2020, time.June, 15, 0, 0, 0, 0, time.UTC)),
DueDate: dueTime,
Created: time1,
DoneAt: time3,
Reminders: []time.Time{
time.Date(2020, time.June, 15, 0, 0, 0, 0, time.UTC),
},
},
{
Title: "Task400000006",
Done: true,
DueDate: timeutil.FromTime(dueTime),
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(time3),
DueDate: dueTime,
Created: time1,
DoneAt: time3,
RelatedTasks: map[models.RelationKind][]*models.Task{
models.RelationKindSubtask: {
{
Title: "Task with parent",
Done: false,
Priority: 2,
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(nilTime),
Created: time1,
DoneAt: nilTime,
},
},
},
@ -414,34 +414,34 @@ func TestConvertTodoistToVikunja(t *testing.T) {
Title: "Task with parent",
Done: false,
Priority: 2,
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(nilTime),
Created: time1,
DoneAt: nilTime,
},
{
Title: "Task400000106",
Done: true,
DueDate: timeutil.FromTime(dueTime),
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(time3),
DueDate: dueTime,
Created: time1,
DoneAt: time3,
Labels: vikunjaLabels,
},
{
Title: "Task400000107",
Done: true,
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(time3),
Created: time1,
DoneAt: time3,
},
{
Title: "Task400000108",
Done: true,
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(time3),
Created: time1,
DoneAt: time3,
},
{
Title: "Task400000109",
Done: true,
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(time3),
Created: time1,
DoneAt: time3,
},
},
},
@ -453,35 +453,35 @@ func TestConvertTodoistToVikunja(t *testing.T) {
{
Title: "Task400000007",
Done: false,
DueDate: timeutil.FromTime(dueTime),
Created: timeutil.FromTime(time1),
DueDate: dueTime,
Created: time1,
},
{
Title: "Task400000008",
Done: false,
DueDate: timeutil.FromTime(dueTime),
Created: timeutil.FromTime(time1),
DueDate: dueTime,
Created: time1,
},
{
Title: "Task400000009",
Done: false,
Created: timeutil.FromTime(time1),
Reminders: []timeutil.TimeStamp{
timeutil.FromTime(time.Date(2020, time.June, 15, 0, 0, 0, 0, time.UTC)),
Created: time1,
Reminders: []time.Time{
time.Date(2020, time.June, 15, 0, 0, 0, 0, time.UTC),
},
},
{
Title: "Task400000010",
Description: "Lorem Ipsum dolor sit amet",
Done: true,
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(time3),
Created: time1,
DoneAt: time3,
},
{
Title: "Task400000101",
Description: "Lorem Ipsum dolor sit amet",
Done: false,
Created: timeutil.FromTime(time1),
Created: time1,
Attachments: []*models.TaskAttachment{
{
File: &files.File{
@ -489,37 +489,37 @@ func TestConvertTodoistToVikunja(t *testing.T) {
Mime: "text/plain",
Size: 12345,
Created: time1,
Created: timeutil.FromTime(time1),
Created: time1,
FileContent: exampleFile,
},
Created: timeutil.FromTime(time1),
Created: time1,
},
},
},
{
Title: "Task400000102",
Done: false,
DueDate: timeutil.FromTime(dueTime),
Created: timeutil.FromTime(time1),
DueDate: dueTime,
Created: time1,
Labels: vikunjaLabels,
},
{
Title: "Task400000103",
Done: false,
Created: timeutil.FromTime(time1),
Created: time1,
Labels: vikunjaLabels,
},
{
Title: "Task400000104",
Done: false,
Created: timeutil.FromTime(time1),
Created: time1,
Labels: vikunjaLabels,
},
{
Title: "Task400000105",
Done: false,
DueDate: timeutil.FromTime(dueTime),
Created: timeutil.FromTime(time1),
DueDate: dueTime,
Created: time1,
Labels: vikunjaLabels,
},
},
@ -532,8 +532,8 @@ func TestConvertTodoistToVikunja(t *testing.T) {
{
Title: "Task400000111",
Done: true,
Created: timeutil.FromTime(time1),
DoneAt: timeutil.FromTime(time3),
Created: time1,
DoneAt: time3,
},
},
},

View File

@ -23,7 +23,6 @@ import (
"code.vikunja.io/api/pkg/log"
"code.vikunja.io/api/pkg/models"
"code.vikunja.io/api/pkg/modules/migration"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/user"
"code.vikunja.io/api/pkg/utils"
"encoding/json"
@ -145,7 +144,7 @@ func convertListForFolder(listID int, list *list, content *wunderlistContents) (
l := &models.List{
Title: list.Title,
Created: timeutil.FromTime(list.CreatedAt),
Created: list.CreatedAt,
}
// Find all tasks belonging to this list and put them in
@ -153,13 +152,13 @@ func convertListForFolder(listID int, list *list, content *wunderlistContents) (
if t.ListID == listID {
newTask := &models.Task{
Title: t.Title,
Created: timeutil.FromTime(t.CreatedAt),
Created: t.CreatedAt,
Done: t.Completed,
}
// Set Done At
if newTask.Done {
newTask.DoneAt = timeutil.FromTime(t.CompletedAt)
newTask.DoneAt = t.CompletedAt
}
// Parse the due date
@ -168,7 +167,7 @@ func convertListForFolder(listID int, list *list, content *wunderlistContents) (
if err != nil {
return nil, err
}
newTask.DueDate = timeutil.FromTime(dueDate)
newTask.DueDate = dueDate
}
// Find related notes
@ -199,13 +198,12 @@ func convertListForFolder(listID int, list *list, content *wunderlistContents) (
Mime: f.ContentType,
Size: uint64(f.FileSize),
Created: f.CreatedAt,
Created: timeutil.FromTime(f.CreatedAt),
// We directly pass the file contents here to have a way to link the attachment to the file later.
// Because we don't have an ID for our task at this point of the migration, we cannot just throw all
// attachments in a slice and do the work of downloading and properly storing them later.
FileContent: buf.Bytes(),
},
Created: timeutil.FromTime(f.CreatedAt),
Created: f.CreatedAt,
})
}
}
@ -225,7 +223,7 @@ func convertListForFolder(listID int, list *list, content *wunderlistContents) (
// Reminders
for _, r := range content.reminders {
if r.TaskID == t.ID {
newTask.Reminders = append(newTask.Reminders, timeutil.FromTime(r.Date))
newTask.Reminders = append(newTask.Reminders, r.Date)
}
}
@ -248,8 +246,8 @@ func convertWunderlistToVikunja(content *wunderlistContents) (fullVikunjaHierach
namespace := &models.NamespaceWithLists{
Namespace: models.Namespace{
Title: folder.Title,
Created: timeutil.FromTime(folder.CreatedAt),
Updated: timeutil.FromTime(folder.UpdatedAt),
Created: folder.CreatedAt,
Updated: folder.UpdatedAt,
},
}

View File

@ -193,18 +193,18 @@ func TestWunderlistParsing(t *testing.T) {
{
Namespace: models.Namespace{
Title: "Lorem Ipsum",
Created: timeutil.FromTime(time1),
Updated: timeutil.FromTime(time2),
Created: time1,
Updated: time2,
},
Lists: []*models.List{
{
Created: timeutil.FromTime(time1),
Created: time1,
Title: "Lorem1",
Tasks: []*models.Task{
{
Title: "Ipsum1",
DueDate: 1378339200,
Created: timeutil.FromTime(time1),
Created: time1,
Description: "Lorem Ipsum dolor sit amet",
Attachments: []*models.TaskAttachment{
{
@ -213,18 +213,18 @@ func TestWunderlistParsing(t *testing.T) {
Mime: "text/plain",
Size: 12345,
Created: time2,
Created: timeutil.FromTime(time2),
Created: time2,
FileContent: exampleFile,
},
Created: timeutil.FromTime(time2),
Created: time2,
},
},
Reminders: []timeutil.TimeStamp{timeutil.FromTime(time4)},
Reminders: []time.Time{time4},
},
{
Title: "Ipsum2",
DueDate: 1378339200,
Created: timeutil.FromTime(time1),
Created: time1,
Description: "Lorem Ipsum dolor sit amet",
RelatedTasks: map[models.RelationKind][]*models.Task{
models.RelationKindSubtask: {
@ -240,15 +240,15 @@ func TestWunderlistParsing(t *testing.T) {
},
},
{
Created: timeutil.FromTime(time1),
Created: time1,
Title: "Lorem2",
Tasks: []*models.Task{
{
Title: "Ipsum3",
Done: true,
DoneAt: timeutil.FromTime(time1),
DoneAt: time1,
DueDate: 1378339200,
Created: timeutil.FromTime(time1),
Created: time1,
Description: "Lorem Ipsum dolor sit amet",
Attachments: []*models.TaskAttachment{
{
@ -257,18 +257,18 @@ func TestWunderlistParsing(t *testing.T) {
Mime: "text/plain",
Size: 12345,
Created: time3,
Created: timeutil.FromTime(time3),
Created: time3,
FileContent: exampleFile,
},
Created: timeutil.FromTime(time3),
Created: time3,
},
},
},
{
Title: "Ipsum4",
DueDate: 1378339200,
Created: timeutil.FromTime(time1),
Reminders: []timeutil.TimeStamp{timeutil.FromTime(time3)},
Created: time1,
Reminders: []time.Time{time3},
RelatedTasks: map[models.RelationKind][]*models.Task{
models.RelationKindSubtask: {
{
@ -280,52 +280,52 @@ func TestWunderlistParsing(t *testing.T) {
},
},
{
Created: timeutil.FromTime(time1),
Created: time1,
Title: "Lorem3",
Tasks: []*models.Task{
{
Title: "Ipsum5",
DueDate: 1378339200,
Created: timeutil.FromTime(time1),
Created: time1,
},
{
Title: "Ipsum6",
DueDate: 1378339200,
Created: timeutil.FromTime(time1),
Created: time1,
Done: true,
DoneAt: timeutil.FromTime(time1),
DoneAt: time1,
},
{
Title: "Ipsum7",
DueDate: 1378339200,
Created: timeutil.FromTime(time1),
Created: time1,
Done: true,
DoneAt: timeutil.FromTime(time1),
DoneAt: time1,
},
{
Title: "Ipsum8",
DueDate: 1378339200,
Created: timeutil.FromTime(time1),
Created: time1,
},
},
},
{
Created: timeutil.FromTime(time1),
Created: time1,
Title: "Lorem4",
Tasks: []*models.Task{
{
Title: "Ipsum9",
DueDate: 1378339200,
Created: timeutil.FromTime(time1),
Created: time1,
Done: true,
DoneAt: timeutil.FromTime(time1),
DoneAt: time1,
},
{
Title: "Ipsum10",
DueDate: 1378339200,
Created: timeutil.FromTime(time1),
Created: time1,
Done: true,
DoneAt: timeutil.FromTime(time1),
DoneAt: time1,
},
},
},
@ -337,7 +337,7 @@ func TestWunderlistParsing(t *testing.T) {
},
Lists: []*models.List{
{
Created: timeutil.FromTime(time4),
Created: time4,
Title: "List without a namespace",
},
},

View File

@ -44,7 +44,7 @@ func NewUserJWTAuthtoken(user *user.User) (token string, err error) {
claims["id"] = user.ID
claims["username"] = user.Username
claims["email"] = user.Email
claims["exp"] = time.Now().Add(time.Hour * 72).()
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
// Generate encoded token and send it as response.
return t.SignedString([]byte(config.ServiceJWTSecret.GetString()))
@ -62,7 +62,7 @@ func NewLinkShareJWTAuthtoken(share *models.LinkSharing) (token string, err erro
claims["list_id"] = share.ListID
claims["right"] = share.Right
claims["sharedByID"] = share.SharedByID
claims["exp"] = time.Now().Add(time.Hour * 72).()
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
// Generate encoded token and send it as response.
return t.SignedString([]byte(config.ServiceJWTSecret.GetString()))

View File

@ -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().(), 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().(), 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.(vlra.task.Updated.ToTime().(), 0)
return vlra.task.Updated
}
if vlra.list != nil {
return time.(vlra.list.Updated.ToTime().(), 0)
return vlra.list.Updated
}
return time.Time{}

View File

@ -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
}

View File

@ -30,12 +30,12 @@ type TimeStamp int64
// ToTime returns a time.Time from a TimeStamp
func (ts *TimeStamp) ToTime() time.Time {
return time.(int64(*ts), 0)
return time.Unix(int64(*ts), 0)
}
// FromTime converts a time.Time to a TimeStamp
func FromTime(t time.Time) TimeStamp {
return TimeStamp(t.())
return TimeStamp(t.Unix())
}
// MarshalJSON converts a TimeStamp to a json string
@ -61,7 +61,7 @@ func (ts *TimeStamp) UnmarshalJSON(data []byte) error {
return err
}
if s == "" {
*ts = FromTime(time.(0, 0))
*ts = FromTime(time.Unix(0, 0))
return nil
}
@ -75,6 +75,6 @@ func (ts *TimeStamp) UnmarshalJSON(data []byte) error {
return err
}
*ts = TimeStamp(t.In(loc).())
*ts = TimeStamp(t.In(loc).Unix())
return nil
}

View File

@ -21,7 +21,6 @@ import (
"code.vikunja.io/api/pkg/config"
"code.vikunja.io/api/pkg/mail"
"code.vikunja.io/api/pkg/metrics"
"code.vikunja.io/api/pkg/timeutil"
"code.vikunja.io/api/pkg/utils"
"code.vikunja.io/web"
"fmt"
@ -29,6 +28,7 @@ import (
"github.com/labstack/echo/v4"
"golang.org/x/crypto/bcrypt"
"reflect"
"time"
)
// Login Object to recive user credentials in JSON format
@ -56,9 +56,9 @@ type User struct {
EmailConfirmToken string `xorm:"varchar(450) null" json:"-"`
// A timestamp when this task was created. You cannot change this value.
Created timeutil.TimeStamp `xorm:"created not null" json:"created"`
Created time.Time `xorm:"created not null" json:"created"`
// A timestamp when this task was last updated. You cannot change this value.
Updated timeutil.TimeStamp `xorm:"updated not null" json:"updated"`
Updated time.Time `xorm:"updated not null" json:"updated"`
web.Auth `xorm:"-" json:"-"`
}

View File

@ -22,7 +22,7 @@ import (
)
func init() {
rand.Seed(time.Now().Nano())
rand.Seed(time.Now().UnixNano())
}
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"