Odd problem parsing dates

15 posts, 0 answers
  1. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 22 Jul 2009 Link to this post

    I'm running into an odd issue parsing dates when I set the culture. Here's the repro steps
    1. Create a blank Telerik Web Application
    2. On the Default.aspx page drop a RadScriptManager and a RadDatePicker
    3. In the code behind, add the following method:

    protected override void InitializeCulture() 
        base.InitializeCulture(); 
     
        var culture = CultureInfo.CurrentCulture.Clone() as CultureInfo; 
        if ( culture == null ) 
            return
     
        culture.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy"
     
        this.Culture = culture.ToString(); 
        this.UICulture = culture.ToString(); 
        Thread.CurrentThread.CurrentCulture = culture; 
        Thread.CurrentThread.CurrentUICulture = culture; 
     


    Notice that all I'm doing is cloning the existing Culture (which in my case happens to be en-US) and changing the default ShortDateTimePattern.

    The effect of doing this is that the control will parse dates as if they are European dates instead of US dates. For example, entering 05012009 will result in 05-Jan-2009 instead of 01-May-2009.

  2. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 23 Jul 2009 Link to this post

    In the off chance that the answer to my question is something akin to the fact that parser uses the ShortDatePattern for parsing, how do I globally set the DisplayDateFormat for all date controls in my application at runtime (I'm fully aware that I can use skins to do it at design time)?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 24 Jul 2009 Link to this post

    Hello Thomas,

    I have answered to your support thread opened on the same matter. Here is a quote of the answer:

    Hello Thomas,

    Thank you for contacting us.

    Unfortunately there is no easy way how to attain the required functionality. One possible solution is to override RadDatePicker and set DisplayDateFormat property. Hence you will need to use everywhere this control in your application. Thus the DisplayDateFormat will be set for each control used in the app. Nevertheless if you need to change the DisplayDateFormat depending on some condition, you still will need to set it for the control placed on the current page.

    Let me know whether this helps.

    All the best,


    Sincerely yours,
    Georgi Krustev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 24 Jul 2009 Link to this post

    Am I to also assume that the CultureInfo's DateTimeFormat.ShortDatePattern property is used in the parsing algorithm? That's a shame because the solution seems intuitive IMO but I can understand how that would cause a problem.

    Unfortunately, this puts me into a rather ugly lurch as our application is used by numerous customers in multiple countries that themselves have offices in multiple countries where they want to standardize the date display which is why a skin won't work unless I jump through some serious hoops a try writing the skin file at runtime (bleh). It's that, or replace every single date control in the system with a derived version.
  6. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 30 Jul 2009 Link to this post

    Hello Thomas,

    I am afraid that the options you have is then one suggested by my colleague Georgi in his previous replay. However i will forward your feedback to our developers.

    Regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 24 Aug 2009 Link to this post

    I've come back to this issue on the date formats. In general, it is a PITA that there is no way to globally set the date format at run time. In fact, I ran into an interesting issue with changing the format. I notice that changing the format which is set at runtime does not take effect if you are using an expression builder and have compiled the app with aspnet_compiler. The only way I was able to force the effect to occur is by recompiling the app using aspnet_compiler.

    I do not want to make a derived date control because there is plenty of subitems on the date control that I don't want to have to implement. It makes for a brittle solution.

    I seem to remember way back in the day, it used to be possible to set the date format in the web.config file. Even that would be much nicer as I have many clients running off the same code base but with different parent web.config files.

    In the end, we're going to have to set the date format using the code we use for security which enables/disables all the controls on the page. Even that may not work entirely as some of the controls may be buried in placeholders, grids etc. Not sure but I'll post again when I know.
  8. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 24 Aug 2009 Link to this post

    As another follow up, we basically ended up having to set the DateFormat and DisplayDateFormat on each control manually (i.e. in markup everywhere). In doing so, we realized that setting these values probably does nothing to the format of the calendar, which I believe will use the page's culture (and thus the browser's by default) for formatting. I also note that I cannot set the calendar's culture in javascript which would have helped.
  9. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 27 Aug 2009 Link to this post

    Hello Thomas,

    The only way to set the culture of the control is described in these online help articles:
    http://www.telerik.com/help/aspnet-ajax/calendar_localizationcultureinfo.html
    http://www.telerik.com/help/aspnet-ajax/calendar_localizationdateformatpattern.html

    Nevertheless I will follow-up your suggestions to our developers for further consideration.

    Regards,
    Georgi Krustev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 27 Aug 2009 Link to this post

    Am I correct in assuming that the DisplayDateFormat and DateFormat override the Culture even if all three are set in code?
  11. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 27 Aug 2009 Link to this post

    Btw, the date format pattern won't work without also setting the culture as that creates the same problem: the format is based on the user's browser culture. The scenario we have is that some of our customers have offices in multiple parts of the world and want the same format used for display and entry at all offices and the display format is not always standard. With many dozens of date controls, it is real problem to control the display and entry settings globally across the app.
  12. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 31 Aug 2009 Link to this post

    Hello Thomas,

    The expected behavior of the calendar is to get the Culture from the page. If you explicitly set the culture of the control, the page's Culture will be overridden. If you set just the date format the input control will use the culture of the page. You mentioned for the DateFormat, DisplayDataFormat in one of your earlier posts. In general these properties uses the current culture to format the date, they do not override it.

    I suppose that in order to achieve your goal you will need to set culture property of the Page. Thus offices around the world will open page with explicitly set culture.

    Regards,
    Georgi Krustev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  13. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 31 Aug 2009 Link to this post

    I tried setting the culture of the page. That should solve the issue with the calendar but not the display format issue. I.e., I still have to add markup to every DatePicker control to explicitly set the display format if the user desires something different than default for the given culture.
  14. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 01 Sep 2009 Link to this post

    Hello Thomas,

    I hope you will agree with me, that if the requirement is to show the date  in different than the set culture it is required to set the DateFormat and the DisplayDateFormat. Unfortunately you will need to set them declaratively for every calendar.

    Regards,
    Georgi Krustev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  15. Thomas
    Thomas avatar
    143 posts
    Member since:
    Feb 2007

    Posted 01 Sep 2009 Link to this post

    I do agree and therein is the issue. I have many dozens of date controls in my app. Most customers want a display date format of dd-MMM-yyyy for clarity when dealing with multiple cultures to avoid the confusion between m/d/yyyy and d/m/yyyy. The problem is that this obviously deviates from the ShortDatePattern on any culture. I want the ability to globally set that format in the web.config file or barring that at runtime. I cannot set it in a Theme because there are times when clients want to change that (e.g. some do want m/d/yyyy, some m/d/yy etc) and with many hundreds of clients, I want (and have) a single code base.
  16. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 04 Sep 2009 Link to this post

    Hello Thomas,

    You can set a value for the date format in the web.config file. Hence you can retrieve it for every RadDatePicker control and to set it. Thus you can achieve global assigning of the DateFormat property of the RadDatePicker.

    Best regards,
    Georgi Krustev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017