/** * Converts {@link INTERVALDS} to {@link Duration}. * * @param dbData the data from the database to be converted, possibly {@code null} * @return the converted value, possibly {@code null} */ public static Duration intervaldsToDuration(INTERVALDS dbData) { if (dbData == null) { return null; } byte[] bytes = dbData.toBytes(); int day = toUnsignedInt(bytes[0]) << 24 | toUnsignedInt(bytes[1]) << 16 | toUnsignedInt(bytes[2]) << 8 | toUnsignedInt(bytes[3]); day ^= HIGH_BIT_FLAG; int hour = toUnsignedInt(bytes[4]) - 60; int minute = toUnsignedInt(bytes[5]) - 60; int second = toUnsignedInt(bytes[6]) - 60; int nano = toUnsignedInt(bytes[7]) << 24 | toUnsignedInt(bytes[8]) << 16 | toUnsignedInt(bytes[9]) << 8 | toUnsignedInt(bytes[10]); nano ^= HIGH_BIT_FLAG; return Duration.ofDays(day) .plusHours(hour) .plusMinutes(minute) .plusSeconds(second) .plusNanos(nano); }
/** * Converts {@link INTERVALDS} to {@link Duration}. * * @param dbData the data from the database to be converted, possibly {@code null} * @return the converted value, possibly {@code null} */ public static Duration intervaldsToDuration(INTERVALDS dbData) { if (dbData == null) { return null; } byte[] bytes = dbData.toBytes(); int day = toUnsignedInt(bytes[0]) << 24 | toUnsignedInt(bytes[1]) << 16 | toUnsignedInt(bytes[2]) << 8 | toUnsignedInt(bytes[3]); day ^= HIGH_BIT_FLAG; int hour = toUnsignedInt(bytes[4]) - 60; int minute = toUnsignedInt(bytes[5]) - 60; int second = toUnsignedInt(bytes[6]) - 60; int nano = toUnsignedInt(bytes[7]) << 24 | toUnsignedInt(bytes[8]) << 16 | toUnsignedInt(bytes[9]) << 8 | toUnsignedInt(bytes[10]); nano ^= HIGH_BIT_FLAG; return Duration.ofDays(day) .plusHours(hour) .plusMinutes(minute) .plusSeconds(second) .plusNanos(nano); }