Search in sources :

Example 1 with LocalTime

use of org.threeten.bp.LocalTime in project spring-data-commons by spring-projects.

the class ThreeTenBackPortConvertersUnitTests method convertsLocalTimeToDate.

// DATACMNS-606
@Test
public void convertsLocalTimeToDate() {
    LocalTime now = LocalTime.now();
    assertThat(format(CONVERSION_SERVICE.convert(now, Date.class), "HH:mm:ss.SSS")).isEqualTo(now.toString());
}
Also used : LocalTime(org.threeten.bp.LocalTime) Date(java.util.Date) LocalDate(org.threeten.bp.LocalDate) Test(org.junit.Test)

Example 2 with LocalTime

use of org.threeten.bp.LocalTime in project SeriesGuide by UweTrottmann.

the class TimeTools method getShowReleaseDateTime.

/**
 * Calculates the current release date time. Adjusts for time zone effects on release time, e.g.
 * delays between time zones (e.g. in the United States) and DST. Adjusts for user-defined
 * offset.
 *
 * @param releaseTime The {@link com.battlelancer.seriesguide.provider.SeriesGuideContract.Shows#RELEASE_TIME}.
 * @return The date is today or on the next day matching the given week day.
 */
public static Date getShowReleaseDateTime(@NonNull Context context, int releaseTime, int weekDay, @Nullable String timeZone, @Nullable String country, @Nullable String network) {
    // determine show time zone (falls back to America/New_York)
    ZoneId showTimeZone = getDateTimeZone(timeZone);
    LocalTime time = TimeTools.getShowReleaseTime(releaseTime);
    ZonedDateTime dateTime = getShowReleaseDateTime(time, weekDay, showTimeZone, country, network, Clock.system(showTimeZone));
    dateTime = applyUserOffset(context, dateTime);
    return new Date(dateTime.toInstant().toEpochMilli());
}
Also used : ZoneId(org.threeten.bp.ZoneId) LocalTime(org.threeten.bp.LocalTime) ZonedDateTime(org.threeten.bp.ZonedDateTime) Date(java.util.Date) LocalDate(org.threeten.bp.LocalDate)

Example 3 with LocalTime

use of org.threeten.bp.LocalTime in project SeriesGuide by UweTrottmann.

the class TimeToolsTest method test_applyUnitedStatesCorrections.

@Test
public void test_applyUnitedStatesCorrections() {
    // assume a US show releasing in Eastern time at 20:00
    LocalTime localTimeOf2000 = LocalTime.of(20, 0);
    ZoneId zoneIdUsEastern = ZoneId.of(TimeTools.TIMEZONE_ID_US_EASTERN);
    ZonedDateTime showDateTime = ZonedDateTime.of(LocalDate.of(2017, 1, 31), localTimeOf2000, zoneIdUsEastern);
    // Same local time as US Eastern
    applyAndAssertFor(showDateTime, localTimeOf2000, TimeTools.TIMEZONE_ID_US_EASTERN);
    applyAndAssertFor(showDateTime, localTimeOf2000, TimeTools.TIMEZONE_ID_US_EASTERN_DETROIT);
    applyAndAssertFor(showDateTime, localTimeOf2000, TimeTools.TIMEZONE_ID_US_PACIFIC);
    // One hour earlier local time than US Eastern
    LocalTime localTimeOf1900 = LocalTime.of(19, 0);
    applyAndAssertFor(showDateTime, localTimeOf1900, TimeTools.TIMEZONE_ID_US_CENTRAL);
    applyAndAssertFor(showDateTime, localTimeOf1900, TimeTools.TIMEZONE_ID_US_MOUNTAIN);
    // Same during winter...
    applyAndAssertFor(showDateTime, localTimeOf1900, TimeTools.TIMEZONE_ID_US_ARIZONA);
    // ...but observes no daylight saving
    LocalDate dateDuringDaylightSaving = LocalDate.of(2017, 5, 31);
    ZonedDateTime showTimeInDst = ZonedDateTime.of(dateDuringDaylightSaving, localTimeOf2000, zoneIdUsEastern);
    applyAndAssertFor(showTimeInDst, localTimeOf1900, TimeTools.TIMEZONE_ID_US_ARIZONA);
}
Also used : LocalTime(org.threeten.bp.LocalTime) ZoneId(org.threeten.bp.ZoneId) ZonedDateTime(org.threeten.bp.ZonedDateTime) LocalDate(org.threeten.bp.LocalDate) Test(org.junit.Test)

Example 4 with LocalTime

use of org.threeten.bp.LocalTime in project SeriesGuide by UweTrottmann.

the class TimeToolsTest method test_applyUnitedStatesCorrections_nonUs.

@Test
public void test_applyUnitedStatesCorrections_nonUs() {
    // assume a non-US show releasing at 20:00 local Berlin time (UTC+01:00)
    LocalTime localTimeOf2000 = LocalTime.of(20, 0);
    ZonedDateTime showDateTime = ZonedDateTime.of(LocalDate.of(2017, 1, 31), localTimeOf2000, ZoneId.of(EUROPE_BERLIN));
    // difference to US Central (UTC-06:00): -7 hours
    applyAndAssertFor(showDateTime, LocalTime.of(13, 0), TimeTools.TIMEZONE_ID_US_CENTRAL);
}
Also used : LocalTime(org.threeten.bp.LocalTime) ZonedDateTime(org.threeten.bp.ZonedDateTime) Test(org.junit.Test)

Aggregations

LocalTime (org.threeten.bp.LocalTime)4 Test (org.junit.Test)3 LocalDate (org.threeten.bp.LocalDate)3 ZonedDateTime (org.threeten.bp.ZonedDateTime)3 Date (java.util.Date)2 ZoneId (org.threeten.bp.ZoneId)2