-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.go
42 lines (36 loc) · 1.04 KB
/
add.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
package vtime
import "time"
func (v Time) Add(x int64, unit string) Time {
t := tt(v)
switch unit {
case "ns", "nanosecond", "nanoseconds":
t = t.Add(time.Duration(x) * time.Nanosecond)
case "us", "microsecond", "microseconds":
t = t.Add(time.Duration(x) * time.Microsecond)
case "ms", "millisecond", "milliseconds":
t = t.Add(time.Duration(x) * time.Millisecond)
case "s", "second", "seconds":
t = t.Add(time.Duration(x) * time.Second)
case "m", "minute", "minutes":
t = t.Add(time.Duration(x) * time.Minute)
case "h", "hour", "hours":
t = t.Add(time.Duration(x) * time.Hour)
case "d", "day", "days":
t = t.Add(time.Duration(x) * 24 * time.Hour)
case "w", "week", "weeks":
t = t.Add(time.Duration(x) * 7 * 24 * time.Hour)
case "y", "year", "years":
t = t.AddDate(int(x), 0, 0)
case "M", "month", "months":
t = t.AddDate(0, int(x), 0)
default:
return v
}
return ft(t)
}
func (v Time) Subtract(x int64, unit string) Time {
return v.Add(-x, unit)
}
func (v Time) AddDuration(d time.Duration) Time {
return ft(tt(v).Add(d))
}