Class GDateTime
- All Implemented Interfaces:
Cloneable
DateTimeProp
property. The class is immutable and the clone returns the same instance.Note: GDateTime.Type.ZoneId
does not have a corresponding direct representation in Value
.
For all conversions, the Locale Information is used to get the Zone ID or Zone Offset for any conversions that take place in the class. This information is retrieved either from the direct parameter of the method call, or by looking up this information from the current thread. If not found, the system default values are used.
Several conversions methods in this class do not always need the Locale Information for a particular conversion, but the parameter may be present anyway. Setting it to null
will cause it to look-up the value only when required.
- Author:
- Christopher Mindus
Nested Class Summary
Field Summary
Constructor Summary
ConstructorDescriptionConstructs the date/time from a LocalDate.GDateTime
(LocalDateTime localDateTime) Constructs the date/time from a LocalDateTime.Constructs the date/time from a LocalTime.GDateTime
(OffsetDateTime offsetDateTime) Constructs the date/time from an OffsetDateTime.GDateTime
(OffsetTime offsetTime) Constructs the date/time from an OffsetTime.GDateTime
(ZonedDateTime zonedDateTime) Constructs the date/time from an OffsetDateTime.Constructs the date/time from a ZoneId.Method Summary
Modifier and TypeMethodDescriptionstatic StringArrayProp
Creates a new time zones array list property namedAtom.ZONES
.boolean
Checks if two date objects are equal.static GDateTime
Helper to constructs a date from an SQL Date instance as a LocalDate.static GDateTime
Helper to constructs a date from aDate
instance as a LocalDate.static GDateTime
fromDateTime
(Timestamp timeStamp) Helper to constructs a date/time from a timestamp as a LocalDateTime.static GDateTime
fromDateTime
(Date dateTime) Helper to constructs a date/time from a data and time as a LocalDateTime.static GDateTime
fromString
(GDateTime.Type type, String string) Creates a new GDateTime value from a type and a String.static GDateTime
Helper to constructs a time from a Time instance as a LocalTime.static GDateTime
Helper to constructs a time from aDate
instance as a LocalTime.static GDateTime
Helper to constructs a date/time from aValue
, if the Value is of the Value Types LocalTime, OffsetTime, LocalDate, LocalDateTime, OffsetDateTime or ZonedDateTime.Returns the zone name that given to the Zone ID or Zone Offset.Gets the value as a LocalDate.Gets the value as a LocalDateTime.Gets the value as a LocalTime.Gets the time offset value.Gets the value as a OffsetDateTime.Gets the value as a OffsetTime.Gets the date/time as a String depending on the the instance type of, i.e.getType()
Returns the date/time type for this instance value.static GDateTime.Type
Gets the type from an Object.getValue()
Gets the value object.Gets the date/time value as a String, i.e.getZone()
Gets the time zone for the ZonedDateTime or ZoneId types, such as 'Europe/Paris'.Gets the value as a ZonedDateTime.boolean
hasDate()
Returns if the value consists of a date component.boolean
hasTime()
Returns if the value consists of a time component.boolean
Returns if the value has a time offset component.static int
nanoOfSecond
(Date timeOrDateTime) Gets the nanos of seconds of a time value.static GDateTime
now
(GDateTime.Type type, LocaleInfo localeInfo) Create a new GDateTime with the current date and/or time for a type.protected String
Returns the parameter string representing the state of this event.Gets the date/time value that would match a date value component.Gets the date as a LocalDate with potential forced conversion.Gets the date as a LocalDateTime with potential forced conversion.Gets the current value as a LocalTime with potential forced conversion.toOffsetDateTime
(LocaleInfo localeInfo) Gets the date as a OffsetDateTime with potential forced conversion.toOffsetTime
(LocaleInfo localeInfo) Gets the current value as a OffsetTime with potential forced conversion.toString()
Returns a string representation of this class instance and its values.Gets the date/time value that would match a time value component.toType
(GDateTime.Type type, LocaleInfo localeInfo) Converts a date/time value to another type.toZonedDateTime
(LocaleInfo localeInfo) Gets the date as a LocalDateTime with potential forced conversion, and will only work to convert an OffsetDateTime.
Field Details
EPOCH_DATE
The epoch date as a LocalDate, i.e. 1st of January 1970.MIDNIGHT
The time as midnight as a LocalTime, i.e. 00:00:00.
Constructor Details
GDateTime
Constructs the date/time from a LocalTime.- Parameters:
localTime
- The local time.- Throws:
NullPointerException
- If the parameter is null.
GDateTime
Constructs the date/time from an OffsetTime.- Parameters:
offsetTime
- The OffsetTime.- Throws:
NullPointerException
- If the parameter is null.
GDateTime
Constructs the date/time from a LocalDate.- Parameters:
localDate
- The local date.- Throws:
NullPointerException
- If the parameter is null.
GDateTime
Constructs the date/time from a LocalDateTime.- Parameters:
localDateTime
- The local date and time.- Throws:
NullPointerException
- If the parameter is null.
GDateTime
Constructs the date/time from an OffsetDateTime.- Parameters:
offsetDateTime
- The OffsetDateTime.- Throws:
NullPointerException
- If the parameter is null.
GDateTime
Constructs the date/time from an OffsetDateTime.- Parameters:
zonedDateTime
- The ZonedDateTime.- Throws:
NullPointerException
- If the parameter is null.
GDateTime
Constructs the date/time from a ZoneId.- Parameters:
zone
- The ZoneId.- Throws:
NullPointerException
- If the parameter is null.
Method Details
createTimeZonesProp
Creates a new time zones array list property namedAtom.ZONES
. The time zones are sorted using the default locale.- Returns:
- A new instance of the shared string array. The property is set to read-only.
getType
Gets the type from an Object. Only values of the classesLocalTime
,OffsetTime
,LocalDate
,LocalDateTime
,OffsetDateTime
,ZonedDateTime
andZoneId
return non-null.- Returns:
- The Type that matches, or null for no match.
nanoOfSecond
Gets the nanos of seconds of a time value.fromTime
Helper to constructs a time from a Time instance as a LocalTime.- Returns:
- The new GDateTime instance with a LocalTime type.
fromTime
Helper to constructs a time from aDate
instance as a LocalTime.- Returns:
- The new GDateTime instance with a LocalTime type.
fromDate
Helper to constructs a date from an SQL Date instance as a LocalDate.- Returns:
- The new GDateTime instance with a LocalDate type.
fromDate
Helper to constructs a date from aDate
instance as a LocalDate.- Returns:
- The new GDateTime instance with a LocalDate type.
fromDateTime
Helper to constructs a date/time from a timestamp as a LocalDateTime.- Returns:
- The new GDateTime instance with a LocalDateTime type.
fromDateTime
Helper to constructs a date/time from a data and time as a LocalDateTime.- Returns:
- The new GDateTime instance with a LocalDateTime type.
fromString
public static GDateTime fromString(GDateTime.Type type, String string) throws DateTimeParseException Creates a new GDateTime value from a type and a String.- Parameters:
type
- The type.string
- The String.- Returns:
- The new GDateTime instance.
- Throws:
DateTimeParseException
- If the string cannot be parsed.
now
Create a new GDateTime with the current date and/or time for a type. For ZoneId, the zone ID is retrieved from the locale information.- Parameters:
type
- The type.- Returns:
- The new GDateTime instance with the current date/time.
fromValue
Helper to constructs a date/time from aValue
, if the Value is of the Value Types LocalTime, OffsetTime, LocalDate, LocalDateTime, OffsetDateTime or ZonedDateTime.Note:
GDateTime.Type.ZoneId
does not have a corresponding direct representation inValue
.- Parameters:
value
- The Value-value, null or null Value is NOT allowed.- Returns:
- The new GDateTime instance with matching type, except ZoneId that does not have a corresponding Value type.
- Throws:
IllegalArgumentException
- If the value is not of correct type, i.e. one of the Value Types LocalTime, OffsetTime, LocalDate, LocalDateTime, OffsetDateTime or ZonedDateTime, or the value is null.
hasDate
public boolean hasDate()Returns if the value consists of a date component.- Returns:
- true for LocalDate, LocalDateTime and OffsetDateTime, false for LocalTime and OffsetTime.
hasTime
public boolean hasTime()Returns if the value consists of a time component.- Returns:
- true for LocalDateTime and OffsetDateTime, LocalTime or OffsetTime, false for LocalDate.
hasTimeOffset
public boolean hasTimeOffset()Returns if the value has a time offset component.- Returns:
- true for OffsetTime and OffsetDateTime, false otherwise.
equals
Checks if two date objects are equal.getType
Returns the date/time type for this instance value.getValue
Gets the value object.- Returns:
- The value object as an instance of
LocalTime
,OffsetTime
,LocalDate
,LocalDateTime
,OffsetDateTime
, orZonedDateTime
. If the type is ZoneId, null is returned.
getString
Gets the date/time as a String depending on the the instance type of, i.e."type,dateTimeValue.toString()"
.- Returns:
- the String as described above.
getValueString
Gets the date/time value as a String, i.e."dateTimeValue.toString()"
.- Returns:
- the String as described above.
paramString
Returns the parameter string representing the state of this event. This string is useful for debugging. Subclasses adds extra information to the string by preceding it with a comma followed by the extra information.- Returns:
- the parameter string of this event.
toString
Returns a string representation of this class instance and its values.getLocalTime
Gets the value as a LocalTime.- Returns:
- The time as LocalTime if the type is LocalTime, otherwise null.
getOffsetTime
Gets the value as a OffsetTime.- Returns:
- The time as OffsetTime if the type is OffsetTime, otherwise null.
getLocalDate
Gets the value as a LocalDate.- Returns:
- The date as LocalDate if the type is LocalDate, otherwise null.
getLocalDateTime
Gets the value as a LocalDateTime.- Returns:
- The date and time as LocalDateTime if the type is LocalDateTime, otherwise null.
getOffsetDateTime
Gets the value as a OffsetDateTime.- Returns:
- The date and time as OffsetDateTime if the type is OffsetDateTime, otherwise null.
getZonedDateTime
Gets the value as a ZonedDateTime.- Returns:
- The date and time as ZonedDateTime if the type is ZonedDateTime, otherwise null.
getOffset
Gets the time offset value.- Returns:
- The zone offset for OffsetTime, OffsetDateTime and ZonedDateTime, null otherwise.
getZone
Gets the time zone for the ZonedDateTime or ZoneId types, such as 'Europe/Paris'. It is also returned for OffsetTime and OffsetDateTime, but then it is a ZoneOffset (that is a subclass of ZoneId).This returns the zone ID. This identifies the time-zone rules that determine when and how the offset from UTC/Greenwich changes.
- Returns:
- The zone ID for OffsetTime, OffsetDateTime, ZonedDateTime and ZoneId, null otherwise.
getGivenZoneName
Returns the zone name that given to the Zone ID or Zone Offset. This name may be different from what has been passed from the remote part in case it failed the ZoneId parsing.- Returns:
- The zone name or ID for OffsetTime, OffsetDateTime, ZonedDateTime and ZoneId.
toDateValue
Gets the date/time value that would match a date value component.- Returns:
- A LocalDate type of value, i.e. this same instance for LocalDate, otherwise a new value for LocalDateTime, OffsetDateTime and ZonedDateTime with the type LocalDate.
- Throws:
IllegalStateException
- If the type is LocalTime, OffsetTime or ZoneId.
toTimeValue
Gets the date/time value that would match a time value component. The time value can include a zone offset component in case the type is OffsetTime or OffsetDateTime.- Returns:
- A LocalTime or OffsetTime type of value, i.e. this same instance for LocalTime, OffsetTime and ZonedDateTime, otherwise a new value for LocalDateTime and OffsetDateTime with the type LocalTime.
- Throws:
IllegalStateException
- If the type is LocalDate or ZoneId.
toLocalTime
Gets the current value as a LocalTime with potential forced conversion. The conversion does not lose any time information that LocalTime cannot store.- Returns:
- The time as LocalTime converted if required.
- Throws:
IllegalStateException
- In case the type is LocalDate or ZoneId.
toOffsetTime
Gets the current value as a OffsetTime with potential forced conversion. The conversion does not lose any time information that OffsetTime cannot store apart of the calculated zone offset from the current user session or the system default.- Parameters:
localeInfo
- The locale information to use, or null to use the current user's or system default. Only the conversion from LocalTime or LocalDateTime uses the locale information.- Returns:
- The time as OffsetTime converted if required.
- Throws:
IllegalStateException
- In case the type is LocalDate or ZoneId
toLocalDate
Gets the date as a LocalDate with potential forced conversion.- Returns:
- The date as LocalDate converted if required.
- Throws:
IllegalStateException
- In case the type is LocalTime, OffsetTime or ZoneId.
toLocalDateTime
Gets the date as a LocalDateTime with potential forced conversion.- Returns:
- The date as LocalDateTime converted if required.
- Throws:
IllegalStateException
- In case the type is a LocalTime, OffsetTime, LocalDate or ZoneId.
toOffsetDateTime
Gets the date as a OffsetDateTime with potential forced conversion.- Parameters:
localeInfo
- The locale information to use, or null to use the current user's or system default.- Returns:
- The date as OffsetDateTime converted if required.
- Throws:
IllegalStateException
- In case the type is a LocalTime, OffsetTime, LocalDate or ZoneId.
toZonedDateTime
Gets the date as a LocalDateTime with potential forced conversion, and will only work to convert an OffsetDateTime. All other conversions will fail with an exception.- Parameters:
localeInfo
- The locale information to use, or null to use the current user's or system default.- Returns:
- The date as ZonedDateTime converted if required.
- Throws:
IllegalStateException
- In case the type is a LocalTime, OffsetTime, LocalDate or ZoneId.
toType
Converts a date/time value to another type.- Parameters:
type
- The target type.localeInfo
- The locale information to use, or null to use the current user's or system default.- Returns:
- A GDateTime value with the requested type, or the same instance in case the type already is of the requested type.
- Throws:
IllegalStateException
- In case the type conversion is not possible.