package datarange import ( "git.ichub.com/general/webcli120/goconfig/base/basedto" "time" ) type DateRangeAll struct { basedto.BaseEntity DateRangeStr *DateRangeStr DateRange *DateRange DateRangeGtime *DateRangeGtime } func NewDataRangeAll() *DateRangeAll { var dr = &DateRangeAll{} dr.InitProxy(dr) return dr } func DefaultAll(start, end string) *DateRangeAll { var dr = NewDataRangeAll() dr.DateRangeStr = DefaultRangeOf(start, end) dr.DateRange, _ = dr.DateRangeStr.ToDateRange() dr.DateRangeGtime, _ = dr.DateRangeStr.ToGtime() return dr } func DefaultAllDate(start, end time.Time) *DateRangeAll { var dr = NewDataRangeAll() dr.DateRange = NewDateRange() dr.DateRange.Start = start dr.DateRange.End = end dr.DateRangeStr = dr.DateRange.ToDateRangeStr() return dr } func (self DateRangeAll) ToEsDateRange() *DateRangeStr { return self.DateRangeGtime.ToEsDateRange() } func (self *DateRangeAll) BeforeDay() *DateRangeAll { var c = *self c.DateRange = c.DateRange.BeforeDay() return &c } func (self *DateRangeAll) YesterDay() *DateRangeAll { var c = *self c.DateRange = c.DateRange.YesterDay() return &c } func (self *DateRangeAll) Tommorow() *DateRangeAll { var c = *self c.DateRange = c.DateRange.Tommorow() return &c }
package datarange import ( "git.ichub.com/general/webcli120/goconfig/base/basedto" "github.com/gogf/gf/v2/os/gtime" "icd/utils" "time" ) type DateRange struct { basedto.BaseEntity Start time.Time End time.Time } func NewDateRange() *DateRange { var dr = &DateRange{} dr.InitProxy(dr) return dr } func (self *DateRange) Yesterday() DateRange { return DateRange{} } func (self *DateRange) DayBefore() DateRange { return DateRange{} } func (self *DateRange) ToDateRangeStr() *DateRangeStr { var strday = FindBeanDateRangeStr() strday.Start = gtime.NewFromTime(self.Start).Layout("2006-01-02") strday.End = gtime.NewFromTime(self.End).Layout("2006-01-02") return strday } func (self *DateRange) ToId(memberId int64) string { return self.Start.Format("2006-01-02") + "|" + utils.FormatInt(memberId) + "|0|0" } func (self *DateRange) Clone() *DateRange { var c = *self return &c } func (self DateRange) BeforeDay() *DateRange { var c = self.Clone() c.Start = c.Start.Add(-48 * time.Hour) c.End = c.End.Add(-48 * time.Hour) return c } func (self DateRange) YesterDay() *DateRange { var c = self.Clone() c.Start = c.Start.Add(-24 * time.Hour) c.End = c.End.Add(-24 * time.Hour) return c } func (self DateRange) Tommorow() *DateRange { var c = self.Clone() c.Start = c.Start.Add(24 * time.Hour) c.End = c.End.Add(24 * time.Hour) return c }
package datarange import ( "git.ichub.com/general/webcli120/goconfig/base/basedto" "github.com/gogf/gf/v2/os/gtime" ) type DateRangeStr struct { basedto.BaseEntity Start string End string } func NewDateRangeStr() *DateRangeStr { return &DateRangeStr{} } func DefaultRangeOf(start, end string) *DateRangeStr { var dr = &DateRangeStr{ Start: start, End: end, } dr.InitProxy(dr) return dr } //start, _ := time.ParseInLocation("2006-01-02", "2024-12-03", time.Local) //end, _ := time.ParseInLocation("2006-01-02", "2024-12-03", time.Local) func (self *DateRangeStr) ToGtime() (*DateRangeGtime, error) { var gt = FindBeanDateRangeGtime() var start, err = gtime.StrToTimeLayout(self.Start, "2006-01-02") if err != nil { return gt, err } gt.Start = start gt.End, err = gtime.StrToTimeLayout(self.End, "2006-01-02") //gt.Start.ToZone() return gt, err } func (self *DateRangeStr) ToDateRange() (*DateRange, error) { var dr = FindBeanDateRange() var gdr, err = self.ToGtime() if err != nil { return dr, err } dr.Start = gdr.Start.Time dr.End = gdr.End.Time return dr, nil }标签:return,DateRange,根与值,Start,func,go,dr,self From: https://blog.csdn.net/leijmdas/article/details/144214951