Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    dateutil.setdateformatter - need setdatetimeformatter!

    Hi, not sure if this has been discussed, but i couldn't find any thread. My header is wrong, i'm talking about datetimeparser, not formatter!

    I have a need for a custom, locale specific dateformatter/parser. For most fields i want to display my datetime fields as "yyyy-MM-dd HH:mm".

    For this purpose i set dateutil.setdateformatter with a custom class, and a parser to parse it back into dates.

    for this i'm using
    Code:
    Dateutil.setdateformatter and dateutil.setdateparser
    However, my issue is that if i have an item, for example date field or datechooser which is date and not datetime, that formatter is still called, then with the string "yyyy-MM-dd" but without the time part -> i get an IllegalArgumentException.

    What i imagine is needed here is dateutil.setdatetimeparser in addition to setdateparser, but there is no such method.

    Is there another way to accomplish what i need i.e. one parser for date and another one for datetime ?

    Thanks for input.
    Last edited by mathias; 14 Feb 2012, 07:54.

    #2
    According to the current docs following formatters are available:
    Code:
    static void 	setNormalDateDisplayFormatter(DateDisplayFormatter formatter)
              Set the default formatter for date objects to the custom DateDisplayFormatter passed in.
    static void 	setShortDateDisplayFormatter(DateDisplayFormatter formatter)
              Set up a system wide default short date formatting function.
    static void 	setShortDatetimeDisplayFormatter(DateDisplayFormatter formatter)
              Set up a system wide default short datetime formatting function.
    So, looks like setNormalDateTimeDisplayFormatter() is missing ?
    MichalG

    Comment


      #3
      Oh man, i just realized that i wrote it up wrong in my post.

      I'm talking about DateUtil.setDateParser, not formatter.

      the dateparser is called when a textfield, datechooser etc is to be converted into a date item, to be sent to the server for example.

      My problem is that there's no setDateTimeParser. The dateparser gets called for both date and dateitem fields, from what i can see.

      Therefor i basically had to code for both of my formats, so that if it's not a datetime item, i catch the illegalargument and then assume its a date on the "yyyy-MM-dd" format:

      Code:
      DateUtil.setDateParser(new DateParser() {
                  public Date parse(String dateString) {
                      try {
                          return dateTimeFormat.parse(dateString);
                      } catch (IllegalArgumentException e) {
                          try {
                              return dateFormat.parse(dateString);
                          } catch (IllegalArgumentException e1) {
                          }
                      }
                      return null;
                  }
              });
      It would be great if there was a DateUtil.setDateTimeParser...

      Comment


        #4
        I see.
        I am doing the same in the setDateParser().
        Right, it would be nice to have setDateTimeParser().
        MichalG

        Comment


          #5
          Definitely. I'm not sure i remember correctly, but i thought i read somewhere that DateUtils would get a couple of upgrades. Guess this nice one didn't make it...

          Comment

          Working...
          X