mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 04:14:39 +03:00
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:
@@ -23,17 +23,5 @@ func ParseDateStringAsTime(dateString string) (time.Time, error) {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// Support partial dates: year-month format
|
||||
t, e = time.Parse("2006-01", dateString)
|
||||
if e == nil {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// Support partial dates: year only format
|
||||
t, e = time.Parse("2006", dateString)
|
||||
if e == nil {
|
||||
return t, nil
|
||||
}
|
||||
|
||||
return time.Time{}, fmt.Errorf("ParseDateStringAsTime failed: dateString <%s>", dateString)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestParseDateStringAsTime(t *testing.T) {
|
||||
@@ -16,13 +15,11 @@ func TestParseDateStringAsTime(t *testing.T) {
|
||||
{"Date only", "2014-01-02", false},
|
||||
{"Date with time", "2014-01-02 15:04:05", false},
|
||||
|
||||
// Partial date formats (new support)
|
||||
{"Year-Month", "2006-08", false},
|
||||
{"Year only", "2014", false},
|
||||
|
||||
// Invalid formats
|
||||
{"Invalid format", "not-a-date", true},
|
||||
{"Empty string", "", true},
|
||||
{"Year-Month", "2006-08", true},
|
||||
{"Year only", "2014", true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -44,37 +41,3 @@ func TestParseDateStringAsTime(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDateStringAsTime_YearOnly(t *testing.T) {
|
||||
result, err := ParseDateStringAsTime("2014")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to parse year-only date: %v", err)
|
||||
}
|
||||
|
||||
if result.Year() != 2014 {
|
||||
t.Errorf("Expected year 2014, got %d", result.Year())
|
||||
}
|
||||
if result.Month() != time.January {
|
||||
t.Errorf("Expected month January, got %s", result.Month())
|
||||
}
|
||||
if result.Day() != 1 {
|
||||
t.Errorf("Expected day 1, got %d", result.Day())
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDateStringAsTime_YearMonth(t *testing.T) {
|
||||
result, err := ParseDateStringAsTime("2006-08")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to parse year-month date: %v", err)
|
||||
}
|
||||
|
||||
if result.Year() != 2006 {
|
||||
t.Errorf("Expected year 2006, got %d", result.Year())
|
||||
}
|
||||
if result.Month() != time.August {
|
||||
t.Errorf("Expected month August, got %s", result.Month())
|
||||
}
|
||||
if result.Day() != 1 {
|
||||
t.Errorf("Expected day 1, got %d", result.Day())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user