java.lang.Object
org.firebirdsql.jaybird.util.FbDatetimeConversion
Helpers and classes for Firebird/Jaybird datetime handling.
- Since:
- 6
- Author:
- Mark Rotteveel
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TemporalFieldField for Firebird time.static final TemporalUnitThe Firebird unit of time, i.e.static final longNumber of microseconds per Firebird unit of time (i.e.static final longNumber of nanoseconds per Firebird unit of time (i.e. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable StringformatSqlDate(@Nullable LocalDate localDate) Formats a local date as a SQL date value (yyyy-mm-dd).static @Nullable StringformatSqlTime(@Nullable LocalTime localTime) Formats a local time as a SQL time value (hh:mm:ss[.f...]).static @Nullable StringformatSqlTimestamp(@Nullable LocalDateTime localDateTime) Formats a local date time as a SQL timestamp value (yyyy-mm-dd hh:mm:ss[.f...]).static LocalTimefromFbTimeUnits(int timeUnits) Converts Firebird time units (a.k.a.static LocalDatefromModifiedJulianDate(int mjd) Converts a Modified Julian Date to the correspondingLocalDate.static @Nullable LocalDateTimeparseIsoOrSqlTimestamp(@Nullable String datetimeString) Parse a string as a ISO 8601 datetime (yyyy-mm-dd{T|t}hh:mm[:ss[.f...]] or as a SQL timestamp value (seeparseSqlTimestamp(String)).static @Nullable LocalDateparseSqlDate(@Nullable String dateString) Parse a string as a SQL date value (yyyy-[m]m-[d]d).static @Nullable LocalTimeparseSqlTime(@Nullable String timeString) Parse a string as a SQL time value (hh:mm[:ss[.f...]]).static @Nullable LocalDateTimeparseSqlTimestamp(@Nullable String datetimeString) Parse a string as a SQL timestamp value (yyyy-[m]m-[d]d hh:mm[:ss[.f...]]).static inttoFbTimeUnits(LocalTime localTime) Converts a local time to Firebird time units (a.k.a.static inttoModifiedJulianDate(LocalDate localDate) Converts a local date to a Modified Julian Date.static <R extends Temporal>
RupdateFbTimeUnits(R datetime, int timeUnits) Returns a copy ofdatetime, updated so its time is now set to the value corresponding to the Firebird time units (timeUnits).static <R extends Temporal>
RupdateModifiedJulianDate(R datetime, int mjd) Returns a copy ofdatetime, updated so its date is now set to the value corresponding to the Modified Julian Datemjd.
-
Field Details
-
FB_TIME_UNIT
The Firebird unit of time, i.e. 100 microseconds. -
FB_TIME_FIELD
Field for Firebird time. -
MICROS_PER_UNIT
public static final long MICROS_PER_UNITNumber of microseconds per Firebird unit of time (i.e. 100 microseconds).- See Also:
-
NANOS_PER_UNIT
public static final long NANOS_PER_UNITNumber of nanoseconds per Firebird unit of time (i.e. 100 microseconds, or 100,000 nanoseconds).- See Also:
-
-
Method Details
-
toModifiedJulianDate
Converts a local date to a Modified Julian Date.Firebird's
DATEtype uses Modified Julian Date to store dates. Current Firebird versions only support values in the range [0001-01-01, 9999-12-31] or [-678575, 2973483]; this method does not enforce this range. We leave that to the server to enforce, in case it changes in the future.- Parameters:
localDate- local date value- Returns:
- Modified Julian Date value
- Throws:
ArithmeticException- if the resulting Modified Julian Date is out of range of anint- See Also:
-
fromModifiedJulianDate
Converts a Modified Julian Date to the correspondingLocalDate.A Modified Julian Date is the number of days since 17 November 1858.
- Parameters:
mjd- Modified Julian Date value- Returns:
- local date corresponding to
mjd - See Also:
-
updateModifiedJulianDate
Returns a copy ofdatetime, updated so its date is now set to the value corresponding to the Modified Julian Datemjd.- Type Parameters:
R- type ofdatetime- Parameters:
datetime- datetime value to modifymjd- Modified Julian Date value- Returns:
- copy of the same type as
datetime, with the date changed to matchmjd - See Also:
-
toFbTimeUnits
Converts a local time to Firebird time units (a.k.a. fractions, or 100 microseconds).- Parameters:
localTime- local time value- Returns:
- number of 100 microseconds to represent
localTime - See Also:
-
fromFbTimeUnits
Converts Firebird time units (a.k.a. fractions, or 100 microseconds) to a local time.- Parameters:
timeUnits- number of 100 microseconds- Returns:
- local time
- See Also:
-
updateFbTimeUnits
Returns a copy ofdatetime, updated so its time is now set to the value corresponding to the Firebird time units (timeUnits).- Type Parameters:
R- type ofdatetime- Parameters:
datetime- datetime value to modifytimeUnits- number of 100 microseconds- Returns:
- copy of the same type as
datetime, with the time changed to matchtimeUnits - See Also:
-
parseIsoOrSqlTimestamp
Parse a string as a ISO 8601 datetime (yyyy-mm-dd{T|t}hh:mm[:ss[.f...]] or as a SQL timestamp value (seeparseSqlTimestamp(String)).- Parameters:
datetimeString- datetime value to parse- Returns:
- local date time value, or
nullifdatetimeStringisnull - Throws:
DateTimeParseException- ifdatetimeStringcannot be parsed- See Also:
-
parseSqlTimestamp
Parse a string as a SQL timestamp value (yyyy-[m]m-[d]d hh:mm[:ss[.f...]]).- Parameters:
datetimeString- datetime value to parse- Returns:
- local date time value, or
nullifdatetimeStringisnull - Throws:
DateTimeParseException- ifdatetimeStringcannot be parsed- See Also:
-
formatSqlTimestamp
Formats a local date time as a SQL timestamp value (yyyy-mm-dd hh:mm:ss[.f...]).- Parameters:
localDateTime- local date time- Returns:
- formatted string, or
nulliflocalDateTimeisnull
-
parseSqlTime
Parse a string as a SQL time value (hh:mm[:ss[.f...]]).Contrary to
Time, fractional seconds are supported.- Parameters:
timeString- time value to parse- Returns:
- local time value, or
nulliftimeStringisnull - Throws:
DateTimeParseException- iftimeStringcannot be parsed- See Also:
-
formatSqlTime
Formats a local time as a SQL time value (hh:mm:ss[.f...]).- Parameters:
localTime- local time- Returns:
- formatted string, or
nulliflocalTimeisnull
-
parseSqlDate
Parse a string as a SQL date value (yyyy-[m]m-[d]d).- Parameters:
dateString- date value to parse- Returns:
- local date value, or
nullifdateStringisnull - Throws:
DateTimeParseException- ifdateStringcannot be parsed- See Also:
-
formatSqlDate
Formats a local date as a SQL date value (yyyy-mm-dd).- Parameters:
localDate- local date- Returns:
- formatted string, or
nulliflocalDateisnull
-