-
Notifications
You must be signed in to change notification settings - Fork 30
/
time_data.go
66 lines (58 loc) · 1.9 KB
/
time_data.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package gokeepasslib
import (
w "github.com/tobischo/gokeepasslib/v3/wrappers"
)
type TimeDataOption func(*TimeData)
func WithTimeDataFormattedTime(formatted bool) TimeDataOption {
return func(td *TimeData) {
td.CreationTime.Formatted = formatted
td.LastModificationTime.Formatted = formatted
td.LastAccessTime.Formatted = formatted
td.LocationChanged.Formatted = formatted
td.Expires = w.NewBoolWrapper(false)
}
}
// TimeData contains all metadata related to times for groups and entries
// e.g. the last modification time or the creation time
type TimeData struct {
CreationTime *w.TimeWrapper `xml:"CreationTime"`
LastModificationTime *w.TimeWrapper `xml:"LastModificationTime"`
LastAccessTime *w.TimeWrapper `xml:"LastAccessTime"`
ExpiryTime *w.TimeWrapper `xml:"ExpiryTime"`
Expires w.BoolWrapper `xml:"Expires"`
UsageCount int64 `xml:"UsageCount"`
LocationChanged *w.TimeWrapper `xml:"LocationChanged"`
}
func (td *TimeData) setKdbxFormatVersion(version formatVersion) {
if td.CreationTime != nil {
td.CreationTime.Formatted = !isKdbx4(version)
}
if td.LastModificationTime != nil {
td.LastModificationTime.Formatted = !isKdbx4(version)
}
if td.LastAccessTime != nil {
td.LastAccessTime.Formatted = !isKdbx4(version)
}
if td.ExpiryTime != nil {
td.ExpiryTime.Formatted = !isKdbx4(version)
}
if td.LocationChanged != nil {
td.LocationChanged.Formatted = !isKdbx4(version)
}
}
// NewTimeData returns a TimeData struct with good defaults (no expire time, all times set to now)
func NewTimeData(options ...TimeDataOption) TimeData {
now := w.Now()
td := TimeData{
CreationTime: &now,
LastModificationTime: &now,
LastAccessTime: &now,
LocationChanged: &now,
Expires: w.NewBoolWrapper(false),
UsageCount: 0,
}
for _, option := range options {
option(&td)
}
return td
}