Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loading string data #152

Open
dowglaz opened this issue Dec 6, 2022 · 1 comment
Open

Error loading string data #152

dowglaz opened this issue Dec 6, 2022 · 1 comment

Comments

@dowglaz
Copy link

dowglaz commented Dec 6, 2022

I have the current data in the table creation:

amount varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL

and in the fixture file:

amount: "000000601"

When it loads the fixtures, for some unknown reason, it converts it to: 0000-06-01 00:00:00 -0659 LMT.

When I remove the quotes in the fixture file:

amount: 000000601

it converts correctly to a varchar.

However, I would like to keep being explicit about the data type by using quotes.

@slsyy
Copy link
Contributor

slsyy commented Jul 30, 2024

Perhaps that value is implicitly casted to a time.Time in this code

testfixtures/time.go

Lines 8 to 43 in 98baced

var timeFormats = [...]string{
"2006-01-02",
"2006-01-02 15:04",
"2006-01-02 15:04:05",
"20060102",
"20060102 15:04",
"20060102 15:04:05",
"02/01/2006",
"02/01/2006 15:04",
"02/01/2006 15:04:05",
"2006-01-02T15:04-07:00",
"2006-01-02T15:04:05-07:00",
"2006-01-02T15:04:05Z07:00",
"2006-01-02 15:04:05Z07:00",
"2006-01-02T15:04:05Z0700",
"2006-01-02 15:04:05Z0700",
"2006-01-02T15:04:05Z07",
"2006-01-02 15:04:05Z07",
"2006-01-02 15:04:05 MST",
}
func (l *Loader) tryStrToDate(s string) (time.Time, error) {
loc := l.location
if loc == nil {
loc = time.Local
}
for _, f := range timeFormats {
t, err := time.ParseInLocation(f, s, loc)
if err != nil {
continue
}
return t, nil
}
return time.Time{}, fmt.Errorf(`testfixtures: could not convert string "%s" to time`, s)
}

Removing this pattern would help, but I am worried about breaking a backward compatibility to this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants