Search in sources :

Example 6 with LocalDateTime

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();
}
Also used : LocalDateTime(org.threeten.bp.LocalDateTime) ZonedDateTime(org.threeten.bp.ZonedDateTime) Instant(org.threeten.bp.Instant) LocalDate(org.threeten.bp.LocalDate)

Aggregations

LocalDateTime (org.threeten.bp.LocalDateTime)6 LocalDate (org.threeten.bp.LocalDate)2 ZonedDateTime (org.threeten.bp.ZonedDateTime)2 NonNull (androidx.annotation.NonNull)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 Location (com.waz.api.Location)1 Date (java.util.Date)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 Test (org.junit.Test)1 Instant (org.threeten.bp.Instant)1