Java Code Examples for java.time.Instant#atOffset()
The following examples show how to use
java.time.Instant#atOffset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKInstant.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 2
Source File: TCKInstant.java From j2objc with Apache License 2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 3
Source File: TCKInstant.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 4
Source File: TCKInstant.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 5
Source File: TCKInstant.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 6
Source File: TCKInstant.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 7
Source File: TCKInstant.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 8
Source File: TCKInstant.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 9
Source File: TCKInstant.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 10
Source File: TCKInstant.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 11
Source File: TCKInstant.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 12
Source File: TCKInstant.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 13
Source File: Utils.java From catnip with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Nonnull @CheckReturnValue public static OffsetDateTime creationTimeOf(final long id) { final long discordTimestamp = id >> 22; final Instant instant = Instant.ofEpochMilli(discordTimestamp + DISCORD_EPOCH); return instant.atOffset(ZoneOffset.UTC); }
Example 14
Source File: TCKInstant.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 15
Source File: TCKInstant.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test_atOffset() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); OffsetDateTime test = instant.atOffset(ZoneOffset.ofHours(1)); assertEquals(test.getYear(), 1970); assertEquals(test.getMonthValue(), 1); assertEquals(test.getDayOfMonth(), 1 + (i >= 23 * 60 * 60 ? 1 : 0)); assertEquals(test.getHour(), ((i / (60 * 60)) + 1) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); } }
Example 16
Source File: EventEmitterShould.java From docker-compose-rule with Apache License 2.0 | 4 votes |
private OffsetDateTime timeIs(int seconds) { Instant instant = Instant.ofEpochSecond(seconds); when(clock.instant()).thenReturn(instant); return instant.atOffset(ZoneOffset.UTC); }
Example 17
Source File: TimeSpec.java From java-timeseries with MIT License | 4 votes |
@Test public void whenToInstantThenCorrectInstantReturned() { Instant instant = Instant.ofEpochSecond(3000L); Time time = new Time(instant.atOffset(ZoneOffset.UTC)); assertThat(time.toInstant(), is(instant)); }
Example 18
Source File: Utils.java From ShedLock with Apache License 2.0 | 4 votes |
public static String toIsoString(@NonNull Instant instant) { OffsetDateTime utc = instant.atOffset(ZoneOffset.UTC); return formatter.format(utc); }
Example 19
Source File: CronHelper.java From cloudformation-cli-java-plugin with Apache License 2.0 | 3 votes |
/** * Schedule a re-invocation of the executing handler no less than 1 minute from * now * * * /** Creates a cron(..) expression for a single instance at Now+minutesFromNow * NOTE: CloudWatchEvents only support a 1minute granularity for re-invoke * Anything less should be handled inside the original handler request * * Expression is of form cron(minutes, hours, day-of-month, month, day-of-year, * year) where day-of-year is not necessary when the day-of-month and * month-of-year fields are supplied * * @param minutesFromNow The number of minutes from now for building the cron * expression * @return A cron expression for use with CloudWatchEvents putRule(..) API */ public String generateOneTimeCronExpression(final int minutesFromNow) { // Add additional 1 minute, since rule can be created after scheduled time, like // "13:40:59" -> cron(41 13 30) Instant instant = Instant.now(this.clock).plusSeconds(60L * (minutesFromNow + 1)); OffsetDateTime odt = instant.atOffset(ZoneOffset.UTC); return DateTimeFormatter.ofPattern("'cron('m H d M ? u')'").format(odt); }