mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
27 lines
390 B
Go
27 lines
390 B
Go
package model
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
type Timestamp time.Time
|
|
|
|
func (t Timestamp) MarshalJSON() ([]byte, error) {
|
|
ts := time.Time(t).Unix()
|
|
stamp := fmt.Sprint(ts)
|
|
return []byte(stamp), nil
|
|
}
|
|
|
|
|
|
func (t *Timestamp) UnmarshalJSON(b []byte) error {
|
|
ts, err := strconv.Atoi(string(b))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
*t = Timestamp(time.Unix(int64(ts), 0))
|
|
return nil
|
|
}
|