fix daylight saving time is not calculated correctly when checking whether a transaction can be edited

This commit is contained in:
MaysWind
2025-12-25 00:56:39 +08:00
parent 842683da25
commit 6bb69b0c27
3 changed files with 25 additions and 9 deletions
+6
View File
@@ -414,6 +414,12 @@ func GetTransactionTimeRangeByYearMonth(year int32, month int32) (int64, int64,
return minTransactionTime, maxTransactionTime, nil
}
// GetStartOfDay returns the start time of the day for the specified time
func GetStartOfDay(t time.Time) time.Time {
year, month, day := t.Date()
return time.Date(year, month, day, 0, 0, 0, 0, t.Location())
}
// parseFromUnixTime parses a unix time and returns a golang time struct
func parseFromUnixTime(unixTime int64) time.Time {
return time.Unix(unixTime, 0)
+10
View File
@@ -516,6 +516,16 @@ func TestGetTransactionTimeRangeByYearMonth(t *testing.T) {
assert.Equal(t, expectedMaxValue, actualMaxValue)
}
func TestGetStartOfDay(t *testing.T) {
expectedValue := int64(1617148800) // 2021-03-31 00:00:00 UTC
actualValue := GetStartOfDay(time.Unix(1617228083, 0).In(time.UTC))
assert.Equal(t, expectedValue, actualValue.Unix())
expectedValue = int64(1617206400) // 2021-04-01 00:00:00 UTC+8
actualValue = GetStartOfDay(time.Unix(1617228083, 0).In(time.FixedZone("Test Timezone", 28800)))
assert.Equal(t, expectedValue, actualValue.Unix())
}
func TestParseFromUnixTime(t *testing.T) {
expectedValue := int64(1617228083)
actualTime := parseFromUnixTime(expectedValue)