1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

fix: json marshalling of custom time (resolve #117)

This commit is contained in:
Ferdinand Mütsch
2021-02-07 12:37:51 +01:00
parent bb1d6c048d
commit 9e5847b66d
2 changed files with 6 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package models
import (
"database/sql/driver"
"encoding/json"
"errors"
"fmt"
"gorm.io/gorm"
@@ -31,6 +32,10 @@ type Interval struct {
type CustomTime time.Time
func (j *CustomTime) MarshalJSON() ([]byte, error) {
return json.Marshal(j.String())
}
func (j *CustomTime) UnmarshalJSON(b []byte) error {
s := strings.Replace(strings.Trim(string(b), "\""), ".", "", 1)
i, err := strconv.ParseInt(s, 10, 64)