ilyakaznacheev / cleanenv

✨Clean and minimalistic environment configuration reader for Golang
MIT License
1.61k stars 111 forks source link

Time layout does not have any effect for yaml #85

Open nononsensecode opened 2 years ago

nononsensecode commented 2 years ago

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 commented 1 year ago

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