Skip to content

Commit

Permalink
retrun a new instance of Time from In()
Browse files Browse the repository at this point in the history
  • Loading branch information
yaa110 committed Mar 29, 2024
1 parent dc82636 commit e9e250e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ptime.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,14 @@ func (t *Time) SetNanosecond(nsec int) {
// In sets the location of t.
//
// loc is a pointer to time.Location and must not be nil.
func (t *Time) In(loc *time.Location) {
func (t Time) In(loc *time.Location) Time {
if loc == nil {
panic("ptime: the Location must not be nil in call to In")
}

t.loc = loc
t.resetWeekday()
return t
}

// At sets the hour, min minute, sec second and nsec nanoseconds offsets of t.
Expand Down
11 changes: 11 additions & 0 deletions ptime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ func TestLocations(t *testing.T) {
"got", Afghanistan().String(),
)
}

loc, _ := time.LoadLocation("Asia/Baghdad")
expected := loc.String()
actual := Now().In(loc).Location().String()
if actual != expected {
t.Error(
"For", "Baghdad",
"expected", expected,
"got", actual,
)
}
}

func TestPersianToGregorian(t *testing.T) {
Expand Down

0 comments on commit e9e250e

Please sign in to comment.