Date- and time-related DTOs

Several Gosu types related to date and time are based on XSD schemas. Examples include XSDDate and XSDDateTime. These XSD-based types can be used as web service DTOs. To represent a valid date or time, you must specify the relevant time zone in the web service call. Failure to specify a time zone results in an IllegalStateException.

The Gosu XSD-based types that require a time zone when used as a DTO are listed below.

  • XSDDate
  • XSDDateTime
  • XSDGDay
  • XSDGMonth
  • XSDGMonthDay
  • XSDGYear
  • XSDGYearMonth
  • XSDTime

The Gosu XSD-based types can be constructed from a java.lang.String object that conforms to the XML Schema date/time formats specified in the W3C XML Schema specification.

construct(s : String)

To convert an XSD-based type to a String, use the object's toString method.

An XSD-based date/time object can also be constructed from a java.util.Calendar object.

construct(cal : Calendar, useTimeZone : boolean)

If the constructor's useTimeZone argument is true, the constructed object inherits the time zone specified in the Calendar object.

Conversely, a Gosu XSD-based date/time object can be converted to a java.util.Calendar object by calling the object's toCalendar method. Calendar fields that are not included in the XSD-based object are set to default values. Two method signatures are supported.

toCalendar() : Calendar
toCalendar(tzDefault : TimeZone) : Calendar

If the Gosu object does not specify a time zone value, calling the toCalendar method signature with no arguments results in an IllegalStateException.