atom/date.go

36 lines
709 B
Go
Raw Permalink Normal View History

2024-10-16 21:28:04 +02:00
package atom
2024-10-13 17:19:40 +02:00
import (
"errors"
"time"
)
type Date struct {
*CommonAttributes
2024-10-17 17:19:43 +02:00
DateTime string `xml:",chardata"`
2024-10-13 17:19:40 +02:00
}
2025-01-24 23:06:32 +01:00
// DateTime formats the time.Time t to a string as defined by RFC3339. It
2024-10-16 19:59:28 +02:00
// returns a string.
func DateTime(t time.Time) string {
return t.Format(time.RFC3339)
}
2025-01-24 23:06:32 +01:00
// NewDate creates a new Date. It takes in a time.Time t and returns a *Date.
func NewDate(t time.Time) *Date {
return &Date{
2024-10-20 15:59:46 +02:00
CommonAttributes: NewCommonAttributes(),
DateTime: DateTime(t),
}
}
2024-10-16 19:59:28 +02:00
// Check checks the Date for incompatibilities with RFC4287. It returns an
// error.
2024-10-13 17:19:40 +02:00
func (d *Date) Check() error {
if d.DateTime == "" {
return errors.New("date time element of date is empty")
}
return nil
}