diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2022-05-07 17:58:20 -0600 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2022-05-07 18:07:13 -0600 |
commit | cfb633b3b5eed1a65b23cc641b1b250adffdbc8f (patch) | |
tree | 0f10762026e5fca27f3cbf3612cb3b8104e5d31c /srv/src/post/date.go | |
parent | 07806c694269f6226a0f42c9f2cfb8c7655afad9 (diff) |
Cleanup various small issues with post package
Diffstat (limited to 'srv/src/post/date.go')
-rw-r--r-- | srv/src/post/date.go | 59 |
1 files changed, 0 insertions, 59 deletions
diff --git a/srv/src/post/date.go b/srv/src/post/date.go deleted file mode 100644 index 34fe109..0000000 --- a/srv/src/post/date.go +++ /dev/null @@ -1,59 +0,0 @@ -package post - -import ( - "database/sql/driver" - "fmt" - "time" -) - -// Date represents a calendar date with no timezone information attached. -type Date struct { - Year int - Month time.Month - Day int -} - -// DateFromTime converts a Time into a Date, truncating all non-date -// information. -func DateFromTime(t time.Time) Date { - t = t.UTC() - return Date{ - Year: t.Year(), - Month: t.Month(), - Day: t.Day(), - } -} - -// ToTime converts a Date into a Time. The returned time will be UTC midnight of -// the Date. -func (d *Date) ToTime() time.Time { - return time.Date(d.Year, d.Month, d.Day, 0, 0, 0, 0, time.UTC) -} - -// Scan implements the sql.Scanner interface. -func (d *Date) Scan(src interface{}) error { - - if src == nil { - *d = Date{} - return nil - } - - ts, ok := src.(int64) - - if !ok { - return fmt.Errorf("cannot scan value %#v into Date", src) - } - - *d = DateFromTime(time.Unix(ts, 0)) - return nil -} - -// Value implements the driver.Valuer interface. -func (d Date) Value() (driver.Value, error) { - - if d == (Date{}) { - return nil, nil - } - - return d.ToTime().Unix(), nil -} |