跨周根据所在时区计算日期
This commit is contained in:
parent
7688583735
commit
70768089da
|
|
@ -76,17 +76,15 @@ func InSameWeek(tNow, tPre time.Time) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
preYear, preWeek := tPre.ISOWeek()
|
if GetWeekStartTs(tNow.Unix()) == GetWeekStartTs(tPre.Unix()) {
|
||||||
nowYear, nowWeek := tNow.ISOWeek()
|
|
||||||
if preYear == nowYear && preWeek == nowWeek {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func TsInSameWeek(tsNow, tsPre int64) bool {
|
func TsInSameWeek(tsNow, tsPre int64) bool {
|
||||||
tNow := time.Unix(tsNow, 0)
|
tNow := time.Unix(tsNow, 0).Local()
|
||||||
tPre := time.Unix(tsPre, 0)
|
tPre := time.Unix(tsPre, 0).Local()
|
||||||
return InSameWeek(tNow, tPre)
|
return InSameWeek(tNow, tPre)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,22 +142,16 @@ func InTimeRange(beginHour, beginMinute, endHour, endMinute, checkHour, checkMin
|
||||||
return beginTime <= checkTime && checkTime <= endTime
|
return beginTime <= checkTime && checkTime <= endTime
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetWeekTimestamp() []int64 {
|
// GetWeekStartTs 获取本周开始的时间戳,周一为周的开始
|
||||||
now := time.Now().Local()
|
|
||||||
year, month, day := now.Date()
|
|
||||||
today := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
|
|
||||||
// 本周起始日期(周日)
|
|
||||||
st := today.AddDate(0, 0, -int(today.Weekday())).Unix()
|
|
||||||
et := today.AddDate(0, 0, 7-int(today.Weekday())).Unix()
|
|
||||||
return []int64{st, et}
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetWeekStartTs(ts int64) int64 {
|
func GetWeekStartTs(ts int64) int64 {
|
||||||
now := time.Unix(ts, 0).Local()
|
now := time.Unix(ts, 0).Local()
|
||||||
year, month, day := now.Date()
|
year, month, day := now.Date()
|
||||||
today := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
|
today := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
|
||||||
// 本周起始日期(周日)
|
n := today.Weekday()
|
||||||
st := today.AddDate(0, 0, -int(today.Weekday())).Unix()
|
if today.Weekday() == 0 {
|
||||||
|
n = 7
|
||||||
|
}
|
||||||
|
st := today.AddDate(0, 0, -int(n-1)).Unix()
|
||||||
return st
|
return st
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ func (b *BindScoreSvc) GetInviteList(req *model.InviteLisArgs, ret *model.Invite
|
||||||
|
|
||||||
now := time.Now().Local()
|
now := time.Now().Local()
|
||||||
for _, v := range res {
|
for _, v := range res {
|
||||||
if !common.InSameWeek(now, v.IScoreTs) {
|
if !common.InSameWeek(now, v.IScoreTs.Local()) {
|
||||||
v.IScore = 0
|
v.IScore = 0
|
||||||
}
|
}
|
||||||
roleId := common.DefaultRoleId
|
roleId := common.DefaultRoleId
|
||||||
|
|
|
||||||
|
|
@ -2269,6 +2269,7 @@ func (this *Player) OnMonthTimer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Player) OnWeekTimer() {
|
func (this *Player) OnWeekTimer() {
|
||||||
|
logger.Logger.Tracef("OnWeekTimer %v", time.Now())
|
||||||
//判断是否一天即可过滤0点多次切换
|
//判断是否一天即可过滤0点多次切换
|
||||||
if common.InSameDayNoZero(time.Now().Local(), this.lastOnWeekChange) {
|
if common.InSameDayNoZero(time.Now().Local(), this.lastOnWeekChange) {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue