You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the absence of a time zone indicator, Parse returns a time in UTC.
If we provide date strings to DateRule validator without any timezone information, it will always assume it to be in UTC.
On top of it, DateRule doesn't provide any functionality to provide custom time.Location.
This is causing issues because the rule is failing when trying to compute whether the date is actually between minDate and maxDate for some cases where timezone is different and Min and Max are close to the input date string.
This I feel is not the desired behaviour and I think DateRule should instead use time.ParseInLocation with a default timezone and also give users the option to provide a custom timezone if they want.
I am really not sure what should be the default timezone. I can think of 2 possibilities:
Using time.Local as default but that would make it backward incompatible
But if we go with time.UTC as default timezone it will make the validation logic more verbose as we'll have to specify timezone while defining each rule if our local timezone is different than UTC
Let me know what do you think.
The text was updated successfully, but these errors were encountered:
Description
While using the builtin DateRule validation rule, I noticed that it uses time.Parse.
time.Parse documentation states that:
If we provide date strings to DateRule validator without any timezone information, it will always assume it to be in UTC.
On top of it, DateRule doesn't provide any functionality to provide custom time.Location.
This is causing issues because the rule is failing when trying to compute whether the date is actually between minDate and maxDate for some cases where timezone is different and
Min
andMax
are close to the input date string.Here's an example demonstrating this behaviour: https://go.dev/play/p/JgKOS6i5oJZ
Proposal
This I feel is not the desired behaviour and I think DateRule should instead use time.ParseInLocation with a default timezone and also give users the option to provide a custom timezone if they want.
I am really not sure what should be the default timezone. I can think of 2 possibilities:
time.Local
as default but that would make it backward incompatibletime.UTC
as default timezone it will make the validation logic more verbose as we'll have to specify timezone while defining each rule if our local timezone is different than UTCLet me know what do you think.
The text was updated successfully, but these errors were encountered: