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 SummaryNested Classes
- Field SummaryFields
- Constructor SummaryConstructorsConstructorDescriptionConstructs 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 SummaryModifier and TypeMethodDescription- static StringArrayPropCreates a new time zones array list property named- Atom.ZONES.- booleanChecks if two date objects are equal.- static GDateTimeHelper to constructs a date from an SQL Date instance as a LocalDate.- static GDateTimeHelper to constructs a date from a- Dateinstance 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 GDateTimeHelper to constructs a time from a Time instance as a LocalTime.- static GDateTimeHelper to constructs a time from a- Dateinstance as a LocalTime.- static GDateTimeHelper to constructs a date/time from a- Value, 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.TypeGets 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.- booleanReturns 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 StringReturns 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_DATEThe epoch date as a LocalDate, i.e. 1st of January 1970.
- MIDNIGHTThe time as midnight as a LocalTime, i.e. 00:00:00.
 
- Constructor Details- GDateTimeConstructs the date/time from a LocalTime.- Parameters:
- localTime- The local time.
- Throws:
- NullPointerException- If the parameter is null.
 
- GDateTimeConstructs the date/time from an OffsetTime.- Parameters:
- offsetTime- The OffsetTime.
- Throws:
- NullPointerException- If the parameter is null.
 
- GDateTimeConstructs the date/time from a LocalDate.- Parameters:
- localDate- The local date.
- Throws:
- NullPointerException- If the parameter is null.
 
- GDateTimeConstructs the date/time from a LocalDateTime.- Parameters:
- localDateTime- The local date and time.
- Throws:
- NullPointerException- If the parameter is null.
 
- GDateTimeConstructs the date/time from an OffsetDateTime.- Parameters:
- offsetDateTime- The OffsetDateTime.
- Throws:
- NullPointerException- If the parameter is null.
 
- GDateTimeConstructs the date/time from an OffsetDateTime.- Parameters:
- zonedDateTime- The ZonedDateTime.
- Throws:
- NullPointerException- If the parameter is null.
 
- GDateTimeConstructs the date/time from a ZoneId.- Parameters:
- zone- The ZoneId.
- Throws:
- NullPointerException- If the parameter is null.
 
 
- Method Details- createTimeZonesPropCreates a new time zones array list property named- Atom.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.
 
- getTypeGets the type from an Object. Only values of the classes- LocalTime,- OffsetTime,- LocalDate,- LocalDateTime,- OffsetDateTime,- ZonedDateTimeand- ZoneIdreturn non-null.- Returns:
- The Type that matches, or null for no match.
 
- nanoOfSecondGets the nanos of seconds of a time value.
- fromTimeHelper to constructs a time from a Time instance as a LocalTime.- Returns:
- The new GDateTime instance with a LocalTime type.
 
- fromTimeHelper to constructs a time from a- Dateinstance as a LocalTime.- Returns:
- The new GDateTime instance with a LocalTime type.
 
- fromDateHelper to constructs a date from an SQL Date instance as a LocalDate.- Returns:
- The new GDateTime instance with a LocalDate type.
 
- fromDateHelper to constructs a date from a- Dateinstance as a LocalDate.- Returns:
- The new GDateTime instance with a LocalDate type.
 
- fromDateTimeHelper to constructs a date/time from a timestamp as a LocalDateTime.- Returns:
- The new GDateTime instance with a LocalDateTime type.
 
- fromDateTimeHelper to constructs a date/time from a data and time as a LocalDateTime.- Returns:
- The new GDateTime instance with a LocalDateTime type.
 
- fromStringpublic 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.
 
- nowCreate 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.
 
- fromValueHelper to constructs a date/time from a- Value, if the Value is of the Value Types LocalTime, OffsetTime, LocalDate, LocalDateTime, OffsetDateTime or ZonedDateTime.- Note: - GDateTime.Type.ZoneIddoes not have a corresponding direct representation in- Value.- 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.
 
- hasDatepublic boolean hasDate()Returns if the value consists of a date component.- Returns:
- true for LocalDate, LocalDateTime and OffsetDateTime, false for LocalTime and OffsetTime.
 
- hasTimepublic boolean hasTime()Returns if the value consists of a time component.- Returns:
- true for LocalDateTime and OffsetDateTime, LocalTime or OffsetTime, false for LocalDate.
 
- hasTimeOffsetpublic boolean hasTimeOffset()Returns if the value has a time offset component.- Returns:
- true for OffsetTime and OffsetDateTime, false otherwise.
 
- equalsChecks if two date objects are equal.
- getTypeReturns the date/time type for this instance value.
- getValueGets 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.
 
- getStringGets the date/time as a String depending on the the instance type of, i.e.- "type,dateTimeValue.toString()".- Returns:
- the String as described above.
 
- getValueStringGets the date/time value as a String, i.e.- "dateTimeValue.toString()".- Returns:
- the String as described above.
 
- paramStringReturns 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.
 
- toStringReturns a string representation of this class instance and its values.
- getLocalTimeGets the value as a LocalTime.- Returns:
- The time as LocalTime if the type is LocalTime, otherwise null.
 
- getOffsetTimeGets the value as a OffsetTime.- Returns:
- The time as OffsetTime if the type is OffsetTime, otherwise null.
 
- getLocalDateGets the value as a LocalDate.- Returns:
- The date as LocalDate if the type is LocalDate, otherwise null.
 
- getLocalDateTimeGets the value as a LocalDateTime.- Returns:
- The date and time as LocalDateTime if the type is LocalDateTime, otherwise null.
 
- getOffsetDateTimeGets the value as a OffsetDateTime.- Returns:
- The date and time as OffsetDateTime if the type is OffsetDateTime, otherwise null.
 
- getZonedDateTimeGets the value as a ZonedDateTime.- Returns:
- The date and time as ZonedDateTime if the type is ZonedDateTime, otherwise null.
 
- getOffsetGets the time offset value.- Returns:
- The zone offset for OffsetTime, OffsetDateTime and ZonedDateTime, null otherwise.
 
- getZoneGets 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.
 
- getGivenZoneNameReturns 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.
 
- toDateValueGets 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.
 
- toTimeValueGets 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.
 
- toLocalTimeGets 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.
 
- toOffsetTimeGets 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
 
- toLocalDateGets 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.
 
- toLocalDateTimeGets 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.
 
- toOffsetDateTimeGets 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.
 
- toZonedDateTimeGets 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.
 
- toTypeConverts 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.