Skip to content

Commit

Permalink
fix UnmarshalJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
azonti committed Jun 3, 2024
1 parent 8680815 commit 46a5bb1
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions receipt/model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package receipt

import (
"bytes"
"strconv"
"time"

Expand All @@ -22,16 +23,16 @@ func (nd date) MarshalJSON() ([]byte, error) {
}

func (nd *date) UnmarshalJSON(b []byte) error {
if bytes.Equal(b, []byte("null")) {
*nd = date(null.Time{})
return nil
}

dateString, err := strconv.Unquote(string(b))
if err != nil {
return err
}

if dateString == "" {
*nd = date(null.Time{})
return nil
}

t, err := time.Parse("2006-01-02 15:04:05 Etc/GMT", dateString)
if err != nil {
return err
Expand All @@ -52,16 +53,16 @@ func (nd dateMS) MarshalJSON() ([]byte, error) {
}

func (nd *dateMS) UnmarshalJSON(b []byte) error {
if bytes.Equal(b, []byte("null")) {
*nd = dateMS(null.Time{})
return nil
}

msString, err := strconv.Unquote(string(b))
if err != nil {
return err
}

if msString == "" {
*nd = dateMS(null.Time{})
return nil
}

sec, err := strconv.ParseInt(msString, 10, 64)
if err != nil {
return err
Expand Down Expand Up @@ -89,16 +90,16 @@ func (nd datePST) MarshalJSON() ([]byte, error) {
}

func (nd *datePST) UnmarshalJSON(b []byte) error {
if bytes.Equal(b, []byte("null")) {
*nd = datePST(null.Time{})
return nil
}

pstString, err := strconv.Unquote(string(b))
if err != nil {
return err
}

if pstString == "" {
*nd = datePST(null.Time{})
return nil
}

loc, err := time.LoadLocation("America/Los_Angeles")
if err != nil {
return err
Expand Down

0 comments on commit 46a5bb1

Please sign in to comment.