use of org.threeten.bp.Instant in project SeriesGuide by UweTrottmann.
the class TimeToolsTest method test_getShowReleaseDateTime_dstGap.
@Test
public void test_getShowReleaseDateTime_dstGap() {
// using begin of daylight saving time in Europe/Berlin on 2017-03-26
// clock moves forward at 2:00 by 1 hour
ZoneId zoneIdBerlin = ZoneId.of(EUROPE_BERLIN);
Instant instantDayOfDstStart = ZonedDateTime.of(LocalDateTime.of(2017, 3, 26, 1, 0), zoneIdBerlin).toInstant();
Clock fixedClock = Clock.fixed(instantDayOfDstStart, zoneIdBerlin);
// put show release exactly inside daylight saving gap (02:00-03:00)
ZonedDateTime dateTime = TimeTools.getShowReleaseDateTime(LocalTime.of(2, 30), DayOfWeek.SUNDAY.getValue(), zoneIdBerlin, GERMANY, "Some Network", fixedClock);
// time should be "fixed" by moving an hour forward
assertThat(dateTime.toLocalTime()).isEqualTo(LocalTime.of(3, 30));
}
use of org.threeten.bp.Instant 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