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 TemporalField
Field for Firebird time.static final TemporalUnit
The Firebird unit of time, i.e.static final long
Number of microseconds per Firebird unit of time (i.e.static final long
Number of nanoseconds per Firebird unit of time (i.e. -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable String
formatSqlDate
(@Nullable LocalDate localDate) Formats a local date as a SQL date value (yyyy-mm-dd
).static @Nullable String
formatSqlTime
(@Nullable LocalTime localTime) Formats a local time as a SQL time value (hh:mm:ss[.f...]
).static @Nullable String
formatSqlTimestamp
(@Nullable LocalDateTime localDateTime) Formats a local date time as a SQL timestamp value (yyyy-mm-dd hh:mm:ss[.f...]
).static LocalTime
fromFbTimeUnits
(int timeUnits) Converts Firebird time units (a.k.a.static LocalDate
fromModifiedJulianDate
(int mjd) Converts a Modified Julian Date to the correspondingLocalDate
.static @Nullable LocalDateTime
parseIsoOrSqlTimestamp
(@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 LocalDate
parseSqlDate
(@Nullable String dateString) Parse a string as a SQL date value (yyyy-[m]m-[d]d
).static @Nullable LocalTime
parseSqlTime
(@Nullable String timeString) Parse a string as a SQL time value (hh:mm[:ss[.f...]]
).static @Nullable LocalDateTime
parseSqlTimestamp
(@Nullable String datetimeString) Parse a string as a SQL timestamp value (yyyy-[m]m-[d]d hh:mm[:ss[.f...]]
).static int
toFbTimeUnits
(LocalTime localTime) Converts a local time to Firebird time units (a.k.a.static int
toModifiedJulianDate
(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
DATE
type 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
null
ifdatetimeString
isnull
- Throws:
DateTimeParseException
- ifdatetimeString
cannot 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
null
ifdatetimeString
isnull
- Throws:
DateTimeParseException
- ifdatetimeString
cannot 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
null
iflocalDateTime
isnull
-
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
null
iftimeString
isnull
- Throws:
DateTimeParseException
- iftimeString
cannot 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
null
iflocalTime
isnull
-
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
null
ifdateString
isnull
- Throws:
DateTimeParseException
- ifdateString
cannot 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
null
iflocalDate
isnull
-