Skip to content

Instantly share code, notes, and snippets.

@ashkan90
Created March 25, 2020 23:00
Show Gist options
  • Save ashkan90/7fe9edc8802f23cc07d2650371b1c480 to your computer and use it in GitHub Desktop.
Save ashkan90/7fe9edc8802f23cc07d2650371b1c480 to your computer and use it in GitHub Desktop.
basic functionallity with time struct
package macro
import "time"
type TimeType uint
type Offset string
const (
Daily = iota
Weekly
Monthly
Yearly
)
type RTime struct {
DayStart Offset
DayEnd Offset
}
func NewRTime() RTime {
return RTime{
DayStart: "",
DayEnd: "",
}
}
func (o *Offset) AddYear(year int) {
*o = Offset( addByType(year, Yearly))
}
func (o *Offset) AddMonth(month int) {
*o = Offset( addByType(month, Monthly))
}
func (o *Offset) AddWeek(week int) {
*o = Offset( addByType(week, Weekly))
}
func (o *Offset) AddDay(day int) {
*o = Offset( addByType(day, Daily))
}
func addByType(amount int, timeType TimeType) string {
var _time string
switch timeType {
case Daily:
_time = time.Now().AddDate(0, 0, amount).String()
break
case Weekly:
_time = time.Now().AddDate(0, 0, amount * 7).String()
break
case Monthly:
_time = time.Now().AddDate(0, amount, 0).String()
break
case Yearly:
_time = time.Now().AddDate(amount, 0, 0).String()
break
}
return _time
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment