[FIXED] [2.3] TimeField SelectedTime is invalid

  1. #1

    [FIXED] [2.3] TimeField SelectedTime is invalid

    Hi,

    There seems to be a problem with the TimeField when setting Format and page Culture.

    I set the Format to "h:mm:ss tt" and SelectedTime to 15:23. The value displayed in the time field is "3:23:00 p.m.", while the values in the list look like this: "3:45:00 pm". The time field is invalid: "3:23:00 p.m. is not a valid time".

    If I choose a value from the list and press OK, the SelectedTime has a value of -10675199.02:48:05.4775808. The Value and Text fields have the same value as the SelectedTime, while the RawText and RawValue fields have the correct value.

    Version of Ext.Net: 2.2.0.1
    Framework: .NET Framework 4
    Operating system: Windows 8
    Visual Studio version: 2012

    I've tested this on Firefox 21, Chrome 27 and IE 10.

    Simplified code:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Threading" %>
    <%@ Import Namespace="System.Globalization" %>
    <script runat="server">
       const string PAGE_CULTURE = "ro-RO";
    
       protected void Page_Load( object sender, EventArgs e )
       {
          if ( !Page.IsPostBack )
          {
             fldTime.Format = "h:mm:ss tt";
             fldTime.SelectedTime = new TimeSpan( 15, 23, 0 );
          }
       }
    
       protected override void InitializeCulture()
       {
          Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture( PAGE_CULTURE );
          Thread.CurrentThread.CurrentUICulture = new CultureInfo( PAGE_CULTURE );
    
          base.InitializeCulture();
       }
    
       protected void btnOK_DirectClick( object sender, Ext.Net.DirectEventArgs e )
       {
          TimeSpan tsValue = fldTime.SelectedTime;
       }
    </script>
    <html>
    <head><title>Set Culture</title></head>
    <body>
       <form id="form1" runat="server">
          <ext:ResourceManager ID="ResourceManager1" runat="server"></ext:ResourceManager>
          <ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout">
             <Items>
                <ext:Container ID="Container1" runat="server" Region="Center">
                   <Items>
                      <ext:Panel ID="Panel1" runat="server" Layout="FormLayout">
                         <Items>
                            <ext:TimeField ID="fldTime" runat="server" FieldLabel="Time" Margin="5" InputWidth="120" LabelWidth="50" AllowBlank="false" AllowOnlyWhitespace="false"></ext:TimeField>
                         </Items>
                         <Buttons>
                            <ext:Button ID="btnOK" runat="server" Text="OK" OnDirectClick="btnOK_DirectClick"></ext:Button>
                         </Buttons>
                      </ext:Panel>
                   </Items>
                </ext:Container>
             </Items>
          </ext:Viewport>
       </form>
    </body>
    </html>
    I'd like to know if this is going to be fixed or it's a known issue (with a workaround hopefully). We need to deliver a proof-of-concept application using Ext.Net and once it's approved by the client, we'll buy the Ext.Net license. However, this TimeField issue is a major problem for us.
    Last edited by Daniil; Jul 05, 2013 at 12:21 PM. Reason: [FIXED] [2.3]
  2. #2
    Hi Edgar,

    It is because of " tt" in the Format. If you remove it it will work.

    The "ro-RO" (and many other) locale doesn't use "am/pm". So, it conflicts.

    You probably should not set up such a Format for "ro-RO" if you support locales.

    Though, we will look what we can do with that.
  3. #3
    Hi Daniil,

    Thanks for the reply.

    What I posted yesterday is just a simplified version of the code. For each user we create a custom culture, based on the chosen language. The user must also be able to set his/her own formats for time, date, numbers etc. Thus, there could be a "tt" in a time format based on the "ro" culture, if the user wants it.

    Each user has a CultureInfo object created like this (simplified code):

    UserCulture = CultureInfo.CreateSpecificCulture( "ro")
    and then this object is used in the InitializeCulture method:
    Thread.CurrentThread.CurrentCulture = UserCulture ;
    Thread.CurrentThread.CurrentUICulture = UserCulture;
    Is there any workaround we could use?
    Last edited by Daniil; Jul 02, 2013 at 3:51 PM. Reason: Please use [CODE] tags
  4. #4
    Currently, a TimeField's SelectedTime is serialized by .NET depending on locale. It doesn't render "am/pm" if a locale doesn't support "tt". A submitted TimeField's Value is also parsed by .NET depending on locale. So, again, it cannot parse a date with "am/pm" if a locale doesn't support "tt".

    In this situation, we should probably eliminate "tt" from a TimeField's Format if a locale doesn't support it. I will discuss it with the colleagues.

    Though, anyway, it is not a solution for you since you need "tt" even for locales which don't support it. For your case a possible solution could be creating a custom TimeField control overriding its ValueProxy (rendering a SelectedTime to client) and Value (parsing a submitted value) properties as you need.

    Hope this helps.
  5. #5
    Quote Originally Posted by Daniil View Post
    For your case a possible solution could be creating a custom TimeField control overriding its ValueProxy (rendering a SelectedTime to client) and Value (parsing a submitted value) properties as you need.

    Hope this helps.
    Thanks Daniil, I will look into it.
  6. #6
    Finally, we decided to strip out the "am/pm" thing from a TimeField's Format, if the current locale doesn't support it.

    Again, it is still actual for you.
    Though, anyway, it is not a solution for you since you need "tt" even for locales which don't support it. For your case a possible solution could be creating a custom TimeField control overriding its ValueProxy (rendering a SelectedTime to client) and Value (parsing a submitted value) properties as you need.

Similar Threads

  1. Timefield Problem(am/pm)
    By kiran malgi in forum 1.x Help
    Replies: 4
    Last Post: Jun 22, 2010, 4:31 AM
  2. TimeField - Help
    By Jose Pereira dos anjos Júnior in forum 1.x Help
    Replies: 0
    Last Post: Jun 07, 2010, 2:09 AM
  3. [CLOSED] TimeField SelectedTime
    By pschojer in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 11, 2009, 7:35 AM
  4. TimeField
    By jmilton in forum 1.x Help
    Replies: 0
    Last Post: May 27, 2009, 12:21 PM

Tags for this Thread

Posting Permissions