ref: f79a9d09c451653ff27fb34afb5b0c71dc758a32
server/dates/ranges.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 |
package dates import ( "fmt" "time" ) type DaysRange struct { From string To string } func CalculateFullDay(t time.Time) DaysRange { yesterday := t.AddDate(0, 0, -1) tomorrow := t.AddDate(0, 0, +1) fmt.Println("today YYYY-MM-DD : ", t.Format("2006-02-01")) fmt.Println("tomorrow YYYY-MM-DD : ", tomorrow.Format("2006-02-01")) return DaysRange{yesterday.Format("2006-02-01"), t.Format("2006-02-01")} } func CalculateFullDayNDaysAgo(n int) DaysRange { t := time.Now().AddDate(0, 0, -n) yesterday := t.AddDate(0, 0, -1) tomorrow := t.AddDate(0, 0, +1) fmt.Println("today YYYY-MM-DD : ", t.Format("2006-02-01")) fmt.Println("tomorrow YYYY-MM-DD : ", tomorrow.Format("2006-02-01")) return DaysRange{yesterday.Format("2006-02-01"), t.Format("2006-02-01")} } |