Intelligent defaults with DDMS 4.1 custom date strings

Description

(Imported from Google Code)
Suggested by Jeff Vettraino:

The date attributes in the Dates component were originally standard XML date types. In DDMS 4.1, a custom date format was added.

To support this, I originally deprecated the Dates accessors that returned attribute values as XMLGregorianCalendar instances, and instead offered a getXxxxString() accessor to get to the raw string data, unparsed.

Jeff suggests that the DDMS 4.1 custom date format could probably be compatible with XMLGregorianCalendar by providing defaults for missing values – for example, 00 seconds when no seconds are included in the string. This would allow the original accessor methods to return an XMLGregorianCalendar instance for the DDMS custom format, and the methods would no longer need to be marked as deprecated.

Custom date pattern:
http://metadata.ces.mil/dse/irs/DDMS/Documentation/4/DDMS_4_1_DateHourMinType.html#Link07D50DD0

All allowable date strings:
http://metadata.ces.mil/dse/irs/DDMS/Documentation/4/DDMS_4_1_CombinedDateType.html

Activity

Show:
Brian Uri
November 20, 2014, 3:15 PM

Complete in rev. 953.

Brian Uri
November 20, 2014, 1:42 PM

Specific new accessor rules:

Attributes are considered missing when the accessor is called in a outdated DDMS version (e.g. calling getApprovedOnString() on a DDMS 2.0 resource).

ddms:dates/@ddms:created (ddms:CombinedDateType, optional, all versions)
ddms:dates/@ddmsosted (ddms:CombinedDateType, optional, all versions)
ddms:dates/@ddms:validTil (ddms:CombinedDateType, optional, all versions)
ddms:dates/@ddms:infoCutOff (ddms:CombinedDateType, optional, all versions)
ddms:dates/@ddms:approvedOn (ddms:CombinedDateType, optional, since DDMS 3.1)
ddms:dates/@ddms:receivedOn (ddms:CombinedDateType, optional, since DDMS 4.0.1)
getXxxxString():
Returns empty string if attribute value is empty or missing. Never returns null.
Returns raw string otherwise.
getXxxx():
Returns null if string accessor returns an empty string.
Returns XMLGregorianCalendar instance otherwise.

ddmsrocessingInfo/@ddms:dateProcessed (ddms:CombinedDateType, required, since DDMS 4.0.1)
getDateProcessedString():
Always returns raw string value of required attribute. Never returns null.
getDateProcessed():
Always returns XMLGregorianCalendar instance for attribute. Never returns null.

ddms:temporalCoverage/@ddms:end (ddms:ExtendedCombinedDateType, default, all versions)
ddms:temporalCoverage/@ddms:start (ddms:ExtendedCombinedDateType, default, all versions)
getXxxxString():
Returns empty string if attribute value is empty or missing. Never returns null.
Returns raw string otherwise.
getXxxx():
Returns null if string accessor returns an empty string, or "Not Applicable", or "Unknown".
Returns XMLGregorianCalendar instance otherwise.

Brian Uri
November 19, 2014, 12:50 PM

From Jeff:

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();
}

Brian Uri
November 14, 2014, 10:38 AM

From Jeff:

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

Brian Uri
November 14, 2014, 12:25 AM

Note that TemporalCoverage also allows "Not Applicable" and "Unknown" as strings. The XMLGregorianCalendar accessor will still return null for those two strings.

Fixed

Assignee

Brian Uri

Reporter

Brian Uri

Labels

None

Fix versions

Priority

Medium