mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-15 15:37:33 +08:00
support setting the last 1 to 3 days of the month to scheduled transaction frequency
This commit is contained in:
@@ -286,6 +286,12 @@ func IsUnixTimeEqualsYearAndMonth(unixTime int64, timezone *time.Location, year
|
||||
return date.Year() == int(year) && int(date.Month()) == int(month)
|
||||
}
|
||||
|
||||
// GetMaxDayOfMonth returns the maximum day of the month for the specified year and month
|
||||
func GetMaxDayOfMonth(year int, month time.Month) int {
|
||||
t := time.Date(year, month+1, 0, 0, 0, 0, 0, time.UTC)
|
||||
return t.Day()
|
||||
}
|
||||
|
||||
// GetTimezoneOffsetMinutes returns offset minutes according specified timezone
|
||||
func GetTimezoneOffsetMinutes(unixTime int64, timezone *time.Location) int16 {
|
||||
_, tzOffset := parseFromUnixTime(unixTime).In(timezone).Zone()
|
||||
|
||||
@@ -333,6 +333,32 @@ func TestIsUnixTimeEqualsYearAndMonth(t *testing.T) {
|
||||
assert.Equal(t, false, actualValue)
|
||||
}
|
||||
|
||||
func TestGetMaxDayOfMonth(t *testing.T) {
|
||||
expectedValue := 31
|
||||
actualValue := GetMaxDayOfMonth(2023, 1)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
expectedValue = 28
|
||||
actualValue = GetMaxDayOfMonth(2023, 2)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
expectedValue = 29
|
||||
actualValue = GetMaxDayOfMonth(2024, 2)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
expectedValue = 30
|
||||
actualValue = GetMaxDayOfMonth(2023, 4)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
expectedValue = 31
|
||||
actualValue = GetMaxDayOfMonth(2023, 12)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
|
||||
expectedValue = 28
|
||||
actualValue = GetMaxDayOfMonth(2100, 2)
|
||||
assert.Equal(t, expectedValue, actualValue)
|
||||
}
|
||||
|
||||
func TestGetTimezoneOffsetMinutes_FixedTimezone(t *testing.T) {
|
||||
timezone := time.FixedZone("Test Timezone", 120*60)
|
||||
expectedValue := int16(120)
|
||||
|
||||
Reference in New Issue
Block a user