Class DateTimeUtil
java.lang.Object
net.okapia.osid.torrefacto.util.DateTimeUtil
Quick conversions from an OSID
DateTime to the common Java
date and time classes. Only the
org.osid.calendaring.DateTime interface is used, so any
provider's implementation may be passed.
The Java classes are Gregorian and tied to a single clock, so only
a datetime on the Gregorian calendar in UTC time can be converted;
any other calendar or time system is rejected.
Components finer than the datetime's granularity are undefined and
are floored (an undefined month or day becomes 1, an undefined time
component becomes 0). If the granularity is coarser than a year the
year itself is undefined and the datetime cannot be converted. When
a value does not fit the target type, an
InvalidArgumentException is thrown rather than silently
wrapping or truncating the date. Sub-nanosecond precision, where
present, is dropped.-
Method Summary
Modifier and TypeMethodDescriptionstatic DateConverts an OSIDDateTimeto ajava.util.Date.static LocalDateTimetoLocalDateTime(DateTime datetime) Converts an OSIDDateTimeto aLocalDateTime.static OffsetDateTimetoOffsetDateTime(DateTime datetime) Converts an OSIDDateTimeto anOffsetDateTime.
-
Method Details
-
toLocalDateTime
Converts an OSIDDateTimeto aLocalDateTime. The value is read as a proleptic Gregorian date in UTC.- Parameters:
datetime- an OSID datetime- Returns:
- the equivalent local datetime
- Throws:
InvalidArgumentException-datetimeis not Gregorian/UTC, has no defined year, or is out of bounds for aLocalDateTimeNullArgumentException-datetimeisnull
-
toOffsetDateTime
Converts an OSIDDateTimeto anOffsetDateTime. The offset is always UTC, as a convertible datetime is in UTC.- Parameters:
datetime- an OSID datetime- Returns:
- the equivalent UTC offset datetime
- Throws:
InvalidArgumentException-datetimeis not Gregorian/UTC, has no defined year, or is out of bounds for anOffsetDateTimeNullArgumentException-datetimeisnull
-
toDate
Converts an OSIDDateTimeto ajava.util.Date. Sub-millisecond precision is dropped.- Parameters:
datetime- an OSID datetime- Returns:
- the equivalent date
- Throws:
InvalidArgumentException-datetimeis not Gregorian/UTC, has no defined year, or is out of bounds for aDateNullArgumentException-datetimeisnull
-