~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest/date/time.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package date
 
2
 
 
3
import (
 
4
        "time"
 
5
)
 
6
 
 
7
// Time defines a type similar to time.Time but assumes a layout of RFC3339 date-time (i.e.,
 
8
// 2006-01-02T15:04:05Z).
 
9
type Time struct {
 
10
        time.Time
 
11
}
 
12
 
 
13
// ParseTime creates a new Time from the passed string.
 
14
func ParseTime(date string) (d Time, err error) {
 
15
        d = Time{}
 
16
        d.Time, err = time.Parse(time.RFC3339, date)
 
17
        return d, err
 
18
}
 
19
 
 
20
// MarshalBinary preserves the Time as a byte array conforming to RFC3339 date-time (i.e.,
 
21
// 2006-01-02T15:04:05Z).
 
22
func (d Time) MarshalBinary() ([]byte, error) {
 
23
        return d.Time.MarshalText()
 
24
}
 
25
 
 
26
// UnmarshalBinary reconstitutes a Time saved as a byte array conforming to RFC3339 date-time
 
27
// (i.e., 2006-01-02T15:04:05Z).
 
28
func (d *Time) UnmarshalBinary(data []byte) error {
 
29
        return d.Time.UnmarshalText(data)
 
30
}
 
31
 
 
32
// MarshalJSON preserves the Time as a JSON string conforming to RFC3339 date-time (i.e.,
 
33
// 2006-01-02T15:04:05Z).
 
34
func (d Time) MarshalJSON() (json []byte, err error) {
 
35
        return d.Time.MarshalJSON()
 
36
}
 
37
 
 
38
// UnmarshalJSON reconstitutes the Time from a JSON string conforming to RFC3339 date-time
 
39
// (i.e., 2006-01-02T15:04:05Z).
 
40
func (d *Time) UnmarshalJSON(data []byte) (err error) {
 
41
        return d.Time.UnmarshalJSON(data)
 
42
}
 
43
 
 
44
// MarshalText preserves the Time as a byte array conforming to RFC3339 date-time (i.e.,
 
45
// 2006-01-02T15:04:05Z).
 
46
func (d Time) MarshalText() (text []byte, err error) {
 
47
        return d.Time.MarshalText()
 
48
}
 
49
 
 
50
// UnmarshalText reconstitutes a Time saved as a byte array conforming to RFC3339 date-time
 
51
// (i.e., 2006-01-02T15:04:05Z).
 
52
func (d *Time) UnmarshalText(data []byte) (err error) {
 
53
        return d.Time.UnmarshalText(data)
 
54
}
 
55
 
 
56
// String returns the Time formatted as an RFC3339 date-time string (i.e.,
 
57
// 2006-01-02T15:04:05Z).
 
58
func (d Time) String() string {
 
59
        // Note: time.Time.String does not return an RFC3339 compliant string, time.Time.MarshalText does.
 
60
        b, err := d.Time.MarshalText()
 
61
        if err != nil {
 
62
                return ""
 
63
        }
 
64
        return string(b)
 
65
}
 
66
 
 
67
// ToTime returns a Time as a time.Time
 
68
func (d Time) ToTime() time.Time {
 
69
        return d.Time
 
70
}