You don't have to use UTC if you know the time.Location in the following example.
import "time"
// Date represents a UTC time zone day
type Date struct {
Year int
Month int
Day int
}
// ToGoTime turns the date into UTC time.Time, at the 0 hrs 0 min 0 second start of the day.
func (d *Date) ToGoTime() time.Time {
return time.Date(d.Year, time.Month(d.Month), d.Day, 0, 0, 0, 0, time.UTC)
}
func DaysBetweenAminusB(a, b *Date) int {
return int(int64(a.ToGoTime().Sub(b.ToGoTime())) / int64(time.Hour*24))
}
e.g.
import "fmt"
import "time"
var d Date
var NYC *time.Location
NYC, err = tz.LoadLocation("America/New_York")
if err != nil {panic(err)}
hr := 12 // noon
min := 0
sec := 0
msec := 0
tm := time.Date(d.Year, time.Month(d.Month), d.Day, hr, min, sec, msec*1e6, NYC)
fmt.Printf("%v", tm.In(NYC).Format(time.RFC3339Nano))