40 lines
1000 B
Go
40 lines
1000 B
Go
|
|
package app
|
||
|
|
|
||
|
|
import (
|
||
|
|
"sync"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
const monitoringBusinessTimeZoneName = "Asia/Shanghai"
|
||
|
|
|
||
|
|
var (
|
||
|
|
monitoringBusinessLocationOnce sync.Once
|
||
|
|
monitoringBusinessLocationValue *time.Location
|
||
|
|
)
|
||
|
|
|
||
|
|
func monitoringBusinessLocation() *time.Location {
|
||
|
|
monitoringBusinessLocationOnce.Do(func() {
|
||
|
|
loc, err := time.LoadLocation(monitoringBusinessTimeZoneName)
|
||
|
|
if err != nil {
|
||
|
|
monitoringBusinessLocationValue = time.FixedZone("UTC+8", 8*60*60)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
monitoringBusinessLocationValue = loc
|
||
|
|
})
|
||
|
|
|
||
|
|
return monitoringBusinessLocationValue
|
||
|
|
}
|
||
|
|
|
||
|
|
func monitoringCanonicalBusinessDay(day time.Time) time.Time {
|
||
|
|
return monitoringBusinessDayAt(day, monitoringBusinessLocation())
|
||
|
|
}
|
||
|
|
|
||
|
|
func monitoringBusinessDayAndDateAt(now time.Time) (time.Time, string) {
|
||
|
|
businessDay := monitoringCanonicalBusinessDay(now)
|
||
|
|
return businessDay, businessDay.Format("2006-01-02")
|
||
|
|
}
|
||
|
|
|
||
|
|
func monitoringBusinessDateText(businessDay time.Time) string {
|
||
|
|
return monitoringCanonicalBusinessDay(businessDay).Format("2006-01-02")
|
||
|
|
}
|