Skip to content

Commit 9467fee

Browse files
committed
fix range initialize
1 parent 57cbf07 commit 9467fee

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

internal/getters/date.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ type RandomDateInRange struct {
4242
}
4343

4444
func (r *RandomDateInRange) Value() interface{} {
45-
rand.Seed(time.Now().UnixNano())
46-
var randomSeconds int64
47-
randomSeconds = rand.Int63n(oneYear) + rand.Int63n(100)
45+
randomSeconds := rand.Int63n(oneYear) + rand.Int63n(100)
4846
d := time.Now().Add(-1 * time.Duration(randomSeconds) * time.Second)
4947
return d
5048
}

internal/getters/datetime.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
)
88

99
type RandomDateTimeInRange struct {
10+
name string
1011
min string
1112
max string
1213
allowNull bool
1314
}
1415

1516
// Value returns a random time.Time in the range specified by the New method
1617
func (r *RandomDateTimeInRange) Value() interface{} {
17-
rand.Seed(time.Now().UnixNano())
1818
randomSeconds := rand.Int63n(oneYear)
1919
d := time.Now().Add(-1 * time.Duration(randomSeconds) * time.Second)
2020
return d
@@ -32,15 +32,15 @@ func (r *RandomDateTimeInRange) Quote() string {
3232
}
3333

3434
// NewRandomDateTimeInRange returns a new random date in the specified range
35-
func NewRandomDateTimeInRange(name string, min, max string, allowNull bool) *RandomDateInRange {
35+
func NewRandomDateTimeInRange(name string, min, max string, allowNull bool) *RandomDateTimeInRange {
3636
if min == "" {
3737
t := time.Now().Add(-1 * time.Duration(oneYear) * time.Second)
38-
min = t.Format("2006-01-02")
38+
min = t.Format("2006-01-02 15:03:04")
3939
}
40-
return &RandomDateInRange{name, min, max, allowNull}
40+
return &RandomDateTimeInRange{name, min, max, allowNull}
4141
}
4242

4343
// NewRandomDateTime returns a new random datetime between Now() and Now() - 1 year
44-
func NewRandomDateTime(name string, allowNull bool) *RandomDateInRange {
45-
return &RandomDateInRange{name, "", "", allowNull}
44+
func NewRandomDateTime(name string, allowNull bool) *RandomDateTimeInRange {
45+
return &RandomDateTimeInRange{name, "", "", allowNull}
4646
}

internal/getters/getters.go

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

3+
import (
4+
"math/rand"
5+
"time"
6+
)
7+
38
// All types defined here satisfy the Getter interface
49
// type Getter interface {
510
// Value() interface{}
@@ -12,3 +17,7 @@ const (
1217
oneYear = int64(60 * 60 * 24 * 365)
1318
NULL = "NULL"
1419
)
20+
21+
func init() {
22+
rand.Seed(time.Now().UnixMicro())
23+
}

0 commit comments

Comments
 (0)