Dates Class and XMLGregorianCalendar representation

12 views
Skip to first unread message

Jeff Vettraino

unread,
Nov 13, 2014, 6:24:08 PM11/13/14
to ddms...@googlegroups.com
Hi Brian,

I was wondering what the reason was for no longer including a date Object representation of the values in the Dates object (the XMLGregorianCalendar one is deprecated).  I see the note in the about the new DDMS 4.1 date format that doesn't include seconds (strange), but wouldn't a date representation of that format be the value with the seconds set to 00 (kind of what is done for milliseconds if they don't appear, or the time if it doesn't appear)?

What I am trying to do is to come up with a way to go from the DDMS Dates Object values to a Java Date or XMLGregorianCalendar representation, and I am not sure the best approach b/c of the deprecated method.  

Thanks!

Jeff

Brian Uri!

unread,
Nov 13, 2014, 7:18:23 PM11/13/14
to ddms...@googlegroups.com
Hi Jeff,

The 4.1 schema change made this a little messy as you can see:
  • Previously, the allowable date strings were all standard XML date types, and could be directly converted into XMLGregorianCalendar instances. The deprecated method would return this instance.
  • DDMS 4.1 added a custom string pattern to the union of allowable date strings. This string is not directly convertible to an XMLGregorianCalendar. This is when I deprecated the original accessor methods and added the getXxxxString() methods instead.
I used the deprecated tags to alert users about the potential for confusion, but have no plans to ever actually remove this method. It will still continue to return XMLGregorianCalendar instances for dates that it can understand.

Your suggestion to default to 00 seconds for the new date type is sensible and could be fit into the existing method without signature change. I opened up Issue 221 to track this.

In the meantime, you can apply the logic with a utility conversion method like this:

public static XMLGregorianCalendar interimConvert(XMLGregorianCalendar xmlDate, String rawDate) {
    // One of the standard XML date types
    if (xmlDate != null) {
        return (xmlDate);
    }
    // Custom DDMS date type
    if (xmlDate == null && !Util.isEmpty(rawDate)) {
        // Use a SimpleDateFormat to parse the DDMS custom pattern into a Date.
        // Create a GregorianCalendar instance based on the Date.
        // Create an XMLGregorianCalendar instance based on the GregorianCalendar.
        // return the XMLGregorianCalendar instance.
    }
    // No date value recorded
    return (null);
}

It could then be called (rather verbosely):

XMLGregorianCalendar approvedOn = interimConvert(dates.getApprovedOn(), dates.getApprovedOnString());

Once a comparable fix is added to DDMSence, that line could simplify to:

XMLGregorianCalendar approvedOn = dates.getApprovedOn();

Regards,
BU

--
You received this message because you are subscribed to the Google Groups "DDMSence" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ddmsence+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeff Vettraino

unread,
Nov 13, 2014, 7:34:45 PM11/13/14
to ddms...@googlegroups.com, br...@urizone.net
Thanks Brian!!!!

That will work perfectly!  I really appreciate the thoughtful and quick response.

Jeff Vettraino

unread,
Nov 13, 2014, 8:55:05 PM11/13/14
to ddms...@googlegroups.com, br...@urizone.net
Just an FYI I used the following method (using the Joda Time formatters) to go from the String representations to a Date Object:

ISODateTimeFormat.dateTimeParser().parseDateTime(rawDate).toDate();

And tested the following formats:
  • 2013-08-04T11:57-00:00
  • 2013-08-04T11:57;
  • 2013-08-04T11:57Z

 

BU

unread,
Nov 14, 2014, 5:41:31 AM11/14/14
to ddms...@googlegroups.com
Thanks Jeff,

I should be able to push out a release with this fix in the Thanksgiving timeframe.

Regards,
BU

--

Jeff Vettraino

unread,
Nov 14, 2014, 11:25:45 AM11/14/14
to ddms...@googlegroups.com
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"
     **/
    protected static DateTimeFormatter DDMS_COMBINEDDATETYPE_FORMATTER = null;
    static {
        DateTimeParser[] parsers = {
            ISODateTimeFormat.dateTimeParser().getParser(),
            new DateTimeFormatterBuilder()
                    .append(ISODateTimeFormat.date())
                    .appendOptional(
                            new DateTimeFormatterBuilder().appendTimeZoneOffset("Z", true, 2, 4)
                                    .toFormatter().getParser()).toParser(),
            new DateTimeFormatterBuilder()
                    .append(ISODateTimeFormat.yearMonth())
                    .appendOptional(
                            new DateTimeFormatterBuilder().appendTimeZoneOffset("Z", true, 2, 4)
                                    .toFormatter().getParser()).toParser(),
            new DateTimeFormatterBuilder()
                    .append(ISODateTimeFormat.year())
                    .appendOptional(
                            new DateTimeFormatterBuilder().appendTimeZoneOffset("Z", true, 2, 4)
                                    .toFormatter().getParser()).toParser()};

        DDMS_COMBINEDDATETYPE_FORMATTER = new DateTimeFormatterBuilder().append(null, parsers)
                .toFormatter();
    }

Jeff Vettraino
Cohesive Integrations
jeff.ve...@cohesiveintegrations.com
(602) 332-1377

--
You received this message because you are subscribed to a topic in the Google Groups "DDMSence" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ddmsence/RibLqaZf8Ng/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ddmsence+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages