From 9b60ddba27ef778419da5089e3b30ebe173afd7d Mon Sep 17 00:00:00 2001 From: yinbentan <yinbentan@live.com> Date: 星期五, 28 六月 2024 14:24:35 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/jialian' into jialian --- utils/util.go | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) diff --git a/utils/util.go b/utils/util.go index 61c9c1c..c1b4d52 100644 --- a/utils/util.go +++ b/utils/util.go @@ -3,9 +3,31 @@ import ( "github.com/google/uuid" "strings" + "time" ) func GetUUID() string { s := uuid.New().String() return strings.ReplaceAll(s, "-", "") } + +// GetLastMonthPeriod 杩斿洖涓婁釜鏈堢殑鏈堝垵鏃堕棿鍜屾湀鏈椂闂� +func GetLastMonthPeriod() (time.Time, time.Time) { + // 鑾峰彇褰撳墠鏃堕棿 + now := time.Now() + + // 璁$畻涓婁釜鏈堢殑骞翠唤鍜屾湀浠� + lastMonth := now.AddDate(0, -1, 0) + lastYear, lastMonthNum, _ := lastMonth.Date() + + // 鑾峰彇涓婁釜鏈堢殑绗竴澶╃殑鏃ユ湡锛堝嵆涓婁釜鏈堟湀鍒濓級 + firstDayOfLastMonth := time.Date(lastYear, lastMonthNum, 1, 0, 0, 0, 0, now.Location()) + + // 鑾峰彇鏈湀绗竴澶╃殑鏃ユ湡锛堝嵆鏈湀鏈堝垵锛� + firstDayOfThisMonth := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()) + + // 涓婁釜鏈堟湀鏈椂闂村嵆涓烘湰鏈堟湀鍒濆噺鍘讳竴绉� + lastDayOfLastMonth := firstDayOfThisMonth.Add(-time.Second) + + return firstDayOfLastMonth, lastDayOfLastMonth +} -- Gitblit v1.8.0