mirror of
https://github.com/jimeh/go-tyme.git
synced 2026-02-19 09:56:42 +00:00
feat(tyme): add basic tyme package
This commit is contained in:
36
time_example_test.go
Normal file
36
time_example_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user