Class PDTXMLConverter
- java.lang.Object
-
- com.helger.datetime.util.PDTXMLConverter
-
@Immutable public final class PDTXMLConverter extends Object
Utility class for XML date/time data type handling.- Author:
- Philip Helger
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static XMLGregorianCalendarcreateNewCalendar()static GregorianCalendargetCalendar(Date aDate)Get the passed date asGregorianCalendarusing the default time zone.static GregorianCalendargetCalendarDefaultTimeZone(long nMillis)Get the passed milliseconds asGregorianCalendar.static GregorianCalendargetCalendarUTC(long nMillis)Get the passed milliseconds asGregorianCalendar.static DatatypeFactorygetDatatypeFactory()static DategetDate(XMLGregorianCalendar aCal)Get the passedXMLGregorianCalendarasDate.static GregorianCalendargetGregorianCalendar(XMLGregorianCalendar aCal)Convert the passedXMLGregorianCalendarto aGregorianCalendar.static LocalDategetLocalDate(XMLGregorianCalendar aCal)Get the passedXMLGregorianCalendarasLocalDate.static LocalDateTimegetLocalDateTime(XMLGregorianCalendar aCal)Get the passedXMLGregorianCalendarasLocalDateTime.static LocalTimegetLocalTime(XMLGregorianCalendar aCal)Get the passedXMLGregorianCalendarasLocalTime.static longgetMillis(XMLGregorianCalendar aCal)Get the passedXMLGregorianCalendaras milliseconds.static intgetTimezoneOffsetInMinutes(int nOffsetInMillis)Convert milliseconds to minutes.static intgetTimezoneOffsetInMinutes(Calendar aCalendar)Get the time zone offset to UTC of the passed calendar in minutes to be used inXMLGregorianCalendar.static XMLGregorianCalendargetXMLCalendar(long nMillis)Get the passed milliseconds asXMLGregorianCalendar.static XMLGregorianCalendargetXMLCalendar(LocalDateTime aBase)Get the passed object asXMLGregorianCalendarwith date and time.static XMLGregorianCalendargetXMLCalendar(ZonedDateTime aBase)Get the passed object asXMLGregorianCalendarwith date and time.static XMLGregorianCalendargetXMLCalendar(Date aDate)Get the passedDateasXMLGregorianCalendar.static XMLGregorianCalendargetXMLCalendar(GregorianCalendar aCal)Get the passedGregorianCalendarasXMLGregorianCalendar.static XMLGregorianCalendargetXMLCalendar(XMLGregorianCalendar aDate, XMLGregorianCalendar aTime)Create a newXMLGregorianCalendarusing separate objects for date and time.static XMLGregorianCalendargetXMLCalendarDate(int nYear, int nMonth, int nDay)Create a Java representation of XML Schema builtin datatypedateorg*.static XMLGregorianCalendargetXMLCalendarDate(int nYear, int nMonth, int nDay, int nTimezone)Create a Java representation of XML Schema builtin datatypedateorg*.static XMLGregorianCalendargetXMLCalendarDate(LocalDate aBase)Get the passed object asXMLGregorianCalendardate (without a time).static XMLGregorianCalendargetXMLCalendarDate(LocalDate aBase, int nTimezoneOffsetInMinutes)Get the passed object asXMLGregorianCalendardate (without a time).static XMLGregorianCalendargetXMLCalendarDate(Date aBase)Get the passed object asXMLGregorianCalendardate (without a time).static XMLGregorianCalendargetXMLCalendarDate(GregorianCalendar aBase)Get the passed object asXMLGregorianCalendardate (without a time).static XMLGregorianCalendargetXMLCalendarDate(XMLGregorianCalendar aBase)Get the passed object asXMLGregorianCalendardate (without a time).static XMLGregorianCalendargetXMLCalendarDateNow()Get the current date asXMLGregorianCalendar.static XMLGregorianCalendargetXMLCalendarNow()Get the current date and time asXMLGregorianCalendarin the default time zone.static XMLGregorianCalendargetXMLCalendarNowUTC()Get the current date and time asXMLGregorianCalendarin UTC.static XMLGregorianCalendargetXMLCalendarTime(int nHour, int nMinute, int nSecond, int nMilliSecond)Create a Java representation of XML Schema builtin datatypedateorg*.static XMLGregorianCalendargetXMLCalendarTime(int nHour, int nMinute, int nSecond, int nMilliSecond, int nTimezone)Create a Java representation of XML Schema builtin datatypedateorg*.static XMLGregorianCalendargetXMLCalendarTime(LocalTime aBase)Get the passed object asXMLGregorianCalendartime (without a date).static XMLGregorianCalendargetXMLCalendarTime(Date aBase)Get the passed object asXMLGregorianCalendartime (without a date).static XMLGregorianCalendargetXMLCalendarTime(GregorianCalendar aBase)Get the passed object asXMLGregorianCalendartime (without a date).static XMLGregorianCalendargetXMLCalendarTime(XMLGregorianCalendar aBase)Get the passed object asXMLGregorianCalendartime (without a date).static XMLGregorianCalendargetXMLCalendarTimeNow()Get the current time asXMLGregorianCalendar.static XMLGregorianCalendargetXMLCalendarUTC(long nMillis)Get the passed milliseconds asXMLGregorianCalendar.static ZonedDateTimegetZonedDateTime(XMLGregorianCalendar aCal)Get the passedXMLGregorianCalendarasZonedDateTime.
-
-
-
Method Detail
-
getDatatypeFactory
@Nonnull public static DatatypeFactory getDatatypeFactory()
- Returns:
- The global
DatatypeFactoryused internally in this class.
-
getTimezoneOffsetInMinutes
public static int getTimezoneOffsetInMinutes(int nOffsetInMillis)
Convert milliseconds to minutes.- Parameters:
nOffsetInMillis- The offset in milliseconds to use. May not benull.- Returns:
- 0 for no offset to UTC, the minutes otherwise. Usually in 60minutes steps :)
-
getTimezoneOffsetInMinutes
public static int getTimezoneOffsetInMinutes(@Nonnull Calendar aCalendar)
Get the time zone offset to UTC of the passed calendar in minutes to be used inXMLGregorianCalendar.- Parameters:
aCalendar- The calendar to use. May not benull.- Returns:
- 0 for no offset to UTC, the minutes otherwise. Usually in 60minutes steps :)
-
getCalendar
@Nonnull public static GregorianCalendar getCalendar(@Nonnull Date aDate)
Get the passed date asGregorianCalendarusing the default time zone.- Parameters:
aDate- The source date. May benull.- Returns:
- Never
null.
-
getCalendarDefaultTimeZone
@Nonnull public static GregorianCalendar getCalendarDefaultTimeZone(long nMillis)
Get the passed milliseconds asGregorianCalendar.- Parameters:
nMillis- Milliseconds since 1.1.1970- Returns:
- Never
null. - Since:
- 9.1.8
-
getCalendarUTC
@Nonnull public static GregorianCalendar getCalendarUTC(long nMillis)
Get the passed milliseconds asGregorianCalendar.- Parameters:
nMillis- Milliseconds since 1.1.1970- Returns:
- Never
null. - Since:
- 9.1.8
-
createNewCalendar
@Nonnull public static XMLGregorianCalendar createNewCalendar()
- Returns:
- A new XML calendar instance, with all fields uninitialized. Never
null.
-
getXMLCalendarDateNow
@Nonnull public static XMLGregorianCalendar getXMLCalendarDateNow()
Get the current date asXMLGregorianCalendar.- Returns:
- Never
null.
-
getXMLCalendarDate
@Nullable public static XMLGregorianCalendar getXMLCalendarDate(@Nullable LocalDate aBase)
Get the passed object asXMLGregorianCalendardate (without a time).- Parameters:
aBase- The source object. May benull.- Returns:
nullif the parameter isnull.
-
getXMLCalendarDate
@Nullable public static XMLGregorianCalendar getXMLCalendarDate(@Nullable LocalDate aBase, int nTimezoneOffsetInMinutes)
Get the passed object asXMLGregorianCalendardate (without a time).- Parameters:
aBase- The source object. May benull.nTimezoneOffsetInMinutes- Timezone offset in minutes. UseDatatypeConstants.FIELD_UNDEFINEDif none is to be used.- Returns:
nullif the parameter isnull.- Since:
- 9.3.5
-
getXMLCalendarDate
@Nullable public static XMLGregorianCalendar getXMLCalendarDate(@Nullable Date aBase)
Get the passed object asXMLGregorianCalendardate (without a time).- Parameters:
aBase- The source object. May benull.- Returns:
nullif the parameter isnull.
-
getXMLCalendarDate
@Nullable public static XMLGregorianCalendar getXMLCalendarDate(@Nullable GregorianCalendar aBase)
Get the passed object asXMLGregorianCalendardate (without a time).- Parameters:
aBase- The source object. May benull.- Returns:
nullif the parameter isnull.
-
getXMLCalendarDate
@Nullable public static XMLGregorianCalendar getXMLCalendarDate(@Nullable XMLGregorianCalendar aBase)
Get the passed object asXMLGregorianCalendardate (without a time).- Parameters:
aBase- The source object. May benull.- Returns:
nullif the parameter isnull.
-
getXMLCalendarDate
@Nonnull public static XMLGregorianCalendar getXMLCalendarDate(int nYear, int nMonth, int nDay)
Create a Java representation of XML Schema builtin datatype
dateorg*.For example, an instance of
gYearcan be created invoking this factory withmonthanddayparameters set toDatatypeConstants.FIELD_UNDEFINED.A
DatatypeConstants.FIELD_UNDEFINEDvalue indicates that field is not set.- Parameters:
nYear- Year to be created.nMonth- Month to be created.nDay- Day to be created.- Returns:
XMLGregorianCalendarcreated from parameter values.- Throws:
IllegalArgumentException- If any individual parameter's value is outside the maximum value constraint for the field as determined by the Date/Time Data Mapping table inXMLGregorianCalendaror if the composite values constitute an invalidXMLGregorianCalendarinstance as determined byXMLGregorianCalendar.isValid().- See Also:
DatatypeConstants.FIELD_UNDEFINED
-
getXMLCalendarDate
@Nonnull public static XMLGregorianCalendar getXMLCalendarDate(int nYear, int nMonth, int nDay, int nTimezone)
Create a Java representation of XML Schema builtin datatype
dateorg*.For example, an instance of
gYearcan be created invoking this factory withmonthanddayparameters set toDatatypeConstants.FIELD_UNDEFINED.A
DatatypeConstants.FIELD_UNDEFINEDvalue indicates that field is not set.- Parameters:
nYear- Year to be created.nMonth- Month to be created.nDay- Day to be created.nTimezone- Offset in minutes.DatatypeConstants.FIELD_UNDEFINEDindicates optional field is not set.- Returns:
XMLGregorianCalendarcreated from parameter values.- Throws:
IllegalArgumentException- If any individual parameter's value is outside the maximum value constraint for the field as determined by the Date/Time Data Mapping table inXMLGregorianCalendaror if the composite values constitute an invalidXMLGregorianCalendarinstance as determined byXMLGregorianCalendar.isValid().- See Also:
DatatypeConstants.FIELD_UNDEFINED
-
getXMLCalendarTimeNow
@Nonnull public static XMLGregorianCalendar getXMLCalendarTimeNow()
Get the current time asXMLGregorianCalendar.- Returns:
- Never
null.
-
getXMLCalendarTime
@Nullable public static XMLGregorianCalendar getXMLCalendarTime(@Nullable LocalTime aBase)
Get the passed object asXMLGregorianCalendartime (without a date).- Parameters:
aBase- The source object. May benull.- Returns:
nullif the parameter isnull.
-
getXMLCalendarTime
@Nullable public static XMLGregorianCalendar getXMLCalendarTime(@Nullable Date aBase)
Get the passed object asXMLGregorianCalendartime (without a date).- Parameters:
aBase- The source object. May benull.- Returns:
nullif the parameter isnull.
-
getXMLCalendarTime
@Nullable public static XMLGregorianCalendar getXMLCalendarTime(@Nullable GregorianCalendar aBase)
Get the passed object asXMLGregorianCalendartime (without a date).- Parameters:
aBase- The source object. May benull.- Returns:
nullif the parameter isnull.
-
getXMLCalendarTime
@Nullable public static XMLGregorianCalendar getXMLCalendarTime(@Nullable XMLGregorianCalendar aBase)
Get the passed object asXMLGregorianCalendartime (without a date).- Parameters:
aBase- The source object. May benull.- Returns:
nullif the parameter isnull.
-
getXMLCalendarTime
@Nonnull public static XMLGregorianCalendar getXMLCalendarTime(int nHour, int nMinute, int nSecond, int nMilliSecond)
Create a Java representation of XML Schema builtin datatype
dateorg*.For example, an instance of
gYearcan be created invoking this factory withmonthanddayparameters set toDatatypeConstants.FIELD_UNDEFINED.A
DatatypeConstants.FIELD_UNDEFINEDvalue indicates that field is not set.- Parameters:
nHour- Hour to be created.nMinute- Minute to be created.nSecond- Second to be created.nMilliSecond- Milli second to be created.- Returns:
XMLGregorianCalendarcreated from parameter values.- Throws:
IllegalArgumentException- If any individual parameter's value is outside the maximum value constraint for the field as determined by the Date/Time Data Mapping table inXMLGregorianCalendaror if the composite values constitute an invalidXMLGregorianCalendarinstance as determined byXMLGregorianCalendar.isValid().- See Also:
DatatypeConstants.FIELD_UNDEFINED
-
getXMLCalendarTime
@Nonnull public static XMLGregorianCalendar getXMLCalendarTime(int nHour, int nMinute, int nSecond, int nMilliSecond, int nTimezone)
Create a Java representation of XML Schema builtin datatype
dateorg*.For example, an instance of
gYearcan be created invoking this factory withmonthanddayparameters set toDatatypeConstants.FIELD_UNDEFINED.A
DatatypeConstants.FIELD_UNDEFINEDvalue indicates that field is not set.- Parameters:
nHour- Hour to be created.nMinute- Minute to be created.nSecond- Second to be created.nMilliSecond- Milli second to be created.nTimezone- Offset in minutes.DatatypeConstants.FIELD_UNDEFINEDindicates optional field is not set.- Returns:
XMLGregorianCalendarcreated from parameter values.- Throws:
IllegalArgumentException- If any individual parameter's value is outside the maximum value constraint for the field as determined by the Date/Time Data Mapping table inXMLGregorianCalendaror if the composite values constitute an invalidXMLGregorianCalendarinstance as determined byXMLGregorianCalendar.isValid().- See Also:
DatatypeConstants.FIELD_UNDEFINED
-
getXMLCalendarNow
@Nonnull public static XMLGregorianCalendar getXMLCalendarNow()
Get the current date and time asXMLGregorianCalendarin the default time zone.- Returns:
- Never
null.
-
getXMLCalendarNowUTC
@Nonnull public static XMLGregorianCalendar getXMLCalendarNowUTC()
Get the current date and time asXMLGregorianCalendarin UTC.- Returns:
- Never
null.
-
getXMLCalendar
@Nullable public static XMLGregorianCalendar getXMLCalendar(@Nullable LocalDateTime aBase)
Get the passed object asXMLGregorianCalendarwith date and time.- Parameters:
aBase- The source object. May benull.- Returns:
nullif the parameter isnull.
-
getXMLCalendar
@Nullable public static XMLGregorianCalendar getXMLCalendar(@Nullable ZonedDateTime aBase)
Get the passed object asXMLGregorianCalendarwith date and time.- Parameters:
aBase- The source object. May benull.- Returns:
nullif the parameter isnull.
-
getXMLCalendar
@Nullable public static XMLGregorianCalendar getXMLCalendar(@Nullable GregorianCalendar aCal)
Get the passedGregorianCalendarasXMLGregorianCalendar.- Parameters:
aCal- Source calendar. May benull.- Returns:
nullif the passed calendar isnull.
-
getXMLCalendar
@Nullable public static XMLGregorianCalendar getXMLCalendar(@Nullable XMLGregorianCalendar aDate, @Nullable XMLGregorianCalendar aTime)
Create a newXMLGregorianCalendarusing separate objects for date and time.- Parameters:
aDate- Source date. May benull.aTime- Source time. May benull.- Returns:
nullif the passed date and time arenull.
-
getXMLCalendar
@Nonnull public static XMLGregorianCalendar getXMLCalendar(long nMillis)
Get the passed milliseconds asXMLGregorianCalendar.- Parameters:
nMillis- Milliseconds since 1.1.1970- Returns:
- Never
null.
-
getXMLCalendarUTC
@Nonnull public static XMLGregorianCalendar getXMLCalendarUTC(long nMillis)
Get the passed milliseconds asXMLGregorianCalendar.- Parameters:
nMillis- Milliseconds since 1.1.1970- Returns:
- Never
null. - Since:
- 9.1.8
-
getXMLCalendar
@Nullable public static XMLGregorianCalendar getXMLCalendar(@Nullable Date aDate)
Get the passedDateasXMLGregorianCalendar.- Parameters:
aDate- Source date. May benull.- Returns:
nullif the passed date isnull.
-
getGregorianCalendar
@Nullable public static GregorianCalendar getGregorianCalendar(@Nullable XMLGregorianCalendar aCal)
Convert the passedXMLGregorianCalendarto aGregorianCalendar.- Parameters:
aCal- Source calendar. May benull.- Returns:
nullif the parameter isnull.
-
getLocalDate
@Nullable public static LocalDate getLocalDate(@Nullable XMLGregorianCalendar aCal)
Get the passedXMLGregorianCalendarasLocalDate.- Parameters:
aCal- The sourceXMLGregorianCalendar. May benull.- Returns:
nullif the parameter isnull.
-
getLocalTime
@Nullable public static LocalTime getLocalTime(@Nullable XMLGregorianCalendar aCal)
Get the passedXMLGregorianCalendarasLocalTime.- Parameters:
aCal- The sourceXMLGregorianCalendar. May benull.- Returns:
nullif the parameter isnull.
-
getLocalDateTime
@Nullable public static LocalDateTime getLocalDateTime(@Nullable XMLGregorianCalendar aCal)
Get the passedXMLGregorianCalendarasLocalDateTime.- Parameters:
aCal- The sourceXMLGregorianCalendar. May benull.- Returns:
nullif the parameter isnull.
-
getZonedDateTime
@Nullable public static ZonedDateTime getZonedDateTime(@Nullable XMLGregorianCalendar aCal)
Get the passedXMLGregorianCalendarasZonedDateTime.- Parameters:
aCal- The sourceXMLGregorianCalendar. May benull.- Returns:
nullif the parameter isnull.
-
getDate
@Nullable public static Date getDate(@Nullable XMLGregorianCalendar aCal)
Get the passedXMLGregorianCalendarasDate.- Parameters:
aCal- The sourceXMLGregorianCalendar. May benull.- Returns:
nullif the parameter isnull.
-
getMillis
@CheckForSigned public static long getMillis(@Nullable XMLGregorianCalendar aCal)
Get the passedXMLGregorianCalendaras milliseconds.- Parameters:
aCal- The sourceXMLGregorianCalendar. May benull.- Returns:
if the parameter isCGlobal.ILLEGAL_ULONGnull.
-
-