Add function to create a new date construct

This commit is contained in:
Jason Streifling 2024-10-15 16:25:45 +02:00
parent 7de921b1b5
commit 8bfd8a648e

12
date.go
View File

@ -10,6 +10,14 @@ type Date struct {
DateTime string
}
func DateTime(t time.Time) string {
return string(t.Format(time.RFC3339))
}
func NewDate(t time.Time) *Date {
return &Date{DateTime: DateTime(t)}
}
func (d *Date) Check() error {
if d.DateTime == "" {
return errors.New("date time element of date is empty")
@ -17,7 +25,3 @@ func (d *Date) Check() error {
return nil
}
func DateTime(t time.Time) string {
return string(t.Format(time.RFC3339))
}