java.time.ZoneOffset Java Examples
The following examples show how to use
java.time.ZoneOffset.
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: TestZoneId.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public void test_NewYork_getOffsetInfo_gap() { ZoneId test = ZoneId.of("America/New_York"); final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 9, 2, 0, 0, 0); ZoneOffsetTransition trans = checkOffset(test.getRules(), dateTime, ZoneOffset.ofHours(-5), GAP); assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-5)); assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-4)); assertEquals(trans.getInstant(), createInstant(2008, 3, 9, 2, 0, 0, 0, ZoneOffset.ofHours(-5))); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-6)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), false); assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-3)), false); assertEquals(trans.toString(), "Transition[Gap at 2008-03-09T02:00-05:00 to -04:00]"); assertFalse(trans.equals(null)); assertFalse(trans.equals(ZoneOffset.ofHours(-5))); assertTrue(trans.equals(trans)); final ZoneOffsetTransition otherTrans = test.getRules().getTransition(dateTime); assertTrue(trans.equals(otherTrans)); assertEquals(trans.hashCode(), otherTrans.hashCode()); }
Example #2
Source File: ITDashboardsApi.java From influxdb-client-java with MIT License | 6 votes |
@Test void createDashboard() { OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC); Dashboard dashboard = dashboardsApi.createDashboard(generateName("dashboard"), "coolest dashboard", organization.getId()); Assertions.assertThat(dashboard).isNotNull(); Assertions.assertThat(dashboard.getId()).isNotEmpty(); Assertions.assertThat(dashboard.getOrgID()).isEqualTo(organization.getId()); Assertions.assertThat(dashboard.getCells()).hasSize(0); Assertions.assertThat(dashboard.getMeta()).isNotNull(); Assertions.assertThat(dashboard.getMeta().getCreatedAt()).isAfter(now); Assertions.assertThat(dashboard.getMeta().getUpdatedAt()).isAfter(now); Assertions.assertThat(dashboard.getLabels()).hasSize(0); Assertions.assertThat(dashboard.getLinks()).isNotNull(); Assertions.assertThat(dashboard.getLinks().getSelf()).isEqualTo("/api/v2/dashboards/" + dashboard.getId()); Assertions.assertThat(dashboard.getLinks().getMembers()).isEqualTo("/api/v2/dashboards/" + dashboard.getId() + "/members"); Assertions.assertThat(dashboard.getLinks().getOwners()).isEqualTo("/api/v2/dashboards/" + dashboard.getId() + "/owners"); Assertions.assertThat(dashboard.getLinks().getCells()).isEqualTo("/api/v2/dashboards/" + dashboard.getId() + "/cells"); Assertions.assertThat(dashboard.getLinks().getLabels()).isEqualTo("/api/v2/dashboards/" + dashboard.getId() + "/labels"); Assertions.assertThat(dashboard.getLinks().getOrg()).isEqualTo("/api/v2/orgs/" + organization.getId()); }
Example #3
Source File: DTOProjectionImportTest.java From hibernate-types with Apache License 2.0 | 6 votes |
@Override public void afterInit() { doInJPA(entityManager -> { Post post = new Post(); post.setId(1L); post.setTitle("High-Performance Java Persistence"); post.setCreatedBy("Vlad Mihalcea"); post.setCreatedOn(Timestamp.from( LocalDateTime.of(2020, 11, 2, 12, 0, 0).toInstant(ZoneOffset.UTC) )); post.setUpdatedBy("Vlad Mihalcea"); post.setUpdatedOn(Timestamp.from( LocalDateTime.now().toInstant(ZoneOffset.UTC) )); entityManager.persist(post); }); }
Example #4
Source File: TCKSignStyle.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "signStyle") public void test_signStyle(LocalDate localDate, SignStyle style, Class<?> expectedEx, String expectedStr) { DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); DateTimeFormatter formatter = builder.appendValue(ChronoField.YEAR, 2, 4, style) .toFormatter(); formatter = formatter.withZone(ZoneOffset.UTC); if (expectedEx == null) { String output = formatter.format(localDate); assertEquals(output, expectedStr); } else { try { formatter.format(localDate); fail(); } catch (Exception ex) { assertTrue(expectedEx.isInstance(ex)); } } }
Example #5
Source File: EncodeGorillaTest.java From gorilla-tsc with Apache License 2.0 | 6 votes |
@Test void simpleEncodeAndDecodeTest() throws Exception { long now = LocalDateTime.now().truncatedTo(ChronoUnit.HOURS) .toInstant(ZoneOffset.UTC).toEpochMilli(); Pair[] pairs = { new Pair(now + 10, Double.doubleToRawLongBits(1.0)), new Pair(now + 20, Double.doubleToRawLongBits(-2.0)), new Pair(now + 28, Double.doubleToRawLongBits(-2.5)), new Pair(now + 84, Double.doubleToRawLongBits(65537)), new Pair(now + 400, Double.doubleToRawLongBits(2147483650.0)), new Pair(now + 2300, Double.doubleToRawLongBits(-16384)), new Pair(now + 16384, Double.doubleToRawLongBits(2.8)), new Pair(now + 16500, Double.doubleToRawLongBits(-38.0)) }; comparePairsToCompression(now, pairs); }
Example #6
Source File: TCKZoneRules.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void test_Apia_jumpForwardOverInternationalDateLine_P12_to_M12() { // transition occurred at 1892-07-04T00:00+12:33:04 ZoneRules test = pacificApia(); Instant instantBefore = LocalDate.of(1892, 7, 2).atStartOfDay(ZoneOffset.UTC).toInstant(); ZoneOffsetTransition trans = test.nextTransition(instantBefore); assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(1892, 7, 5, 0, 0)); assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(1892, 7, 4, 0, 0)); assertEquals(trans.isGap(), false); assertEquals(trans.isOverlap(), true); assertEquals(trans.isValidOffset(ZoneOffset.ofHoursMinutesSeconds(+12, 33, 4)), true); assertEquals(trans.isValidOffset(ZoneOffset.ofHoursMinutesSeconds(-11, -26, -56)), true); assertEquals(trans.getDuration(), Duration.ofHours(-24)); assertEquals(trans.getInstant(), LocalDateTime.of(1892, 7, 4, 0, 0).toInstant(ZoneOffset.ofHoursMinutesSeconds(-11, -26, -56))); ZonedDateTime zdt = ZonedDateTime.of(1892, 7, 4, 23, 0, 0, 0, ZoneId.of("Pacific/Apia")); assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(1892, 7, 4, 1, 0, 0)); }
Example #7
Source File: TCKOffsetDateTime.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="sampleTimes") public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneOffset offset) { LocalDate localDate = LocalDate.of(y, o, d); LocalTime localTime = LocalTime.of(h, m, s, n); LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime); OffsetDateTime a = OffsetDateTime.of(localDateTime, offset); assertEquals(a.getYear(), localDate.getYear()); assertEquals(a.getMonth(), localDate.getMonth()); assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth()); assertEquals(a.getDayOfYear(), localDate.getDayOfYear()); assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek()); assertEquals(a.getHour(), localDateTime.getHour()); assertEquals(a.getMinute(), localDateTime.getMinute()); assertEquals(a.getSecond(), localDateTime.getSecond()); assertEquals(a.getNano(), localDateTime.getNano()); assertEquals(a.toOffsetTime(), OffsetTime.of(localTime, offset)); assertEquals(a.toString(), localDateTime.toString() + offset.toString()); }
Example #8
Source File: TCKMinguoChronology.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test public void test_dateNow(){ assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now()) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(ZoneId.systemDefault())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(Clock.systemDefaultZone())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoDate.now(Clock.systemDefaultZone().getZone())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(), MinguoChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ; ZoneId zoneId = ZoneId.of("Europe/Paris"); assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoChronology.INSTANCE.dateNow(Clock.system(zoneId))) ; assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoDate.now(Clock.system(zoneId))) ; assertEquals(MinguoChronology.INSTANCE.dateNow(zoneId), MinguoDate.now(Clock.system(zoneId).getZone())) ; assertEquals(MinguoChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), MinguoChronology.INSTANCE.dateNow(Clock.systemUTC())) ; }
Example #9
Source File: RepositoryIT.java From sdn-rx with Apache License 2.0 | 6 votes |
@Override void setupData(Transaction transaction) { ZonedDateTime createdAt = LocalDateTime.of(2019, 1, 1, 23, 23, 42, 0).atZone(ZoneOffset.UTC.normalized()); id1 = transaction.run("" + "CREATE (n:PersonWithAllConstructor) " + " SET n.name = $name, n.sameValue = $sameValue, n.first_name = $firstName, n.cool = $cool, n.personNumber = $personNumber, n.bornOn = $bornOn, n.nullable = 'something', n.things = ['a', 'b'], n.place = $place, n.createdAt = $createdAt " + "RETURN id(n)", Values.parameters("name", TEST_PERSON1_NAME, "sameValue", TEST_PERSON_SAMEVALUE, "firstName", TEST_PERSON1_FIRST_NAME, "cool", true, "personNumber", 1, "bornOn", TEST_PERSON1_BORN_ON, "place", NEO4J_HQ, "createdAt", createdAt) ).next().get(0).asLong(); transaction .run("CREATE (a:Thing {theId: 'anId', name: 'Homer'})-[:Has]->(b:Thing2{theId: 4711, name: 'Bart'})"); IntStream.rangeClosed(1, 20).forEach(i -> transaction.run("CREATE (a:Thing {theId: 'id' + $i, name: 'name' + $i})", Values.parameters("i", String.format("%02d", i)))); person1 = new PersonWithAllConstructor(id1, TEST_PERSON1_NAME, TEST_PERSON1_FIRST_NAME, TEST_PERSON_SAMEVALUE, true, 1L, TEST_PERSON1_BORN_ON, "something", Arrays.asList("a", "b"), NEO4J_HQ, createdAt.toInstant()); }
Example #10
Source File: ZoneOffsetTransitionRule.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Reads the state from the stream. * * @param in the input stream, not null * @return the created object, not null * @throws IOException if an error occurs */ static ZoneOffsetTransitionRule readExternal(DataInput in) throws IOException { int data = in.readInt(); Month month = Month.of(data >>> 28); int dom = ((data & (63 << 22)) >>> 22) - 32; int dowByte = (data & (7 << 19)) >>> 19; DayOfWeek dow = dowByte == 0 ? null : DayOfWeek.of(dowByte); int timeByte = (data & (31 << 14)) >>> 14; TimeDefinition defn = TimeDefinition.values()[(data & (3 << 12)) >>> 12]; int stdByte = (data & (255 << 4)) >>> 4; int beforeByte = (data & (3 << 2)) >>> 2; int afterByte = (data & 3); LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0)); ZoneOffset std = (stdByte == 255 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds((stdByte - 128) * 900)); ZoneOffset before = (beforeByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + beforeByte * 1800)); ZoneOffset after = (afterByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + afterByte * 1800)); return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after); }
Example #11
Source File: TCKZoneRules.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public void test_London_getOffsetInfo_gap() { ZoneRules test = europeLondon(); final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 30, 1, 0, 0, 0); ZoneOffsetTransition trans = checkOffset(test, dateTime, OFFSET_ZERO, GAP); assertEquals(trans.isGap(), true); assertEquals(trans.isOverlap(), false); assertEquals(trans.getOffsetBefore(), OFFSET_ZERO); assertEquals(trans.getOffsetAfter(), OFFSET_PONE); assertEquals(trans.getInstant(), createInstant(2008, 3, 30, 1, 0, ZoneOffset.UTC)); assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2008, 3, 30, 1, 0)); assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2008, 3, 30, 2, 0)); assertEquals(trans.isValidOffset(OFFSET_ZERO), false); assertEquals(trans.isValidOffset(OFFSET_PONE), false); assertEquals(trans.isValidOffset(OFFSET_PTWO), false); assertEquals(trans.toString(), "Transition[Gap at 2008-03-30T01:00Z to +01:00]"); assertFalse(trans.equals(null)); assertFalse(trans.equals(OFFSET_ZERO)); assertTrue(trans.equals(trans)); final ZoneOffsetTransition otherTrans = test.getTransition(dateTime); assertTrue(trans.equals(otherTrans)); assertEquals(trans.hashCode(), otherTrans.hashCode()); }
Example #12
Source File: DvDateTime.java From archie with Apache License 2.0 | 5 votes |
public void setMagnitude(Long magnitude) { if(magnitude == null) { value = null; } else { value = LocalDateTime.ofEpochSecond(magnitude, 0, ZoneOffset.UTC); } }
Example #13
Source File: TCKChronoLocalDate.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="calendars") public void test_from_TemporalAccessor(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoLocalDate date = chrono.date(refDate); ChronoLocalDate test1 = ChronoLocalDate.from(date); assertEquals(test1, date); ChronoLocalDate test2 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30))); assertEquals(test2, date); ChronoLocalDate test3 = ChronoLocalDate.from(date.atTime(LocalTime.of(12, 30)).atZone(ZoneOffset.UTC)); assertEquals(test3, date); }
Example #14
Source File: ChronoZonedDateTimeImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
/** * Obtains an instance from a local date-time using the preferred offset if possible. * * @param localDateTime the local date-time, not null * @param zone the zone identifier, not null * @param preferredOffset the zone offset, null if no preference * @return the zoned date-time, not null */ static <R extends ChronoLocalDate> ChronoZonedDateTime<R> ofBest( ChronoLocalDateTimeImpl<R> localDateTime, ZoneId zone, ZoneOffset preferredOffset) { Objects.requireNonNull(localDateTime, "localDateTime"); Objects.requireNonNull(zone, "zone"); if (zone instanceof ZoneOffset) { return new ChronoZonedDateTimeImpl<>(localDateTime, (ZoneOffset) zone, zone); } ZoneRules rules = zone.getRules(); LocalDateTime isoLDT = LocalDateTime.from(localDateTime); List<ZoneOffset> validOffsets = rules.getValidOffsets(isoLDT); ZoneOffset offset; if (validOffsets.size() == 1) { offset = validOffsets.get(0); } else if (validOffsets.size() == 0) { ZoneOffsetTransition trans = rules.getTransition(isoLDT); localDateTime = localDateTime.plusSeconds(trans.getDuration().getSeconds()); offset = trans.getOffsetAfter(); } else { if (preferredOffset != null && validOffsets.contains(preferredOffset)) { offset = preferredOffset; } else { offset = validOffsets.get(0); } } Objects.requireNonNull(offset, "offset"); // protect against bad ZoneRules return new ChronoZonedDateTimeImpl<>(localDateTime, offset, zone); }
Example #15
Source File: TCKZoneOffset.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="query") Object[][] data_query() { return new Object[][] { {ZoneOffset.UTC, TemporalQueries.chronology(), null}, {ZoneOffset.UTC, TemporalQueries.zoneId(), null}, {ZoneOffset.UTC, TemporalQueries.precision(), null}, {ZoneOffset.UTC, TemporalQueries.zone(), ZoneOffset.UTC}, {ZoneOffset.UTC, TemporalQueries.offset(), ZoneOffset.UTC}, {ZoneOffset.UTC, TemporalQueries.localDate(), null}, {ZoneOffset.UTC, TemporalQueries.localTime(), null}, }; }
Example #16
Source File: KucoinRestClientTest.java From kucoin-java-sdk with MIT License | 5 votes |
@BeforeClass public static void setUpClass() { sandboxKucoinRestClient = new KucoinClientBuilder().withBaseUrl("https://openapi-sandbox.kucoin.com") .withApiKey("5c42a37bef83c73aa68e43c4", "7df80b16-1b95-4739-9b03-3d987599c332", "asd123456") .buildRestClient(); liveKucoinRestClient = new KucoinClientBuilder().withBaseUrl("https://openapi-v2.kucoin.com") .buildRestClient(); startAt = LocalDateTime.of(2019, 1, 1, 0, 0, 0).toEpochSecond(ZoneOffset.of("+8")); endAt = LocalDateTime.of(2019, 1, 21, 0, 0, 0).toEpochSecond(ZoneOffset.of("+8")); }
Example #17
Source File: TestOffsetDateTime_instants.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_ofInstant_tooBig() { long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7); long year = Year.MAX_VALUE + 1L; long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970; Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L); OffsetDateTime.ofInstant(instant, ZoneOffset.UTC); }
Example #18
Source File: TupleCodecProviderTest.java From immutables with Apache License 2.0 | 5 votes |
@Test void localDate() { LocalDateHolderCriteria criteria = LocalDateHolderCriteria.localDateHolder; Query query = Query.of(TypeHolder.LocalDateHolder.class) .addProjections(Matchers.toExpression(criteria.value), Matchers.toExpression(criteria.nullable), Matchers.toExpression(criteria.optional)); Path idPath = Visitors.toPath(KeyExtractor.defaultFactory().create(TypeHolder.LocalDateHolder.class).metadata().keys().get(0)); TupleCodecProvider provider = new TupleCodecProvider(query, new MongoPathNaming(idPath, PathNaming.defaultNaming()).toExpression()); Codec<ProjectedTuple> codec = provider.get(ProjectedTuple.class, registry); LocalDate now = LocalDate.now(); final long millisEpoch = now.atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli(); BsonDocument doc = new BsonDocument() .append("id", new BsonString("id1")) .append("value", new BsonDateTime(millisEpoch)) .append("nullable", BsonNull.VALUE) .append("optional", BsonNull.VALUE) .append("array", new BsonArray()) .append("list", new BsonArray()); ProjectedTuple tuple = codec.decode(new BsonDocumentReader(doc), DecoderContext.builder().build()); check(tuple.get(Matchers.toExpression(criteria.value))).is(now); check(tuple.get(Matchers.toExpression(criteria.nullable))).isNull(); check(tuple.get(Matchers.toExpression(criteria.optional))).is(Optional.empty()); }
Example #19
Source File: TestZoneOffsetParser.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="offsets") public void test_parse_exactMatch(String pattern, String parse, ZoneOffset expected) throws Exception { ParsePosition pos = new ParsePosition(0); TemporalAccessor parsed = getFormatter(pattern, "Z").parseUnresolved(parse, pos); assertEquals(pos.getIndex(), parse.length()); assertParsed(parsed, expected); }
Example #20
Source File: TCKZonedDateTime.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test public void test_withZoneSameLocal_retainOffset1() { LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0); // overlap ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-04:00") ); ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York")); assertEquals(base.getOffset(), ZoneOffset.ofHours(-4)); assertEquals(test.getOffset(), ZoneOffset.ofHours(-4)); }
Example #21
Source File: TestZoneOffsetParser.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="offsets") public void test_parse_exactMatch_EmptyUTC(String pattern, String parse, ZoneOffset expected) throws Exception { ParsePosition pos = new ParsePosition(0); TemporalAccessor parsed = getFormatter(pattern, "").parseUnresolved(parse, pos); assertEquals(pos.getIndex(), parse.length()); assertParsed(parsed, expected); }
Example #22
Source File: TCKDateTimeFormatterBuilder.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="offsetPatterns") public void test_appendOffset_format(String pattern, int h, int m, int s, String expected) throws Exception { builder.appendOffset(pattern, "Z"); DateTimeFormatter f = builder.toFormatter(); ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(h, m, s); assertEquals(f.format(offset), expected); }
Example #23
Source File: TCKZoneRules.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void test_London_getStandardOffset() { ZoneRules test = europeLondon(); ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC); while (zdt.getYear() < 2010) { Instant instant = zdt.toInstant(); if (zdt.getYear() < 1848) { assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15)); } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) { assertEquals(test.getStandardOffset(instant), OFFSET_PONE); } else { assertEquals(test.getStandardOffset(instant), OFFSET_ZERO); } zdt = zdt.plusMonths(6); } }
Example #24
Source File: TCKInstantPrinterParser.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Test public void test_parse_leapSecond() { Instant expected = OffsetDateTime.of(1970, 2, 3, 23, 59, 59, 123456789, ZoneOffset.UTC).toInstant(); DateTimeFormatter f = new DateTimeFormatterBuilder().appendInstant(-1).toFormatter(); for (ResolverStyle style : ResolverStyle.values()) { TemporalAccessor parsed = f.withResolverStyle(style).parse("1970-02-03T23:59:60.123456789Z"); assertEquals(parsed.query(Instant::from), expected); assertEquals(parsed.query(DateTimeFormatter.parsedExcessDays()), Period.ZERO); assertEquals(parsed.query(DateTimeFormatter.parsedLeapSecond()), Boolean.TRUE); } }
Example #25
Source File: OffsetTimeCodecTest.java From r2dbc-mysql with Apache License 2.0 | 5 votes |
OffsetTimeCodecTest() { OffsetTime[] times = new OffsetTime[LocalTimeCodecTest.TIMES.length << 2]; for (int i = 0; i < LocalTimeCodecTest.TIMES.length; ++i) { LocalTime time = LocalTimeCodecTest.TIMES[i]; times[i << 2] = OffsetTime.of(time, ZoneOffset.MIN); times[(i << 2) + 1] = OffsetTime.of(time, ZoneOffset.of("+6")); times[(i << 2) + 2] = OffsetTime.of(time, ZoneOffset.of("+10")); times[(i << 2) + 3] = OffsetTime.of(time, ZoneOffset.MAX); } this.times = times; }
Example #26
Source File: TCKZoneOffset.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void doTestOffset(ZoneOffset offset, int hours, int minutes, int seconds) { assertEquals(offset.getTotalSeconds(), hours * 60 * 60 + minutes * 60 + seconds); final String id; if (hours == 0 && minutes == 0 && seconds == 0) { id = "Z"; } else { String str = (hours < 0 || minutes < 0 || seconds < 0) ? "-" : "+"; str += Integer.toString(Math.abs(hours) + 100).substring(1); str += ":"; str += Integer.toString(Math.abs(minutes) + 100).substring(1); if (seconds != 0) { str += ":"; str += Integer.toString(Math.abs(seconds) + 100).substring(1); } id = str; } assertEquals(offset.getId(), id); assertEquals(offset, ZoneOffset.ofHoursMinutesSeconds(hours, minutes, seconds)); if (seconds == 0) { assertEquals(offset, ZoneOffset.ofHoursMinutes(hours, minutes)); if (minutes == 0) { assertEquals(offset, ZoneOffset.ofHours(hours)); } } assertEquals(ZoneOffset.of(id), offset); assertEquals(offset.toString(), id); }
Example #27
Source File: PackedInstant.java From tablesaw with Apache License 2.0 | 5 votes |
public static long pack(Instant instant) { if (instant == null) { return missingValueIndicator(); } LocalDateTime dateTime = LocalDateTime.ofInstant(instant, ZoneOffset.UTC); LocalDate date = dateTime.toLocalDate(); LocalTime time = dateTime.toLocalTime(); return (pack(date, time)); }
Example #28
Source File: TCKOffsetDateTime.java From j2objc with Apache License 2.0 | 5 votes |
@Test(expected=NullPointerException.class) public void constructor_nullTime() throws Throwable { Constructor<OffsetDateTime> con = OffsetDateTime.class.getDeclaredConstructor(LocalDateTime.class, ZoneOffset.class); con.setAccessible(true); try { con.newInstance(null, OFFSET_PONE); } catch (InvocationTargetException ex) { throw ex.getCause(); } }
Example #29
Source File: TCKOffsetDateTime.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void check(OffsetDateTime test, int y, int mo, int d, int h, int m, int s, int n, ZoneOffset offset) { assertEquals(test.getYear(), y); assertEquals(test.getMonth().getValue(), mo); assertEquals(test.getDayOfMonth(), d); assertEquals(test.getHour(), h); assertEquals(test.getMinute(), m); assertEquals(test.getSecond(), s); assertEquals(test.getNano(), n); assertEquals(test.getOffset(), offset); assertEquals(test, test); assertEquals(test.hashCode(), test.hashCode()); assertEquals(OffsetDateTime.of(LocalDateTime.of(y, mo, d, h, m, s, n), offset), test); }
Example #30
Source File: OffsetDateTimeDeserializerIT.java From bootique with Apache License 2.0 | 5 votes |
@Test public void testDeserialization02() throws Exception { OffsetDateTime offsetDateTime = OffsetDateTime.of(2017, 9, 2, 10, 15, 30, 0, ZoneOffset.ofHours(1)); OffsetDateTime value = deserialize(OffsetDateTime.class, "\"2017-09-02T10:15:30+01:00\""); assertNotNull(value, "The value should not be null."); assertEquals(offsetDateTime, value, "The value is not correct."); }