1// +build go1.13
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5// Code generated by Microsoft (R) AutoRest Code Generator.
6// Changes may cause incorrect behavior and will be lost if the code is regenerated.
7
8package azartifacts
9
10import (
11	"regexp"
12	"strings"
13	"time"
14)
15
16const (
17	utcLayoutJSON = `"2006-01-02T15:04:05.999999999"`
18	utcLayout     = "2006-01-02T15:04:05.999999999"
19	rfc3339JSON   = `"` + time.RFC3339Nano + `"`
20)
21
22// Azure reports time in UTC but it doesn't include the 'Z' time zone suffix in some cases.
23var tzOffsetRegex = regexp.MustCompile(`(Z|z|\+|-)(\d+:\d+)*"*$`)
24
25type timeRFC3339 time.Time
26
27func (t timeRFC3339) MarshalJSON() (json []byte, err error) {
28	tt := time.Time(t)
29	return tt.MarshalJSON()
30}
31
32func (t timeRFC3339) MarshalText() (text []byte, err error) {
33	tt := time.Time(t)
34	return tt.MarshalText()
35}
36
37func (t *timeRFC3339) UnmarshalJSON(data []byte) error {
38	layout := utcLayoutJSON
39	if tzOffsetRegex.Match(data) {
40		layout = rfc3339JSON
41	}
42	return t.Parse(layout, string(data))
43}
44
45func (t *timeRFC3339) UnmarshalText(data []byte) (err error) {
46	layout := utcLayout
47	if tzOffsetRegex.Match(data) {
48		layout = time.RFC3339Nano
49	}
50	return t.Parse(layout, string(data))
51}
52
53func (t *timeRFC3339) Parse(layout, value string) error {
54	p, err := time.Parse(layout, strings.ToUpper(value))
55	*t = timeRFC3339(p)
56	return err
57}
58