File: time.go

package info (click to toggle)
golang-github-mimuret-golang-iij-dpf 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,340 kB
  • sloc: makefile: 55
file content (38 lines) | stat: -rw-r--r-- 623 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package types

import (
	"encoding/json"
	"time"
)

func ParseTime(layout, value string) (Time, error) {
	var err error
	res := Time{}
	res.Time, err = time.Parse(layout, value)
	if err != nil {
		return res, err
	}
	return res, nil
}

// +k8s:deepcopy-gen=false
type Time struct {
	time.Time
}

func (i Time) MarshalJSON() ([]byte, error) {
	return json.Marshal(i.Time)
}

func (i *Time) UnmarshalJSON(data []byte) error {
	if string(data) == `""` {
		return nil
	}
	var err error
	i.Time, err = time.Parse(`"`+time.RFC3339Nano+`"`, string(data))
	return err
}

func (i *Time) DeepCopyInto(in *Time) {
	i.Time = in.Time
}