Re: [DDMSence] Dates Class and XMLGregorianCalendar representation

3 views
Skip to first unread message

BU

unread,
Nov 20, 2014, 9:29:20 AM11/20/14
to ddms...@googlegroups.com
Thanks for the test values. The good news is that most of these formats are already XSD date types, and can directly translate into an XMLGregorianCalendar. So, the Joda date formatter only needs to handle the 3 DDMS custom dates:
  • 2013-08-04T11:57-00:00 matches ddms:DateHourMinType.
  • 2013-08-04T11:57 matches ddms:DateHourMinType.
  • 2013-08-04T11:57Z matches ddms:DateHourMinType.

I sorted the test values with this method:

  public static void identifyDateType(String date) {
    final String DDMS_DATE_HOUR_MIN_PATTERN = "[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}(Z|[\\-\\+][0-9]{2}:[0-9]{2})?";
    final Set<QName> DATE_DATATYPES = new HashSet<QName>();
    DATE_DATATYPES.add(DatatypeConstants.DATE);
    DATE_DATATYPES.add(DatatypeConstants.DATETIME);
    DATE_DATATYPES.add(DatatypeConstants.GYEARMONTH);
    DATE_DATATYPES.add(DatatypeConstants.GYEAR);
   
    try {
      XMLGregorianCalendar calendar = getDataTypeFactory().newXMLGregorianCalendar(date);
      if (DATE_DATATYPES.contains(calendar.getXMLSchemaType())) {
        System.out.println(date + " matches a standard XML date type. (" + calendar.getXMLSchemaType() + ")");
      }
    }
    catch (IllegalArgumentException e) {
      if (Pattern.matches(DDMS_DATE_HOUR_MIN_PATTERN, date)) {
        System.out.println(date + " matches ddms:DateHourMinType.");
      }
      else {
        System.out.println(date + " is not a valid DDMS date value.");
      }
    }
  }

Regards,
BU

On Fri, Nov 14, 2014 at 11:25 AM, Jeff Vettraino <jeff.ve...@cohesiveintegrations.com> wrote:
Thanks Brain,

One thing I did run into is I was having issues with getting a valid XMLGregorianCalendar Date when the date only included the date and timezone (no year).  It could have been user error.  When you make the update you might want to check the various formats that the date could be in and verify.  Here is a list (might not contain all of possible formats), that I used, and because of the issue I ran into I ended up using JodaTime formatters to handle it as you can see below...

/**
     * Formatter that handles all of the following formats
     *  "2013-08-04T11:57:00.1-00:00"
     *  "2013-08-04T11:57:00.01"
     *  "2013-08-04T11:57:00.001Z"
     *  "2013-08-04T11:57:00-00:00"
     *  "2013-08-04T11:57:00"
     *  "2013-08-04T11:57:00Z"
     *  "2013-08-04T11:57-00:00"
     *  "2013-08-04T11:57"
     *  "2013-08-04T11:57Z"
     *  "2013-08-04T11:57:22-00:00"
     *  "2013-08-04T11:57:22"
     *  "2013-08-04T11:57:22Z"
     *  "2013-08-04T11:57:22.1-00:00"
     *  "2013-08-04T11:57:22.01"
     *  "2013-08-04T11:57:22.001Z"
     *  "2013-08-04Z"
     *  "2013-08-04"
     *  "2013-08-04-00:00"
     *  "2013-08Z"
     *  "2013-08"
     *  "2013-08-00:00"
     *  "2013Z"
     *  "2013"
     *  "2013-00:00"
     **/


Reply all
Reply to author
Forward
0 new messages