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

Time layout does not have any effect for yaml #85

Open
nononsensecode opened this issue Jan 20, 2022 · 1 comment
Open

Time layout does not have any effect for yaml #85

nononsensecode opened this issue Jan 20, 2022 · 1 comment

Comments

@nononsensecode
Copy link

nononsensecode commented Jan 20, 2022

Below given is the configuation file

type Config struct { Order struct { Date time.Time ``yaml:"date" env:"ORDER_DATE" env-layout:"02/01/2006 03:04:05 PM"`` } ``yaml:"order"`` }

Below is the yml file

order: date: 17/01/2022 10:00:00 AM subtime: 5m

I am getting the following error:
config file parsing error: parsing time "Mon Jan 17 10:00:00 2022" as "2006-01-02T15:04:05Z07:00": cannot parse "Mon Jan 17 10:00:00 2022" as "2006"

I also cloned your repo, edited the test eleanenv_test.go to include the following to the TestParseFile function

Time time.Time ``yaml:"time" json:"time" toml:"time" env-layout:"02/01/2006 03:04:05 PM"``

On running the test I got the following errors:

go test github.com/ilyakaznacheev/cleanenv --- FAIL: TestParseFile (0.00s) --- FAIL: TestParseFile/yaml (0.00s) cleanenv_test.go:624: wrong error behavior config file parsing error: parsing time "17/01/2022 10:00:00 AM" as "2006-01-02T15:04:05Z07:00": cannot parse "1/2022 10:00:00 AM" as "2006", wantErr false --- FAIL: TestParseFile/json (0.00s) cleanenv_test.go:624: wrong error behavior config file parsing error: parsing time "\"17/01/2022 10:00:00 AM\"" as "\"2006-01-02T15:04:05Z07:00\"": cannot parse "1/2022 10:00:00 AM\"" as "2006", wantErr false --- FAIL: TestParseFile/toml (0.00s) cleanenv_test.go:624: wrong error behavior config file parsing error: parsing time "17/01/2022 10:00:00 AM" as "2006-01-02T15:04:05Z07:00": cannot parse "1/2022 10:00:00 AM" as "2006", wantErr false FAIL FAIL github.com/ilyakaznacheev/cleanenv 0.004s FAIL

@illiafox
Copy link
Contributor

env-layout tag affects only environmental variables, because yaml parsing is done by the other library

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