From 62eb675aeda0f4fc04b1ce2a6831c5d79037d4c9 Mon Sep 17 00:00:00 2001 From: twystd Date: Wed, 5 Jun 2024 09:24:36 -0700 Subject: [PATCH] Replaced TimeProfile from/to date pointers with concrete values --- go.mod | 4 ++-- go.sum | 4 ++++ simulator/UT0311L04/actions.go | 6 ++++-- simulator/UT0311L04/actions_test.go | 6 ++---- simulator/UT0311L04/get_time_profile.go | 17 ++--------------- simulator/UT0311L04/set_time_profile.go | 4 ++-- 6 files changed, 16 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 2291bd8..b1de9c8 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 11b1a57..b1aaf55 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/simulator/UT0311L04/actions.go b/simulator/UT0311L04/actions.go index 777233c..bf2df54 100644 --- a/simulator/UT0311L04/actions.go +++ b/simulator/UT0311L04/actions.go @@ -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 } diff --git a/simulator/UT0311L04/actions_test.go b/simulator/UT0311L04/actions_test.go index e27a936..6782afa 100644 --- a/simulator/UT0311L04/actions_test.go +++ b/simulator/UT0311L04/actions_test.go @@ -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, diff --git a/simulator/UT0311L04/get_time_profile.go b/simulator/UT0311L04/get_time_profile.go index 28c251c..1bdce4e 100644 --- a/simulator/UT0311L04/get_time_profile.go +++ b/simulator/UT0311L04/get_time_profile.go @@ -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) { @@ -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] diff --git a/simulator/UT0311L04/set_time_profile.go b/simulator/UT0311L04/set_time_profile.go index b38ad4d..0b9b266 100644 --- a/simulator/UT0311L04/set_time_profile.go +++ b/simulator/UT0311L04/set_time_profile.go @@ -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,