You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB
Go

package timez
import (
"joybuywork/internal/consts"
"joybuywork/internal/utils"
"testing"
"time"
"github.com/golang-module/carbon/v2"
)
func TestName(t *testing.T) {
f, _ := time.ParseInLocation("2006-01-02 15:04:05", "2024-08-07 00:00:00", time.FixedZone(consts.CampaignTz, 8*3600))
//f, _ := time.Parse("2006-01-02 15:04:05", "2024-08-07 00:00:00")
t.Log(f, f.Unix())
var of int32 = 9
start := carbon.CreateFromTimestamp(f.Unix())
start1 := GMTCarbon(of).CreateFromTimestamp(f.Unix())
s := GMT(carbon.Parse(start1.ToShortDateString()).Timestamp(), of)
e := GMT(carbon.Parse(start1.ToShortDateString()).EndOfDay().Timestamp(), of)
day, s1, e1 := GMTStartAndEndTs(of, f.Unix())
t.Log(start.ToDateTimeString(), start1.ToDateTimeString(), carbon.CreateFromTimestamp(s).ToDateTimeString(), carbon.CreateFromTimestamp(e).ToDateTimeString())
t.Log(day, carbon.CreateFromTimestamp(s1).ToDateTimeString(), carbon.CreateFromTimestamp(e1).ToDateTimeString())
}
func TestWeekend(t *testing.T) {
start, end := getWeekEnd(4)
st := GMTTime(8, start)
et := GMTTime(8, end)
t.Log(st.Format(time.DateTime), et.Format(time.DateTime))
}
func getWeekEnd(weekNum int32) (start, end int64) {
t, _ := GMTTimeStart(8)
w := utils.Ternary[int32](t.Weekday() == 0, 7, int32(t.Weekday()))
var ws int64 = 7 * 86400
if w < weekNum {
end = t.Unix() + int64((weekNum-w)*86400)
} else {
end = t.Unix() + int64((7-(w-weekNum))*86400)
}
return end - ws, end
}