Java Code Examples for java.time.OffsetDateTime#get()

The following examples show how to use java.time.OffsetDateTime#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateTime.java    From cql_engine with Apache License 2.0 5 votes vote down vote up
@Override
public Integer compareToPrecision(BaseTemporal other, Precision thePrecision) {
    boolean leftMeetsPrecisionRequirements = this.precision.toDateTimeIndex() >= thePrecision.toDateTimeIndex();
    boolean rightMeetsPrecisionRequirements = other.precision.toDateTimeIndex() >= thePrecision.toDateTimeIndex();

    // adjust dates to evaluation offset
    OffsetDateTime leftDateTime = this.getDateTimeWithEvaluationOffset();
    OffsetDateTime rightDateTime = ((DateTime) other).getDateTimeWithEvaluationOffset();

    if (!leftMeetsPrecisionRequirements || !rightMeetsPrecisionRequirements) {
        thePrecision = Precision.getLowestDateTimePrecision(this.precision, other.precision);
    }

    for (int i = 0; i < thePrecision.toDateTimeIndex() + 1; ++i) {
        int leftComp = leftDateTime.get(Precision.getDateTimeChronoFieldFromIndex(i));
        int rightComp = rightDateTime.get(Precision.getDateTimeChronoFieldFromIndex(i));
        if (leftComp > rightComp) {
            return 1;
        }
        else if (leftComp < rightComp) {
            return -1;
        }
    }

    if (leftMeetsPrecisionRequirements && rightMeetsPrecisionRequirements) {
        return 0;
    }

    return null;
}
 
Example 2
Source File: OffsetDateTimeTypeHandler.java    From mybatis-types with MIT License 5 votes vote down vote up
@Override
public void setNonNullParameter(PreparedStatement ps, int i, OffsetDateTime parameter, JdbcType jdbcType) throws SQLException {
    // Postgres do not work with offsets > than 15 hours, maybe other DBs too
    int offset = parameter.get(ChronoField.OFFSET_SECONDS);
    if (Math.abs(offset) > 54000) {
        parameter = parameter.withOffsetSameInstant(ZoneOffset.ofHours(offset > 0 ? 15 : -15));
    }

    ps.setTimestamp(
        i,
        Timestamp.from(parameter.toInstant()),
        GregorianCalendar.from(parameter.toZonedDateTime())
    );
}