Search in sources :

Example 16 with Instant

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));
}
Also used : ZoneId(org.threeten.bp.ZoneId) ZonedDateTime(org.threeten.bp.ZonedDateTime) Instant(org.threeten.bp.Instant) Clock(org.threeten.bp.Clock) Test(org.junit.Test)

Example 17 with Instant

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

Aggregations

Instant (org.threeten.bp.Instant)17 SecurityCenterClient (com.google.cloud.securitycenter.v1.SecurityCenterClient)6 IOException (java.io.IOException)6 Test (org.junit.Test)5 Finding (com.google.cloud.securitycenter.v1.Finding)4 ZonedDateTime (org.threeten.bp.ZonedDateTime)4 Value (com.google.protobuf.Value)2 GroupFindingsRequest (com.google.cloud.securitycenter.v1.GroupFindingsRequest)1 GroupResult (com.google.cloud.securitycenter.v1.GroupResult)1 ListFindingsRequest (com.google.cloud.securitycenter.v1.ListFindingsRequest)1 ListFindingsResult (com.google.cloud.securitycenter.v1.ListFindingsResponse.ListFindingsResult)1 GroupFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.GroupFindingsPagedResponse)1 ListFindingsPagedResponse (com.google.cloud.securitycenter.v1.SecurityCenterClient.ListFindingsPagedResponse)1 UpdateFindingRequest (com.google.cloud.securitycenter.v1.UpdateFindingRequest)1 FieldMask (com.google.protobuf.FieldMask)1 ReceivedMessage (com.google.pubsub.v1.ReceivedMessage)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Clock (org.threeten.bp.Clock)1 DayOfWeek (org.threeten.bp.DayOfWeek)1