I'm trying to use the validator components but I'm having trouble with daylight saving time.
It all started with a simple markup on a clean new website project:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBoxTest" runat="server"></asp:TextBox>
<asp:RangeValidator ID="RangeValidatorTest" runat="server"
Type="Date" MinimumValue="17/09/2013" MaximumValue="12/11/2014"
ControlToValidate="TextBoxTest" ErrorMessage="Invalid Date">
</asp:RangeValidator>
</div>
</form>
I should mention that all dates written on this question are "dd/MM/yyyy". I edited the web.config file and set the culture and uiculture to "pt-BR" and run the application.
Now, with these settings, if I try to input "20/10/2013" or "19/10/2014" it says it is not a valid date.
Those are exactly the dates when it will start the daylight saving time on those years.
If I turn off the option on my dev machine to change the date and time automatically the validator works properly.
Going further, I debugged the client javascript generated by the validators (the culture and uiculture were set on web.config - so I expect the script to be generated accordingly). The error happens in a function called ValidatorConvert. Here's the piece causing the problem:
var date = new Date(year, month, day);
return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;
On my machine, the constructor for the Date object on the first line with 2013, 10 and 20 as parameters create an object with the following: Sat Oct 19 23:00:00 UTC-0300 2013. This means it is respecting my Windows configuration and subtracting automatically 1 hour due to the start of daylight saving time. And because of that the day portion is different than the original one which makes the validation fail as if it were an invalid date.
Is that the way it is supposed to work? It seems like the Javascript for the validators aren't really dynamic as I thought.
How can I work with daylight saving time and those validators?
By the way, I did this test on Visual Studio 2010 (and all service packs available) and .Net Framework 4.0.
I know a couple ways to get out of this problem if I was using Asp.Net MVC but this example belongs to a much bigger system built with WebForms.
For the sake of clarity, here's two debugger screens: