Results 1 to 2 of 2

Thread: TimeField related question

  1. #1
    Ext Premium Member
    Join Date
    Sep 2009
    Posts
    77
    Vote Rating
    0
      0  

    Default TimeField related question

    I have a widget that allows the user to select a start date and time and an end date and time for some specific filter.
    If the user wants to select the entire day, he has to select:
    start date: today at 00:00
    stop date: tomorrow at 00:00

    The customer wants the selection above to be:
    start date: today at 00:00
    stop date: today at 24:00

    So, for the start TimeField, the hour values should be between 00:00 and 23:00 and for the stop TimeField between 01:00 and 24:00.

    I managed to set the format for the second TimeField, such as the stop time field displays values from 1 to 24 this way:
    stopTimeField.setFormat(DateTimeFormat.getFormat("kk:mm"));

    There are a few problems:
    * the values are displayed in this order: 24, 1, 2, ..., 23
    * today at 24:00 means today at 00:00 instead of tomorrow at 00:00

    Are there some clean ways to fix the 2 above issues?

    Thanks,

    Dan

  2. #2
    Sencha User
    Join Date
    Nov 2010
    Posts
    209
    Vote Rating
    -2
      0  

    Default

    TimeField only contain time information and removes the dates. Hour 0 is always hour 0. I does not matter if the DateTimeFormat displays it as 00:00 or 24:00.
    So you need to handle 24:00 specially when you use the time value.

    The entries in the TimeField are stored in a liststore. You can use a custom storesorter to change the order and put 00:00 last.
    Below is an example:
    Code:
        final TimeField time = new TimeField(){
        @Override
        protected void initList() {
          super.initList();
          StoreSorter<Time> sort = new StoreSorter<Time>(new Comparator<Object>() {
            public int compare(Object o1, Object o2) {
              int t1 = (Integer)o1;
              int t2 = (Integer)o2;
              t1 = t1 == 0 ? 24 : t1;
              t2 = t2 == 0 ? 24 : t2;
              return t1 - t2;
            }
          });
          getStore().setStoreSorter(sort);
          getStore().sort("hour", null);
        }
        };
    
        time.setIncrement(60);
        time.setFormat(DateTimeFormat.getFormat("kk:mm"));

Similar Threads

  1. Grouping related question?
    By businessman332211 in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 1 Aug 2008, 6:43 AM
  2. Grid related question?
    By businessman332211 in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 17 Jul 2008, 11:28 AM
  3. Question about using Viewport, BorderLayout related.
    By tdondich in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 20 Nov 2007, 9:04 PM
  4. some question related to Connection
    By kd21 in forum Ext 1.x: Help & Discussion
    Replies: 0
    Last Post: 16 Feb 2007, 12:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •