use of org.threeten.bp.LocalDateTime in project SeriesGuide by UweTrottmann.
the class TimeTools method parseEpisodeReleaseDate.
/**
* Calculates the episode release date time as a millisecond instant. Adjusts for time zone
* effects on release time, e.g. delays between time zones (e.g. in the United States) and DST.
*
* @param showTimeZone See {@link #getDateTimeZone(String)}.
* @param showReleaseTime See {@link #getShowReleaseTime(int)}.
* @return -1 if no conversion was possible. Otherwise, any other long value (may be negative!).
*/
public static long parseEpisodeReleaseDate(@NonNull ZoneId showTimeZone, @Nullable Date releaseDate, @NonNull LocalTime showReleaseTime, @Nullable String showCountry, @Nullable String showNetwork, @NonNull String deviceTimeZone) {
if (releaseDate == null) {
return Constants.EPISODE_UNKNOWN_RELEASE;
}
// Get local date: tmdb-java parses date string to Date using SimpleDateFormat,
// which uses the default time zone.
Instant instant = Instant.ofEpochMilli(releaseDate.getTime());
LocalDate localDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
// set time
LocalDateTime localDateTime = localDate.atTime(showReleaseTime);
localDateTime = handleHourPastMidnight(showCountry, showNetwork, localDateTime);
// get a valid datetime in the show time zone, this auto-forwards time if inside DST gap
ZonedDateTime dateTime = localDateTime.atZone(showTimeZone);
// handle time zone effects on release time for US shows (only if device is set to US zone)
if (deviceTimeZone.startsWith(TIMEZONE_ID_PREFIX_AMERICA)) {
dateTime = applyUnitedStatesCorrections(showCountry, deviceTimeZone, dateTime);
}
return dateTime.toInstant().toEpochMilli();
}
Aggregations