From 4f2372ac18579287c93c8e9025c95ac098870467 Mon Sep 17 00:00:00 2001 From: Florian Date: Mon, 15 May 2023 12:20:41 +0200 Subject: [PATCH] Fix MarshalingJSON when Time is null --- nulltime.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nulltime.go b/nulltime.go index 167a182..ab0bcea 100644 --- a/nulltime.go +++ b/nulltime.go @@ -106,8 +106,8 @@ func (n *Time) UnmarshalJSON(b []byte) error { return nil } -func (n Time) MarshalText() ([]byte, error) { - if n.Valid { +func (n *Time) MarshalText() ([]byte, error) { + if n != nil && n.Valid { location, err := time.LoadLocation(n.Timezone) if err != nil { location = time.UTC @@ -117,8 +117,8 @@ func (n Time) MarshalText() ([]byte, error) { return json.Marshal(nil) } -func (n Time) MarshalJSON() ([]byte, error) { - if n.Valid { +func (n *Time) MarshalJSON() ([]byte, error) { + if n != nil && n.Valid { location, err := time.LoadLocation(n.Timezone) if err != nil { location = time.UTC