Skip to content

Commit c601dca

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 604ba4d + 49c1581 commit c601dca

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

schema/json/generator/date.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package generator
22

33
import (
4-
"github.com/brianvoe/gofakeit/v6"
54
"time"
5+
6+
"github.com/brianvoe/gofakeit/v6"
67
)
78

89
func dates() []*Node {
@@ -155,13 +156,17 @@ func fakeDateWithYearRange(r *Request, min time.Time, maxYear int) (any, error)
155156
year := gofakeit.IntRange(min.Year(), maxYear)
156157
minMonth := int(min.Month())
157158
month := gofakeit.Number(minMonth, 12)
158-
if year == time.Now().Year() {
159-
month = gofakeit.Number(minMonth, 12)
160-
}
161159
minDay := min.Day() + 1
162160
if minDay > maxDayInMonth[month-1] {
163161
minDay = 1
164-
month += 1
162+
if month == 12 {
163+
month = 1
164+
if year == min.Year() {
165+
year++
166+
}
167+
} else {
168+
month += 1
169+
}
165170
}
166171
day := gofakeit.Number(minDay, maxDayInMonth[month-1])
167172

schema/json/generator/date_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package generator
22

33
import (
44
"mokapi/schema/json/schema/schematest"
5+
"strings"
56
"testing"
67
"time"
78

@@ -168,3 +169,10 @@ func TestStringDate(t *testing.T) {
168169
})
169170
}
170171
}
172+
173+
func TestFakeDateWithYearRange_NewYearsEve(t *testing.T) {
174+
r, err := fakeDateWithYearRange(&Request{}, time.Date(2026, 12, 31, 0, 0, 0, 0, time.UTC), 2027)
175+
require.NoError(t, err)
176+
require.NotEqual(t, "", r)
177+
require.True(t, strings.HasPrefix(r.(string), "2027"))
178+
}

0 commit comments

Comments
 (0)