mirror of
https://github.com/jimeh/go-tyme.git
synced 2026-02-19 09:56:42 +00:00
37 lines
690 B
Go
37 lines
690 B
Go
package tyme_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/jimeh/go-tyme"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
func ExampleTime_MarshalJSON() {
|
|
type Order struct {
|
|
Date tyme.Time `json:"date"`
|
|
}
|
|
t := time.Date(2006, 1, 2, 15, 4, 5, 999000000, time.UTC)
|
|
order := Order{Date: tyme.Time(t)}
|
|
b, _ := json.Marshal(order)
|
|
|
|
fmt.Println(string(b))
|
|
// Output:
|
|
// {"date":"2006-01-02T15:04:05.999Z"}
|
|
}
|
|
|
|
func ExampleTime_MarshalYAML() {
|
|
type Order struct {
|
|
Date tyme.Time `yaml:"date"`
|
|
}
|
|
t := time.Date(2006, 1, 2, 15, 4, 5, 999000000, time.UTC)
|
|
order := Order{Date: tyme.Time(t)}
|
|
b, _ := yaml.Marshal(order)
|
|
|
|
fmt.Println(string(b))
|
|
// Output:
|
|
// date: 2006-01-02T15:04:05.999Z
|
|
}
|