Documentation ¶
Overview ¶
Package date provides time.Time derivatives that conform to the Swagger.io (https://swagger.io/) defined date formats: Date and DateTime. Both types may, in most cases, be used in lieu of time.Time types. And both convert to time.Time through a ToTime method.
Index ¶
- func ByUnmarshallingDate(d *Date) autorest.RespondDecorator
- func ByUnmarshallingTime(t *Time) autorest.RespondDecorator
- type Date
- func (d Date) MarshalBinary() ([]byte, error)
- func (d Date) MarshalJSON() (json []byte, err error)
- func (d Date) MarshalText() (text []byte, err error)
- func (d Date) String() string
- func (d Date) ToTime() time.Time
- func (d *Date) UnmarshalBinary(data []byte) error
- func (d *Date) UnmarshalJSON(data []byte) (err error)
- func (d *Date) UnmarshalText(data []byte) (err error)
- type Time
- func (d Time) MarshalBinary() ([]byte, error)
- func (d Time) MarshalJSON() (json []byte, err error)
- func (d Time) MarshalText() (text []byte, err error)
- func (d Time) String() string
- func (d Time) ToTime() time.Time
- func (d *Time) UnmarshalBinary(data []byte) error
- func (d *Time) UnmarshalJSON(data []byte) (err error)
- func (d *Time) UnmarshalText(data []byte) (err error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByUnmarshallingDate ¶
func ByUnmarshallingDate(d *Date) autorest.RespondDecorator
ByUnmarshallingDate returns a RespondDecorator that decodes the http.Response Body into a Date pointed to by d.
func ByUnmarshallingTime ¶
func ByUnmarshallingTime(t *Time) autorest.RespondDecorator
ByUnmarshallingTime returns a RespondDecorator that decodes the http.Response Body into a Time pointed to by t.
Types ¶
type Date ¶
Date defines a type similar to time.Time but assumes a layout of RFC3339 full-date (i.e., 2006-01-02).
Example ¶
d, _ := ParseDate("2001-02-03") t, _ := time.Parse(time.RFC3339, "2001-02-04T00:00:00Z") // Date acts as time.Time when the receiver if d.Before(t) { fmt.Printf("Before ") } else { fmt.Printf("After ") } // Convert Date when needing a time.Time if t.After(d.ToTime()) { fmt.Printf("After") } else { fmt.Printf("Before") }
Output: Before After
func ParseDate ¶
ParseDate create a new Date from the passed string.
Example ¶
d, _ := ParseDate("2001-02-03") fmt.Println(d)
Output: 2001-02-03
func (Date) MarshalBinary ¶
MarshalBinary preserves the Date as a byte array conforming to RFC3339 full-date (i.e., 2006-01-02).
Example ¶
d, _ := ParseDate("2001-02-03") t, _ := d.MarshalBinary() fmt.Println(string(t))
Output: 2001-02-03
func (Date) MarshalJSON ¶
MarshalJSON preserves the Date as a JSON string conforming to RFC3339 full-date (i.e., 2006-01-02).
Example ¶
d, _ := ParseDate("2001-02-03") j, _ := json.Marshal(d) fmt.Println(string(j))
Output: "2001-02-03"
func (Date) MarshalText ¶
MarshalText preserves the Date as a byte array conforming to RFC3339 full-date (i.e., 2006-01-02).
Example ¶
d, _ := ParseDate("2001-02-03") t, _ := d.MarshalText() fmt.Println(string(t))
Output: 2001-02-03
func (Date) String ¶
String returns the Date formatted as an RFC3339 full-date string (i.e., 2006-01-02).
func (*Date) UnmarshalBinary ¶
UnmarshalBinary reconstitutes a Date saved as a byte array conforming to RFC3339 full-date (i.e., 2006-01-02).
Example ¶
d := Date{} t := "2001-02-03" err := d.UnmarshalBinary([]byte(t)) if err != nil { fmt.Println(err) } fmt.Println(d)
Output: 2001-02-03
func (*Date) UnmarshalJSON ¶
UnmarshalJSON reconstitutes the Date from a JSON string conforming to RFC3339 full-date (i.e., 2006-01-02).
Example ¶
var d struct { Date Date `json:"date"` } j := `{ "date" : "2001-02-03" }` err := json.Unmarshal([]byte(j), &d) if err != nil { fmt.Println(err) } fmt.Println(d.Date)
Output: 2001-02-03
func (*Date) UnmarshalText ¶
UnmarshalText reconstitutes a Date saved as a byte array conforming to RFC3339 full-date (i.e., 2006-01-02).
Example ¶
d := Date{} t := "2001-02-03" err := d.UnmarshalText([]byte(t)) if err != nil { fmt.Println(err) } fmt.Println(d)
Output: 2001-02-03
type Time ¶
Time defines a type similar to time.Time but assumes a layout of RFC3339 date-time (i.e., 2006-01-02T15:04:05Z).
func ParseTime ¶
ParseTime creates a new Time from the passed string.
Example ¶
d, _ := ParseTime("2001-02-03T04:05:06Z") fmt.Println(d)
Output: 2001-02-03T04:05:06Z
func (Time) MarshalBinary ¶
MarshalBinary preserves the Time as a byte array conforming to RFC3339 date-time (i.e., 2006-01-02T15:04:05Z).
Example ¶
d, _ := ParseTime("2001-02-03T04:05:06Z") t, _ := d.MarshalBinary() fmt.Println(string(t))
Output: 2001-02-03T04:05:06Z
func (Time) MarshalJSON ¶
MarshalJSON preserves the Time as a JSON string conforming to RFC3339 date-time (i.e., 2006-01-02T15:04:05Z).
Example ¶
d, _ := ParseTime("2001-02-03T04:05:06Z") j, _ := json.Marshal(d) fmt.Println(string(j))
Output: "2001-02-03T04:05:06Z"
func (Time) MarshalText ¶
MarshalText preserves the Time as a byte array conforming to RFC3339 date-time (i.e., 2006-01-02T15:04:05Z).
Example ¶
d, _ := ParseTime("2001-02-03T04:05:06Z") t, _ := d.MarshalText() fmt.Println(string(t))
Output: 2001-02-03T04:05:06Z
func (Time) String ¶
String returns the Time formatted as an RFC3339 date-time string (i.e., 2006-01-02T15:04:05Z).
func (*Time) UnmarshalBinary ¶
UnmarshalBinary reconstitutes a Time saved as a byte array conforming to RFC3339 date-time (i.e., 2006-01-02T15:04:05Z).
Example ¶
d := Time{} t := "2001-02-03T04:05:06Z" err := d.UnmarshalBinary([]byte(t)) if err != nil { fmt.Println(err) } fmt.Println(d)
Output: 2001-02-03T04:05:06Z
func (*Time) UnmarshalJSON ¶
UnmarshalJSON reconstitutes the Time from a JSON string conforming to RFC3339 date-time (i.e., 2006-01-02T15:04:05Z).
Example ¶
var d struct { Time Time `json:"datetime"` } j := `{ "datetime" : "2001-02-03T04:05:06Z" }` err := json.Unmarshal([]byte(j), &d) if err != nil { fmt.Println(err) } fmt.Println(d.Time)
Output: 2001-02-03T04:05:06Z
func (*Time) UnmarshalText ¶
UnmarshalText reconstitutes a Time saved as a byte array conforming to RFC3339 date-time (i.e., 2006-01-02T15:04:05Z).
Example ¶
d := Time{} t := "2001-02-03T04:05:06Z" err := d.UnmarshalText([]byte(t)) if err != nil { fmt.Println(err) } fmt.Println(d)
Output: 2001-02-03T04:05:06Z