45 lines
832 B
Go
45 lines
832 B
Go
package atom
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
)
|
|
|
|
type Date struct {
|
|
*CommonAttributes
|
|
DateTime string `xml:",chardata"`
|
|
}
|
|
|
|
// DateTime formats a time.Time to string formated as defined by RFC3339. It
|
|
// returns a string.
|
|
func DateTime(t time.Time) string {
|
|
return t.Format(time.RFC3339)
|
|
}
|
|
|
|
// NewDate creates a new Date. It returns a *Date.
|
|
func NewDate(t time.Time) *Date {
|
|
return &Date{
|
|
CommonAttributes: newCommonAttributes(),
|
|
DateTime: DateTime(t),
|
|
}
|
|
}
|
|
|
|
// Update updates the Date.
|
|
func (d *Date) Update() {
|
|
if d == nil {
|
|
d = NewDate(time.Now())
|
|
} else {
|
|
d.DateTime = DateTime(time.Now())
|
|
}
|
|
}
|
|
|
|
// Check checks the Date for incompatibilities with RFC4287. It returns an
|
|
// error.
|
|
func (d *Date) Check() error {
|
|
if d.DateTime == "" {
|
|
return errors.New("date time element of date is empty")
|
|
}
|
|
|
|
return nil
|
|
}
|