forked from mirrors/homebox
fix: date and datetime regression (#282)
* use custom types.Date implementation * fix user registration bug * remove sanity check * fix datetime bug
This commit is contained in:
parent
44f13f751a
commit
607b06d2f2
10 changed files with 162 additions and 52 deletions
|
@ -7,9 +7,9 @@ import (
|
|||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hay-kot/homebox/backend/internal/data/repo"
|
||||
"github.com/hay-kot/homebox/backend/internal/data/types"
|
||||
)
|
||||
|
||||
func determineSeparator(data []byte) (rune, error) {
|
||||
|
@ -62,15 +62,6 @@ func parseFloat(s string) float64 {
|
|||
return f
|
||||
}
|
||||
|
||||
func parseDate(s string) time.Time {
|
||||
if s == "" {
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
p, _ := time.Parse("01/02/2006", s)
|
||||
return p
|
||||
}
|
||||
|
||||
func parseBool(s string) bool {
|
||||
switch strings.ToLower(s) {
|
||||
case "true", "yes", "1":
|
||||
|
@ -92,6 +83,7 @@ type csvRow struct {
|
|||
}
|
||||
|
||||
func newCsvRow(row []string) csvRow {
|
||||
|
||||
return csvRow{
|
||||
Location: row[1],
|
||||
LabelStr: row[2],
|
||||
|
@ -109,13 +101,13 @@ func newCsvRow(row []string) csvRow {
|
|||
Manufacturer: row[9],
|
||||
Notes: row[10],
|
||||
PurchaseFrom: row[11],
|
||||
PurchaseTime: parseDate(row[13]),
|
||||
PurchaseTime: types.DateFromString(row[13]),
|
||||
LifetimeWarranty: parseBool(row[14]),
|
||||
WarrantyExpires: parseDate(row[15]),
|
||||
WarrantyExpires: types.DateFromString(row[15]),
|
||||
WarrantyDetails: row[16],
|
||||
SoldTo: row[17],
|
||||
SoldPrice: parseFloat(row[18]),
|
||||
SoldTime: parseDate(row[19]),
|
||||
SoldTime: types.DateFromString(row[19]),
|
||||
SoldNotes: row[20],
|
||||
},
|
||||
}
|
||||
|
|
|
@ -50,9 +50,9 @@ func Test_CorrectDateParsing(t *testing.T) {
|
|||
entity := newCsvRow(record)
|
||||
expected := expected[i-1]
|
||||
|
||||
assert.Equal(t, expected, entity.Item.PurchaseTime, fmt.Sprintf("Failed on row %d", i))
|
||||
assert.Equal(t, expected, entity.Item.WarrantyExpires, fmt.Sprintf("Failed on row %d", i))
|
||||
assert.Equal(t, expected, entity.Item.SoldTime, fmt.Sprintf("Failed on row %d", i))
|
||||
assert.Equal(t, expected, entity.Item.PurchaseTime.Time(), fmt.Sprintf("Failed on row %d", i))
|
||||
assert.Equal(t, expected, entity.Item.WarrantyExpires.Time(), fmt.Sprintf("Failed on row %d", i))
|
||||
assert.Equal(t, expected, entity.Item.SoldTime.Time(), fmt.Sprintf("Failed on row %d", i))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue