Skip to content

Commit

Permalink
Fix date format
Browse files Browse the repository at this point in the history
  • Loading branch information
fre5h committed Mar 7, 2023
1 parent a7c242c commit 11bb699
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ func main() {
###### bash

```text
$ go get "github.com/fre5h/rnokpp"@v1.1.1
go: downloading github.com/fre5h/rnokpp v1.1.1
go: added github.com/fre5h/rnokpp v1.1.1
$ go get "github.com/fre5h/rnokpp"@v1.1.2
go: downloading github.com/fre5h/rnokpp v1.1.2
go: added github.com/fre5h/rnokpp v1.1.2
$ go run main.go
details: valid, male, 01.01.2000
Expand Down
4 changes: 2 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ type ErrNotAllowedDate struct {
}

func (e *ErrNotAllowedDate) Error() string {
return fmt.Sprintf("the allowed dates start from 01.01.1900, but your date %s is earlier", e.Date.Format("02.04.2006"))
return fmt.Sprintf("the allowed dates start from 01.01.1900, but your date %s is earlier", e.Date.Format("02.01.2006"))
}

type ErrDateInFuture struct {
Date time.Time
}

func (e *ErrDateInFuture) Error() string {
return fmt.Sprintf("it is allowed to use only dates in past or current date, but your date is in the future %s", e.Date.Format("02.04.2006"))
return fmt.Sprintf("it is allowed to use only dates in past or current date, but your date is in the future %s", e.Date.Format("02.01.2006"))
}
4 changes: 2 additions & 2 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestErrNotAllowedDate(t *testing.T) {
date, _ := time.Parse("02.04.2006", "31.12.1899")
date, _ := time.Parse("02.01.2006", "31.12.1899")
x := &rnokpp.ErrNotAllowedDate{Date: date}

if x.Error() != "the allowed dates start from 01.01.1900, but your date 31.12.1899 is earlier" {
Expand All @@ -17,7 +17,7 @@ func TestErrNotAllowedDate(t *testing.T) {
}

func TestErrDateInFuture(t *testing.T) {
date, _ := time.Parse("02.04.2006", "01.01.3000")
date, _ := time.Parse("02.01.2006", "01.01.3000")
x := &rnokpp.ErrDateInFuture{Date: date}

if x.Error() != "it is allowed to use only dates in past or current date, but your date is in the future 01.01.3000" {
Expand Down
2 changes: 1 addition & 1 deletion internal/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestGenerateRandomDate(t *testing.T) {
for i := 0; i < 1000; i++ {
date := internal.GenerateRandomDate()
if date.Before(internal.BaseDate) || date.After(time.Now()) {
t.Errorf("Invalid generated date %s\"%s\"%s", red, date.Format("02.04.2006"), reset)
t.Errorf("Invalid generated date %s\"%s\"%s", red, date.Format("02.01.2006"), reset)
}
}
}
2 changes: 1 addition & 1 deletion rnokpp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestGetGender(t *testing.T) {
}

func TestGenerateRnokpp(t *testing.T) {
oldDate, _ := time.Parse("02.04.2006", "31.12.1899")
oldDate, _ := time.Parse("02.01.2006", "31.12.1899")
if _, err := rnokpp.GenerateRnokpp(oldDate, rnokpp.Male); err == nil {
t.Error("Expected error for too old date")
}
Expand Down

0 comments on commit 11bb699

Please sign in to comment.