From e802ee7cebb3ebec3b5be53cb792b134477d115f Mon Sep 17 00:00:00 2001 From: Terence Boldt Date: Sun, 27 Jun 2021 22:30:33 -0400 Subject: [PATCH] Fix date calculation bug and add test --- prodos/time.go | 2 +- prodos/time_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 prodos/time_test.go diff --git a/prodos/time.go b/prodos/time.go index f731969..7563825 100644 --- a/prodos/time.go +++ b/prodos/time.go @@ -45,7 +45,7 @@ func DateTimeFromProDOS(buffer []byte) time.Time { } month := int(buffer[0]>>5 + buffer[1]&1) - day := int(buffer[0] & 23) + day := int(buffer[0] & 31) hour := int(buffer[3]) minute := int(buffer[2]) diff --git a/prodos/time_test.go b/prodos/time_test.go new file mode 100644 index 0000000..66710f2 --- /dev/null +++ b/prodos/time_test.go @@ -0,0 +1,15 @@ +package prodos + +import ( + "testing" + "time" +) + +func TestDateTimeToAndFromProDOS(t *testing.T) { + now := time.Now().Round(time.Minute) + + got := DateTimeFromProDOS(DateTimeToProDOS(now)) + if got != now { + t.Errorf("DateTimeFromProDOS(DateTimeToProDOS(now)) = %s; want %s", got.String(), now.String()) + } +}