2024-10-13 17:19:40 +02:00
|
|
|
package atomfeed
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Date struct {
|
|
|
|
*CommonAttributes
|
|
|
|
DateTime string
|
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// DateTime formats a time.Time to string formated as defined by RFC3339. It
|
|
|
|
// returns a string.
|
2024-10-15 16:25:45 +02:00
|
|
|
func DateTime(t time.Time) string {
|
|
|
|
return string(t.Format(time.RFC3339))
|
|
|
|
}
|
|
|
|
|
2024-10-16 19:59:28 +02:00
|
|
|
// NewDate creates a new Date. It returns a *Date.
|
2024-10-15 16:25:45 +02:00
|
|
|
func NewDate(t time.Time) *Date {
|
|
|
|
return &Date{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
|
|
|
|
}
|