feat(tyme): add basic tyme package

This commit is contained in:
2022-10-30 03:30:34 +00:00
parent b34d102e09
commit 572d532b77
12 changed files with 945 additions and 0 deletions

36
time_example_test.go Normal file
View 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
}