1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 21:15:56 +00:00

add x/timex.GetMonthDays, GetMonthEnd and x/jsonx.SimpleDates type and x/jsonx.GetSimpleDateRange function

This commit is contained in:
Gerasimos (Makis) Maropoulos
2023-12-30 13:23:59 +02:00
parent c80c5903ab
commit b727f4b143
6 changed files with 340 additions and 183 deletions

View File

@@ -116,6 +116,18 @@ func GetMonthStart(now time.Time) time.Time {
return time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
}
// GetMonthEnd returns the date of the last month day of the current now's month.
func GetMonthEnd(now time.Time) time.Time {
now = now.UTC()
// Add one month to the current date and subtract one day
return time.Date(now.Year(), now.Month()+1, 0, 0, 0, 0, 0, now.Location())
}
// GetMonthDays returns the range between first and last days the current month.
func GetMonthDays(now time.Time) (dates []time.Time) {
return Between(GetMonthStart(now), GetMonthEnd(now))
}
// GetYearStart returns the date of the first year of the current now's year.
func GetYearStart(now time.Time) time.Time {
return time.Date(now.Year(), 1, 1, 0, 0, 0, 0, now.Location())