From 6ecb12c98cbfb7dd2520c37033b5d792b190c6d6 Mon Sep 17 00:00:00 2001 From: Elijah Duffy Date: Wed, 23 Jul 2025 10:59:03 -0700 Subject: [PATCH] marshal database value to byte slice --- clocktime.go | 4 ++-- clocktime_test.go | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 clocktime_test.go diff --git a/clocktime.go b/clocktime.go index 32d62bf..f3893f7 100644 --- a/clocktime.go +++ b/clocktime.go @@ -129,9 +129,9 @@ func (t *ClockTime) UnmarshalGQL(value any) error { } // Value implements the database/sql/driver.Valuer interface for ClockTime. -// Marshals the ClockTime to a time.Time for database storage. +// Marshals the ClockTime to a byte slice for database storage. func (t ClockTime) Value() (driver.Value, error) { - return t.Time(), nil + return []byte(t.String()), nil } // Scan implements the database/sql.Scanner interface for ClockTime. diff --git a/clocktime_test.go b/clocktime_test.go new file mode 100644 index 0000000..693c1d6 --- /dev/null +++ b/clocktime_test.go @@ -0,0 +1,19 @@ +package clocktime + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func Test_Comparison(t *testing.T) { + assert := assert.New(t) + time1 := NewClockTime(10, 30, 0) + time2 := NewClockTime(11, 0, 0) + time3 := NewClockTime(10, 30, 0) + + assert.True(time1.Before(time2)) + assert.False(time1.After(time2)) + assert.False(time1.Equal(time2)) + assert.True(time1.Equal(time3)) +}