@@ -93,7 +93,14 @@ func relativeWeekday(t time.Time, weekday time.Weekday) (time.Time, error) {
93
93
// computes the relative time in days from time returning a new
94
94
// time and error.
95
95
func RelativeTime (t time.Time , i int , u string ) (time.Time , error ) {
96
+ //NOTE: Month needs to come before Monday.
96
97
switch {
98
+ case strings .HasPrefix (u , "year" ):
99
+ return t .AddDate (i , 0 , 0 ), nil
100
+ case strings .HasPrefix (u , "month" ):
101
+ return t .AddDate (0 , i , 0 ), nil
102
+ case strings .HasPrefix (u , "week" ):
103
+ return t .AddDate (0 , 0 , 7 * i ), nil
97
104
case strings .HasPrefix (u , "sun" ):
98
105
return relativeWeekday (t , time .Sunday )
99
106
case strings .HasPrefix (u , "mon" ):
@@ -110,12 +117,6 @@ func RelativeTime(t time.Time, i int, u string) (time.Time, error) {
110
117
return relativeWeekday (t , time .Saturday )
111
118
case strings .HasPrefix (u , "day" ):
112
119
return t .AddDate (0 , 0 , i ), nil
113
- case strings .HasPrefix (u , "week" ):
114
- return t .AddDate (0 , 0 , 7 * i ), nil
115
- case strings .HasPrefix (u , "month" ):
116
- return t .AddDate (0 , i , 0 ), nil
117
- case strings .HasPrefix (u , "year" ):
118
- return t .AddDate (i , 0 , 0 ), nil
119
120
}
120
121
return t , errors .New ("Time unit must be day(s), week(s), month(s) or year(s) or weekday name." )
121
122
}
0 commit comments