Skip to content

Commit

Permalink
ensure that clock returns time in local format
Browse files Browse the repository at this point in the history
  • Loading branch information
adamluzsi committed Jun 10, 2023
1 parent 960a0df commit 4c49fb4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clock/Clock.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TimeNow() time.Time {
return internal.GetTime()
return internal.GetTime().Local()
}

func Sleep(d time.Duration) {
Expand Down
17 changes: 17 additions & 0 deletions clock/Clock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package clock_test

import (
"context"
"github.com/adamluzsi/testcase/let"
"testing"
"time"

Expand Down Expand Up @@ -45,6 +46,22 @@ func TestTimeNow(t *testing.T) {
it.Must.True(next.After(now))
})
})

s.And("time moved to a specific time given in non-local format", func(s *testcase.Spec) {
expTime := let.Time(s)

s.Before(func(t *testcase.T) {
timecop.Travel(t, expTime.Get(t).UTC(), timecop.Freeze())
})

s.Then("the time it just returned in the same Local as time.Now()", func(t *testcase.T) {
t.Must.Equal(time.Now().Location(), act(t).Location())
})

s.Then("the time is what Travel set", func(t *testcase.T) {
t.Must.True(expTime.Get(t).Equal(act(t)))
})
})
})

s.When("Timecop is altering the flow of time", func(s *testcase.Spec) {
Expand Down

0 comments on commit 4c49fb4

Please sign in to comment.