Skip to content

Commit a8bbaab

Browse files
author
noah
committed
Fix to revert into the orignal location
1 parent fb9035c commit a8bbaab

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

_example/location.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"time"
6+
7+
"github.com/gitploy-io/cronexpr"
8+
)
9+
10+
func main() {
11+
nextTime := cronexpr.MustParseInLocation("0 * * * *", "Asia/Seoul").Next(time.Now())
12+
fmt.Printf("Parse the cron expression in the KR timezone: %s", nextTime)
13+
}

schedule.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func (s *Schedule) Next(t time.Time) time.Time {
1818
loc = s.Location
1919
}
2020

21+
origLoc := t.Location()
2122
t.In(loc)
2223

2324
added := false
@@ -92,7 +93,7 @@ L:
9293
}
9394
}
9495

95-
return t
96+
return t.In(origLoc)
9697
}
9798

9899
func (s *Schedule) Prev(t time.Time) time.Time {
@@ -101,6 +102,7 @@ func (s *Schedule) Prev(t time.Time) time.Time {
101102
loc = s.Location
102103
}
103104

105+
origLoc := t.Location()
104106
t.In(loc)
105107

106108
subtracted := false
@@ -176,7 +178,7 @@ L:
176178
}
177179
}
178180

179-
return t
181+
return t.In(origLoc)
180182
}
181183

182184
// dayMatches returns true if the schedule's day-of-week and day-of-month

0 commit comments

Comments
 (0)