Skip to content

Commit

Permalink
Replaced TimeProfile from/to date pointers with concrete values
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Jun 5, 2024
1 parent 9e0dfe4 commit 62eb675
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 25 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,6 @@ module github.com/uhppoted/uhppote-simulator
go 1.22

require (
github.com/uhppoted/uhppote-core v0.8.9-0.20240604153627-4993b61f3ba6
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240604154440-5ce365632a38
github.com/uhppoted/uhppote-core v0.8.9-0.20240605161320-cd6c0e95347b
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240605161930-54dea6fc78b1
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 66,8 @@ github.com/uhppoted/uhppote-core v0.8.9-0.20240531170136-432a5b0fbb8b h1:alKlb6o
github.com/uhppoted/uhppote-core v0.8.9-0.20240531170136-432a5b0fbb8b/go.mod h1:Q DHtT8s74efLs2b0eF20DRBUL9yBkySwaTQ 0lsEVM=
github.com/uhppoted/uhppote-core v0.8.9-0.20240604153627-4993b61f3ba6 h1:ltffa7TfO mbR6VLURhlG/6ChkQSglpbN13wUYvQhUM=
github.com/uhppoted/uhppote-core v0.8.9-0.20240604153627-4993b61f3ba6/go.mod h1:Q DHtT8s74efLs2b0eF20DRBUL9yBkySwaTQ 0lsEVM=
github.com/uhppoted/uhppote-core v0.8.9-0.20240605161320-cd6c0e95347b h1:8 6eR7uTFE5cD3tdbOjat2NoI/zS3Pj1eK4WXZvQweA=
github.com/uhppoted/uhppote-core v0.8.9-0.20240605161320-cd6c0e95347b/go.mod h1:Q DHtT8s74efLs2b0eF20DRBUL9yBkySwaTQ 0lsEVM=
github.com/uhppoted/uhppoted-lib v0.8.5 h1:X5RarX5QMRGJvOwPk8ceowrH8k6Ow3t TraWmhYO950=
github.com/uhppoted/uhppoted-lib v0.8.5/go.mod h1:euK2cLO934w0GDgvvnWMjYNtZ29K1xSMrMse6THOzDQ=
github.com/uhppoted/uhppoted-lib v0.8.6-0.20230714155133-57e68f2d1360 h1:XaVqmMmjwskTrX6iCdUl2I4ezrvuoA/yhLzf/455E10=
Expand Down Expand Up @@ -134,3 136,5 @@ github.com/uhppoted/uhppoted-lib v0.8.9-0.20240531170312-cb08695b7cc2 h1:Slbb2pw
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240531170312-cb08695b7cc2/go.mod h1:pg8dPLgY Faru4Zc5Et0Q/bq5lbKU420/VdXQLkkjCE=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240604154440-5ce365632a38 h1:q42QPpm0uFtd00SU1GIbwGhwolCEZa0BNKJUVYc0BKw=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240604154440-5ce365632a38/go.mod h1:MsC5n/1vS80L/S7wcpzpOPeR8UsUNKOMmdOWs/vi5Hg=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240605161930-54dea6fc78b1 h1:T1tGRfDa/jN9apkZtiid5FmHMMxjNXuazp7Mi9J4K/U=
github.com/uhppoted/uhppoted-lib v0.8.9-0.20240605161930-54dea6fc78b1/go.mod h1:di eHPBWGIN6UwtmjXNPzmKZyoE8VL7f1KDbbw1cFzQ=
6 changes: 4 additions & 2 deletions simulator/UT0311L04/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 344,13 @@ func checkTimeProfile(profile types.TimeProfile, offset entities.Offset) bool {
today := types.Date(adjusted)
weekday := today.Weekday()

if profile.From == nil || profile.From.After(today) {
// NTS: zero value 'from' date may be valid
if profile.From.IsZero() || profile.From.After(today) {
return false
}

if profile.To == nil || profile.To.Before(today) {
// NTS: zero value 'to' date may be valid
if profile.To.IsZero() || profile.To.Before(today) {
return false
}

Expand Down
6 changes: 2 additions & 4 deletions simulator/UT0311L04/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 96,14 @@ func TestCheckTimeProfile(t *testing.T) {
}

for _, test := range tests {
from := types.MustParseDate(test.startDate)
to := types.MustParseDate(test.endDate)
start, _ := types.HHmmFromString(test.startTime)
end, _ := types.HHmmFromString(test.endTime)

profile := types.TimeProfile{
ID: 37,
LinkedProfileID: 0,
From: &from,
To: &to,
From: types.MustParseDate(test.startDate),
To: types.MustParseDate(test.endDate),
Weekdays: types.Weekdays{
time.Monday: test.monday,
time.Tuesday: test.tuesday,
Expand Down
17 changes: 2 additions & 15 deletions simulator/UT0311L04/get_time_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,6 @@ import (
"time"

"github.com/uhppoted/uhppote-core/messages"
"github.com/uhppoted/uhppote-core/types"
)

func (s *UT0311L04) getTimeProfile(request *messages.GetTimeProfileRequest) (*messages.GetTimeProfileResponse, error) {
Expand All @@ -18,22 17,10 @@ func (s *UT0311L04) getTimeProfile(request *messages.GetTimeProfileRequest) (*me

if request.ProfileID > 1 && request.ProfileID < 255 {
if profile, ok := s.TimeProfiles[request.ProfileID]; ok {
// FIXME: replace From in types.TimeProfile
from := types.Date{}
if profile.From != nil {
from = *profile.From
}

// FIXME: replace To in TimeProfile entity
to := types.Date{}
if profile.To != nil {
to = *profile.To
}

response.ProfileID = profile.ID
response.LinkedProfileID = profile.LinkedProfileID
response.From = from
response.To = to
response.From = profile.From
response.To = profile.To

response.Monday = profile.Weekdays[time.Monday]
response.Tuesday = profile.Weekdays[time.Tuesday]
Expand Down
4 changes: 2 additions & 2 deletions simulator/UT0311L04/set_time_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 16,8 @@ func (s *UT0311L04) setTimeProfile(request *messages.SetTimeProfileRequest) (*me
profile := types.TimeProfile{
ID: request.ProfileID,
LinkedProfileID: request.LinkedProfileID,
From: &request.From,
To: &request.To,
From: request.From,
To: request.To,
Weekdays: types.Weekdays{
time.Monday: request.Monday,
time.Tuesday: request.Tuesday,
Expand Down

0 comments on commit 62eb675

Please sign in to comment.