This commit is contained in:
2025-06-03 05:04:18 +03:00
parent 0f50873f0f
commit fbb30f31e8
54 changed files with 13234 additions and 0 deletions

39
timeutil/timeutil.go Normal file
View File

@@ -0,0 +1,39 @@
package timeutil
import "time"
func FirstSecondInPeriod(since time.Time, period string) (_ time.Time) {
y, m, d := since.Date()
switch period {
case "h":
h := since.Hour()
return time.Date(y, m, d, h, 0, 0, 0, time.Local)
case "d":
return time.Date(y, m, d, 0, 0, 0, 0, time.Local)
case "m":
return time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
default:
return since
}
}
func LastSecondInPeriod(until time.Time, period string) (_ time.Time) {
y, m, d := until.Date()
switch period {
case "h":
h := until.Hour()
return time.Date(y, m, d, h, 59, 59, 0, time.Local)
case "d":
return time.Date(y, m, d, 23, 59, 59, 0, time.Local)
case "m":
tm := time.Date(y, m, 1, 23, 59, 59, 0, time.Local)
// Додаю місяць
tm = tm.AddDate(0, 1, 0)
// Віднімаю день
return tm.AddDate(0, 0, -1)
default:
return until
}
}