Date precision (#6359)

* Remove month/year only formats from ParseDateStringAsTime
* Add precision field to Date and handle parsing year/month-only dates
* Add date precision columns for date columns
* Adjust UI to account for fuzzy dates
This commit is contained in:
WithoutPants
2025-12-08 09:11:40 +11:00
committed by GitHub
parent eb9d0705bc
commit 7db394bbea
23 changed files with 285 additions and 154 deletions

View File

@@ -5,6 +5,7 @@ import (
"time"
"github.com/stashapp/stash/pkg/models"
"gopkg.in/guregu/null.v4"
)
const sqliteDateLayout = "2006-01-02"
@@ -54,12 +55,12 @@ func (d NullDate) Value() (driver.Value, error) {
return d.Date.Format(sqliteDateLayout), nil
}
func (d *NullDate) DatePtr() *models.Date {
func (d *NullDate) DatePtr(precision null.Int) *models.Date {
if d == nil || !d.Valid {
return nil
}
return &models.Date{Time: d.Date}
return &models.Date{Time: d.Date, Precision: models.DatePrecision(precision.Int64)}
}
func NullDateFromDatePtr(d *models.Date) NullDate {
@@ -68,3 +69,11 @@ func NullDateFromDatePtr(d *models.Date) NullDate {
}
return NullDate{Date: d.Time, Valid: true}
}
func datePrecisionFromDatePtr(d *models.Date) null.Int {
if d == nil {
// default to day precision
return null.Int{}
}
return null.IntFrom(int64(d.Precision))
}