Skip to content

Commit

Permalink
Reworked checkTimeProfile to reference everything from UTC (cf. #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Oct 15, 2022
1 parent b2fec99 commit 6009fa1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
17 changes: 17 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

- [ ] https://github.com/uhppoted/uhppote-simulator/issues/6
- [ ] https://github.com/uhppoted/uhppote-simulator/issues/5
- [ ] github workflow
```
go: downloading github.com/uhppoted/uhppote-core v0.8.3-0.20221014202027-b01c41cc87cb
mkdir -p bin
go build -trimpath -o bin ./...
go test ./...
? github.com/uhppoted/uhppote-simulator/cmd/uhppote-simulator [no test files]
? github.com/uhppoted/uhppote-simulator/commands [no test files]
ok github.com/uhppoted/uhppote-simulator/entities 0.008s
? github.com/uhppoted/uhppote-simulator/rest [no test files]
? github.com/uhppoted/uhppote-simulator/simulator [no test files]
--- FAIL: TestCheckTimeProfileInTimeSegment (0.00s)
actions_test.go:81: checkTimeProfile returned false for an in-bounds time segment - expected: true
FAIL
FAIL github.com/uhppoted/uhppote-simulator/simulator/UT0311L04 0.004s
FAIL
```

### IN PROGRESS

Expand Down
7 changes: 3 additions & 4 deletions simulator/UT0311L04/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,10 @@ func (s *UT0311L04) checkTimeProfile(profileID uint8) bool {
}

func checkTimeProfile(profile types.TimeProfile, offset entities.Offset) bool {
utc := time.Now().UTC().Add(time.Duration(offset))
adjusted := utc.Local()
now := types.HHmmFromTime(adjusted)

today := types.Date(time.Now())
utc := time.Now().UTC()
adjusted := utc.Add(time.Duration(offset))
now := types.HHmmFromTime(adjusted)

if profile.From == nil || profile.From.After(today) {
return false
Expand Down
16 changes: 8 additions & 8 deletions simulator/UT0311L04/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestCheckTimeProfileWithValidProfile(t *testing.T) {
func TestCheckTimeProfileInTimeSegment(t *testing.T) {
from := types.ToDate(2000, time.January, 1)
to := types.ToDate(2099, time.December, 31)
now := time.Now()
now := time.Now().UTC()
start := types.HHmmFromTime(now.Add(-10 * time.Minute))
end := types.HHmmFromTime(now.Add(10 * time.Minute))

Expand Down Expand Up @@ -86,7 +86,7 @@ func TestCheckTimeProfileInTimeSegment(t *testing.T) {
func TestCheckTimeProfileBeforeTimeSegment(t *testing.T) {
from := types.ToDate(2000, time.January, 1)
to := types.ToDate(2099, time.December, 31)
now := time.Now()
now := time.Now().UTC()
start := types.HHmmFromTime(now.Add(10 * time.Minute))
end := types.HHmmFromTime(now.Add(60 * time.Minute))

Expand Down Expand Up @@ -124,7 +124,7 @@ func TestCheckTimeProfileBeforeTimeSegment(t *testing.T) {
func TestCheckTimeProfileAfterTimeSegment(t *testing.T) {
from := types.ToDate(2000, time.January, 1)
to := types.ToDate(2099, time.December, 31)
now := time.Now()
now := time.Now().UTC()
start := types.HHmmFromTime(now.Add(-60 * time.Minute))
end := types.HHmmFromTime(now.Add(-10 * time.Minute))

Expand Down Expand Up @@ -200,7 +200,7 @@ func TestCheckTimeProfileInTimeSegmentWithOffset(t *testing.T) {
start := types.NewHHmm(11, 30)
end := types.NewHHmm(12, 30)

now := time.Now()
now := time.Now().UTC()
datetime := fmt.Sprintf("%v 11:57:32", now.Format("2006-01-02"))

profile := types.TimeProfile{
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestCheckTimeProfileBeforeTimeSegmentWithOffset(t *testing.T) {
start := types.NewHHmm(11, 30)
end := types.NewHHmm(12, 30)

now := time.Now()
now := time.Now().UTC()
datetime := fmt.Sprintf("%v 11:05:32", now.Format("2006-01-02"))

profile := types.TimeProfile{
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestCheckTimeProfileAfterTimeSegmentWithOffset(t *testing.T) {
start := types.NewHHmm(11, 30)
end := types.NewHHmm(12, 30)

now := time.Now()
now := time.Now().UTC()
datetime := fmt.Sprintf("%v 13:13:13", now.Format("2006-01-02"))

profile := types.TimeProfile{
Expand Down Expand Up @@ -312,8 +312,8 @@ func TestCheckTimeProfileAfterTimeSegmentWithOffset(t *testing.T) {
}

func offset(datetime string) entities.Offset {
utc, _ := time.ParseInLocation("2006-01-02 15:04:05", datetime, time.Local)
now := time.Now()
utc, _ := time.ParseInLocation("2006-01-02 15:04:05", datetime, time.UTC)
now := time.Now().UTC()
delta := utc.Sub(now)

return entities.Offset(delta)
Expand Down

0 comments on commit 6009fa1

Please sign in to comment.