mirror of
https://github.com/stashapp/stash.git
synced 2025-12-07 17:02:38 +01:00
38 lines
761 B
Go
38 lines
761 B
Go
package models
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"github.com/stashapp/stash/pkg/logger"
|
|
"github.com/stashapp/stash/pkg/utils"
|
|
"time"
|
|
)
|
|
|
|
type SQLiteDate struct {
|
|
String string
|
|
Valid bool
|
|
}
|
|
|
|
// Scan implements the Scanner interface.
|
|
func (t *SQLiteDate) Scan(value interface{}) error {
|
|
dateTime, ok := value.(time.Time)
|
|
if !ok {
|
|
t.String = ""
|
|
t.Valid = false
|
|
return nil
|
|
}
|
|
|
|
t.String = dateTime.Format("2006-01-02")
|
|
if t.String != "" {
|
|
t.Valid = true
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Value implements the driver Valuer interface.
|
|
func (t SQLiteDate) Value() (driver.Value, error) {
|
|
result, err := utils.ParseDateStringAsFormat(t.String, "2006-01-02")
|
|
if err != nil {
|
|
logger.Debugf("sqlite date conversion error: %s", err.Error())
|
|
}
|
|
return result, nil
|
|
}
|