From 8342bdf606f46d1ce172ad756531c3525ba384ac Mon Sep 17 00:00:00 2001 From: YouSheng Date: Fri, 27 Oct 2023 14:35:14 +0800 Subject: [PATCH] Fix bug: encode DST to NAS will mistake "+10:45" for having DST --- nasConvert/Time.go | 4 ++-- nasConvert/Time_test.go | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/nasConvert/Time.go b/nasConvert/Time.go index 2e62952..b736990 100644 --- a/nasConvert/Time.go +++ b/nasConvert/Time.go @@ -124,10 +124,10 @@ func EncodeDaylightSavingTimeToNas( var nasDaylightSavingTime nasType.NetworkDaylightSavingTime value := 0 - if strings.Contains(timezone, "+1") { + if timezone[len(timezone)-2:] == "+1" { value = 1 } - if strings.Contains(timezone, "+2") { + if timezone[len(timezone)-2:] == "+2" { value = 2 } diff --git a/nasConvert/Time_test.go b/nasConvert/Time_test.go index b729b3f..5f1e42c 100644 --- a/nasConvert/Time_test.go +++ b/nasConvert/Time_test.go @@ -217,6 +217,13 @@ func TestDaylightSavingTimeToNas(t *testing.T) { Octet: uint8(0x00), }, }, + { + in: nasConvert.EncodeDaylightSavingTimeToNas("+10:45"), + out: nasType.NetworkDaylightSavingTime{ + Len: uint8(0x01), + Octet: uint8(0x00), + }, + }, } for _, tc := range nasConvertNetworkDaylightSavingTimeTable {