Skip to content

Commit fc92dd7

Browse files
authored
fix: allow 366 days so clients don't need to care about leap years (#43)
1 parent 7c7c43b commit fc92dd7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

internal/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func (s *service) getAccountStats(
265265
return stats, err
266266
}
267267

268-
const maxPeriodDays = 365
268+
const maxPeriodDays = 366
269269

270270
// defaultPeriod returns a period from the first day of the last complete month to today
271271
func defaultPeriod() Period {

internal/service/service_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func TestGetAccountEgress(t *testing.T) {
244244
require.ErrorAs(t, err, &periodErr)
245245
})
246246

247-
t.Run("returns period not acceptable error when period exceeds 365 days", func(t *testing.T) {
247+
t.Run("returns period not acceptable error when period exceeds 366 days", func(t *testing.T) {
248248
accountDID := testutil.RandomDID(t)
249249
space := testutil.RandomDID(t)
250250

@@ -266,7 +266,7 @@ func TestGetAccountEgress(t *testing.T) {
266266
}
267267

268268
from := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC)
269-
to := time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC) // 366 days
269+
to := time.Date(2025, 1, 2, 0, 0, 0, 0, time.UTC) // 367 days
270270
period := &Period{From: from, To: to}
271271

272272
result, err := svc.GetAccountEgress(context.Background(), accountDID, nil, period)
@@ -275,7 +275,7 @@ func TestGetAccountEgress(t *testing.T) {
275275
require.Nil(t, result)
276276
var periodErr ErrPeriodNotAcceptable
277277
require.ErrorAs(t, err, &periodErr)
278-
assert.Contains(t, periodErr.msg, "365 days")
278+
assert.Contains(t, periodErr.msg, "366 days")
279279
})
280280

281281
t.Run("successfully returns empty result for account with no spaces", func(t *testing.T) {

0 commit comments

Comments
 (0)