2023-12-21 10:53:18 +03:00
|
|
|
package retailcrm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SystemTime time.Time
|
|
|
|
|
|
|
|
const systemTimeLayout = "2006-01-02 15:04:05"
|
|
|
|
|
|
|
|
// UnmarshalJSON parses time.Time from system format.
|
|
|
|
func (st *SystemTime) UnmarshalJSON(b []byte) (err error) {
|
|
|
|
s := strings.Trim(string(b), `"`)
|
|
|
|
nt, err := time.Parse(systemTimeLayout, s)
|
|
|
|
*st = SystemTime(nt)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON will marshal time.Time to system format.
|
|
|
|
func (st SystemTime) MarshalJSON() ([]byte, error) {
|
|
|
|
return []byte(st.String()), nil
|
|
|
|
}
|
|
|
|
|
2025-01-31 11:47:59 +03:00
|
|
|
// String returns the time in the custom format.
|
2023-12-21 10:53:18 +03:00
|
|
|
func (st *SystemTime) String() string {
|
|
|
|
t := time.Time(*st)
|
|
|
|
return fmt.Sprintf("%q", t.Format(systemTimeLayout))
|
|
|
|
}
|