@Test public void now_Clock_allSecsInDay_utc() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); OffsetDateTime test = OffsetDateTime.now(clock); assertEquals(test.getYear(), 1970); assertEquals(test.getMonth(), Month.JANUARY); assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2)); assertEquals(test.getHour(), (i / (60 * 60)) % 24); assertEquals(test.getMinute(), (i / 60) % 60); assertEquals(test.getSecond(), i % 60); assertEquals(test.getNano(), 123456789); assertEquals(test.getOffset(), ZoneOffset.UTC); } }
@Test(dataProvider="RangeVersusCalendar") public void test_JapaneseChrono_vsCalendar(LocalDate isoStartDate, LocalDate isoEndDate) { Locale locale = Locale.forLanguageTag("ja-JP-u-ca-japanese"); assertEquals(locale.toString(), "ja_JP_#u-ca-japanese", "Unexpected locale"); Calendar cal = java.util.Calendar.getInstance(locale); assertEquals(cal.getCalendarType(), "japanese", "Unexpected calendar type"); JapaneseDate jDate = JapaneseChronology.INSTANCE.date(isoStartDate); // Convert to millis and set Japanese Calendar to that start date (at GMT) OffsetDateTime jodt = OffsetDateTime.of(isoStartDate, LocalTime.MIN, ZoneOffset.UTC); long millis = jodt.toInstant().toEpochMilli(); cal.setTimeZone(TimeZone.getTimeZone("GMT+00")); cal.setTimeInMillis(millis); while (jDate.isBefore(isoEndDate)) { assertEquals(jDate.get(ChronoField.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH), "Day mismatch in " + jDate + "; cal: " + cal); assertEquals(jDate.get(ChronoField.MONTH_OF_YEAR), cal.get(Calendar.MONTH) + 1, "Month mismatch in " + jDate); assertEquals(jDate.get(ChronoField.YEAR_OF_ERA), cal.get(Calendar.YEAR), "Year mismatch in " + jDate); jDate = jDate.plus(1, ChronoUnit.DAYS); cal.add(Calendar.DAY_OF_MONTH, 1); } }
/** * Create a graph * @param goalInKg the goal set * @param measurements the measurement data * @return a chart */ public Chart create(BigDecimal goalInKg, Iterable<WeightMeasurement> measurements) { BigDecimal minValue = goalInKg; BigDecimal maxValue = goalInKg; List<List<Object>> dataPoints = new ArrayList<>(); for (WeightMeasurement wm : measurements) { if (minValue == null) { minValue = wm.getWeightInKg(); } else { minValue = minValue.min(wm.getWeightInKg()); } if (maxValue == null) { maxValue = wm.getWeightInKg(); } else { maxValue = maxValue.max(wm.getWeightInKg()); } dataPoints.add(Lists.newArrayList(wm.getDateTime().toInstant(ZoneOffset.UTC).toEpochMilli(),wm.getWeightInKg())); } if (minValue != null) { minValue = minValue.subtract(BigDecimal.valueOf(1)); } if (maxValue != null) { maxValue = maxValue.add(BigDecimal.valueOf(1)); } return Chart.of(minValue, maxValue, goalInKg, dataPoints, calculareTrend(dataPoints)); }
@Test public void test_factory_string_hours_minutes_noColon() { for (int i = -17; i <= 17; i++) { for (int j = -59; j <= 59; j++) { if ((i < 0 && j <= 0) || (i > 0 && j >= 0) || i == 0) { String str = (i < 0 || j < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1) + Integer.toString(Math.abs(j) + 100).substring(1); ZoneOffset test = ZoneOffset.of(str); doTestOffset(test, i, j, 0); } } } ZoneOffset test1 = ZoneOffset.of("-1800"); doTestOffset(test1, -18, 0, 0); ZoneOffset test2 = ZoneOffset.of("+1800"); doTestOffset(test2, 18, 0, 0); }
@Test public void testLoad() throws Exception { new ExecuteAsTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC)) .run(() -> assertThat( load("2017-08-28T07:09:36.000000042Z") .isEqual(OffsetDateTime.of(2017, 8, 28, 7, 9, 36, 42, ZoneOffset.UTC)), is(true) )); }
@Test(dataProvider="calendars") public void test_badPlusTemporalUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); TemporalUnit adjuster = new FixedTemporalUnit(czdt2); if (chrono != chrono2) { try { czdt.plus(1, adjuster); Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException, " + czdt + " can not be cast to " + czdt2); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoZonedDateTime<?> result = czdt.plus(1, adjuster); assertEquals(result, czdt2, "WithAdjuster failed to replace date"); } } }
@Test public void convert_willHandleCollectionOfOffsetDateTimeValues_whenValuesHaveOffset() { OffsetDateTime time1 = OffsetDateTime.of(2017, 10, 11, 17, 24, 36, 123456789, ZoneOffset.ofHours(10)); OffsetDateTime time2 = OffsetDateTime.of(2017, 10, 15, 16, 28, 40, 123456789, ZoneOffset.ofHours(10)); assertThat(convertCollection( Arrays.asList(time1, time2) )).isEqualTo( Arrays.asList("2017-10-11", "2017-10-15") ); assertThat(convertCollection( new OffsetDateTime[]{time1, time2} )).isEqualTo( Arrays.asList("2017-10-11", "2017-10-15") ); }
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()); }
@Test public void testNavDate() throws IOException { OffsetDateTime navDate = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); Manifest manifest = new Manifest("http://some.uri", "A label for the Manifest"); manifest.setNavDate(navDate); String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(manifest); DocumentContext ctx = JsonPath.parse(json); JsonPathAssert.assertThat(ctx).jsonPathAsString("navDate").isEqualTo("1970-01-01T00:00:00Z"); assertThat(mapper.readValue(json, Manifest.class).getNavDate()).isEqualTo(manifest.getNavDate()); Collection coll = new Collection("http://some.uri", "A label for the Collection"); coll.setNavDate(navDate); json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(coll); ctx = JsonPath.parse(json); JsonPathAssert.assertThat(ctx).jsonPathAsString("navDate").isEqualTo("1970-01-01T00:00:00Z"); assertThat(mapper.readValue(json, Collection.class).getNavDate()).isEqualTo(navDate); }
private void doTest_factory_ofInstant_all(long minYear, long maxYear) { long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7); int minOffset = (minYear <= 0 ? 0 : 3); int maxOffset = (maxYear <= 0 ? 0 : 3); long minDays = (minYear * 365L + ((minYear + minOffset) / 4L - (minYear + minOffset) / 100L + (minYear + minOffset) / 400L)) - days_0000_to_1970; long maxDays = (maxYear * 365L + ((maxYear + maxOffset) / 4L - (maxYear + maxOffset) / 100L + (maxYear + maxOffset) / 400L)) + 365L - days_0000_to_1970; final LocalDate maxDate = LocalDate.of(Year.MAX_VALUE, 12, 31); OffsetDateTime expected = OffsetDateTime.of(LocalDate.of((int) minYear, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC); for (long i = minDays; i < maxDays; i++) { Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L); try { OffsetDateTime test = OffsetDateTime.ofInstant(instant, ZoneOffset.UTC); assertEquals(test, expected); if (expected.toLocalDate().equals(maxDate) == false) { expected = expected.plusDays(1); } } catch (RuntimeException|Error ex) { System.out.println("Error: " + i + " " + expected); throw ex; } } }
@Test(dataProvider="calendars") public void test_badMinusTemporalUnitChrono(Chronology chrono) { LocalDate refDate = LocalDate.of(2013, 1, 1); ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); for (Chronology[] clist : data_of_calendars()) { Chronology chrono2 = clist[0]; ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC); TemporalUnit adjuster = new FixedTemporalUnit(czdt2); if (chrono != chrono2) { try { czdt.minus(1, adjuster); Assert.fail("TemporalUnit.doPlus minus should have thrown a ClassCastException, " + czdt.getClass() + " can not be cast to " + czdt2.getClass()); } catch (ClassCastException cce) { // Expected exception; not an error } } else { // Same chronology, ChronoZonedDateTime<?> result = czdt.minus(1, adjuster); assertEquals(result, czdt2, "WithAdjuster failed to replace date"); } } }
@Override public boolean onMouseDrag(MouseEvent e, double x, double y) { view.preparePopup(this.toString()); dragged = true; if (isMoving) { long mins = (endTime.toEpochSecond(ZoneOffset.UTC) - startTime.toEpochSecond(ZoneOffset.UTC)) / 60; startTime = view.roundLocalDateTime(view.getMouseLocalDateTime().plusMinutes(minsOffset)); endTime = startTime.plusMinutes(mins); } else { LocalDateTime newEndTime = view.roundLocalDateTime(view.getMouseLocalDateTime()); if (newEndTime.isAfter(startTime)) { endTime = newEndTime; } } return true; }
@Test public final void testParsingCustomFormattedStringToDate() { MatcherAssert.assertThat( "Can't parse a Date with custom format.", new DateOf( "2017-12-13 14:15:16.000000017", "yyyy-MM-dd HH:mm:ss.n" ).value(), Matchers.is( Date.from( LocalDateTime.of( 2017, 12, 13, 14, 15, 16, 17 ).toInstant(ZoneOffset.UTC) ) ) ); }
@DataProvider(name="adjustInto") Object[][] data_adjustInto() { return new Object[][]{ {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null}, {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null}, {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null}, {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null}, {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null}, {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null}, {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null}, {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class}, }; }
@Test public final void testParsingCustomFormatterStringToDate() { MatcherAssert.assertThat( "Can't parse a Date with custom format.", new DateOf( "2017-12-13 14:15:16.000000017", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.n") ).value(), Matchers.is( Date.from( LocalDateTime.of( 2017, 12, 13, 14, 15, 16, 17 ).toInstant(ZoneOffset.UTC) ) ) ); }
private ZoneOffsetTransition checkOffset(ZoneRules rules, LocalDateTime dateTime, ZoneOffset offset, int type) { List<ZoneOffset> validOffsets = rules.getValidOffsets(dateTime); assertEquals(validOffsets.size(), type); assertEquals(rules.getOffset(dateTime), offset); if (type == 1) { assertEquals(validOffsets.get(0), offset); return null; } else { ZoneOffsetTransition zot = rules.getTransition(dateTime); assertNotNull(zot); assertEquals(zot.isOverlap(), type == 2); assertEquals(zot.isGap(), type == 0); assertEquals(zot.isValidOffset(offset), type == 2); return zot; } }
public void test_equals() { Clock a = Clock.systemUTC(); Clock b = Clock.systemUTC(); assertEquals(a.equals(a), true); assertEquals(a.equals(b), true); assertEquals(b.equals(a), true); assertEquals(b.equals(b), true); Clock c = Clock.system(PARIS); Clock d = Clock.system(PARIS); assertEquals(c.equals(c), true); assertEquals(c.equals(d), true); assertEquals(d.equals(c), true); assertEquals(d.equals(d), true); assertEquals(a.equals(c), false); assertEquals(c.equals(a), false); assertEquals(a.equals(null), false); assertEquals(a.equals("other type"), false); assertEquals(a.equals(Clock.fixed(Instant.now(), ZoneOffset.UTC)), false); }
public static Node getPost(Node author, Long time) { LocalDateTime postedDateTime = LocalDateTime.ofEpochSecond(time, 0, ZoneOffset.UTC); RelationshipType original = RelationshipType.withName("POSTED_ON_" + postedDateTime.format(dateFormatter)); Node post = null; for(Relationship r1 : author.getRelationships(Direction.OUTGOING, original)) { Node potential = r1.getEndNode(); if (time.equals(potential.getProperty(TIME))) { post = potential; break; } } if(post == null) { throw PostExceptions.postNotFound; }; return post; }
@Test public void now_Clock() { Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); MonthDay test = MonthDay.now(clock); assertEquals(test.getMonth(), Month.DECEMBER); assertEquals(test.getDayOfMonth(), 31); }
public void test_London_getOffsetInfo_fromDST() { ZoneId test = ZoneId.of("Europe/London"); checkOffset(test.getRules(), createLDT(2008, 10, 24), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 10, 25), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 10, 26), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 10, 27), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 10, 28), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 10, 29), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 10, 30), ZoneOffset.ofHours(0), 1); checkOffset(test.getRules(), createLDT(2008, 10, 31), ZoneOffset.ofHours(0), 1); // cutover at 01:00Z checkOffset(test.getRules(), LocalDateTime.of(2008, 10, 26, 0, 59, 59, 999999999), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), LocalDateTime.of(2008, 10, 26, 1, 30, 0, 0), ZoneOffset.ofHours(1), OVERLAP); checkOffset(test.getRules(), LocalDateTime.of(2008, 10, 26, 2, 0, 0, 0), ZoneOffset.ofHours(0), 1); }
@Test public void testSave() throws Exception { assertThat( save(ZonedDateTime.of(2017, 8, 28, 7, 9, 36, 42, ZoneOffset.UTC)), is(date("2017-08-28T07:09:36Z")) ); }
@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); }
@Test(dataProvider="offsets") public void test_parse_endStringMatch(String pattern, String parse, ZoneOffset expected) throws Exception { ParsePosition pos = new ParsePosition(5); TemporalAccessor parsed = getFormatter(pattern, "Z").parseUnresolved("OTHER" + parse, pos); assertEquals(pos.getIndex(), parse.length() + 5); assertParsed(parsed, expected); }
@Test public void testSave_willConvertToUTC_whenInputHasAnotherOffset() { assertThat( save(OffsetDateTime.of(2017, 8, 29, 3, 9, 36, 42, ZoneOffset.ofHours(10))), is("2017-08-28T17:09:36.000000042Z") ); }
@Test public void now_Clock_offsets() { Instant base = LocalDateTime.of(1970, 1, 1, 12, 0).toInstant(ZoneOffset.UTC); for (int i = -9; i < 15; i++) { ZoneOffset offset = ZoneOffset.ofHours(i); Clock clock = Clock.fixed(base, offset); OffsetTime test = OffsetTime.now(clock); assertEquals(test.getHour(), (12 + i) % 24); assertEquals(test.getMinute(), 0); assertEquals(test.getSecond(), 0); assertEquals(test.getNano(), 0); assertEquals(test.getOffset(), offset); } }
@Test public void testSave_willConvertToUTC_whenInputHasAnotherOffset() throws Exception { assertThat( save(ZonedDateTime.of(2017, 8, 29, 3, 9, 36, 42, ZoneOffset.ofHours(10))), is("2017-08-28T17:09:36.000000042Z") ); }
@Test public void test_toEpochSecond_afterEpoch() { for (int i = 0; i < 100000; i++) { OffsetDateTime a = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).plusSeconds(i); assertEquals(a.toEpochSecond(), i); } }
/** * Creates a local date-time in this chronology from an instant and zone. * * @param instant the instant, not null * @param zoneId the zone ID, not null * @return the local date-time, not null */ ChronoDateTimeImpl<C> localInstant(Instant instant, ZoneId zoneId) { ZoneRules rules = zoneId.getRules(); ZoneOffset offset = rules.getOffset(instant); LocalDateTime ldt = LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), offset); return ChronoDateTimeImpl.of(dateNow(), LocalTime.MIDNIGHT).with(ldt); // not very efficient... }
@Test(expected = HttpClientErrorException.class) @Transactional public void attendFailCauseRegistClose() { Meeting meeting = meetingService.findById(user1MeetingId).get(); meeting.setMeetingStatus(Meeting.MeetingStatus.PUBLISHED); Date minPlusOpenTime = DateUtils.addMinutes(Date.from(ZonedDateTime.now(ZoneOffset.UTC).toInstant()), -10); meeting.setRegistCloseAt(minPlusOpenTime); meetingAttendService.attend(meeting, baseDataTestHelper.getUser2()); }
@Test(expectedExceptions=DateTimeException.class) public void factory_ofInstant_tooLow() { long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7); int year = Year.MIN_VALUE - 1; long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970; Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L); ZonedDateTime.ofInstant(instant, ZoneOffset.UTC); }
/** * Time to UTC. * @param time Time in the DB * @return UTC */ private static String utc(final long time) { return ZonedDateTime.ofInstant( new Date(time).toInstant(), ZoneOffset.UTC ).format(DateTimeFormatter.ISO_INSTANT); }
public Log(Application application, Interaction interaction, ZonedDateTime start, Session session) { values = new HashMap<>(); values.put("application", application); values.put("session", session); //values.put("module", module); values.put("timestamp", DateTimeFormatter.ofPattern(SOLR_DATE_TIME_FORMAT).format(start.withZoneSameInstant(ZoneOffset.UTC))); values.put("type","interaction"); values.put("request", interaction); }
@Test(dataProvider="offsetBasedValidOther") public void factory_of_String_offsetBasedValidOther(String input, String offsetId) { ZoneId test = ZoneId.of(input); assertEquals(test.getId(), input); assertEquals(test.getRules(), ZoneOffset.of(offsetId).getRules()); assertEquals(test.normalized(), ZoneOffset.of(offsetId)); }
@Test(dataProvider="sampleTimes") public void test_equals_false_minute_differs(int h, int m, int s, int n, ZoneOffset ignored) { m = (m == 59 ? 58 : m); OffsetTime a = OffsetTime.of(h, m, s, n, OFFSET_PONE); OffsetTime b = OffsetTime.of(h, m + 1, s, n, OFFSET_PONE); assertEquals(a.equals(b), false); }
public void test_Paris_getOffsetInfo_fromDST() { ZoneId test = ZoneId.of("Europe/Paris"); checkOffset(test.getRules(), createLDT(2008, 10, 24), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), createLDT(2008, 10, 25), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), createLDT(2008, 10, 26), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), createLDT(2008, 10, 27), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 10, 28), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 10, 29), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 10, 30), ZoneOffset.ofHours(1), 1); checkOffset(test.getRules(), createLDT(2008, 10, 31), ZoneOffset.ofHours(1), 1); // cutover at 01:00Z which is 02:00+01:00(local Paris time) checkOffset(test.getRules(), LocalDateTime.of(2008, 10, 26, 1, 59, 59, 999999999), ZoneOffset.ofHours(2), 1); checkOffset(test.getRules(), LocalDateTime.of(2008, 10, 26, 2, 30, 0, 0), ZoneOffset.ofHours(2), OVERLAP); checkOffset(test.getRules(), LocalDateTime.of(2008, 10, 26, 3, 0, 0, 0), ZoneOffset.ofHours(1), 1); }
@Test public void testIsAfterDatTime() { UrlItem item1 = new UrlItem("location1"); UrlItem item2 = new UrlItem("location2"); assertThat(item1.getRsMdDateTime(), is(nullValue())); assertThat(item1.isZDTAfter(item2), is(0)); RsMd rsmd1 = new RsMd() .withDateTime(ZonedDateTime.parse("2000-01-01T00:00:00.000Z").withZoneSameInstant(ZoneOffset.UTC)); item1.withMetadata(rsmd1); assertThat(item1.isZDTAfter(item2), is(0)); RsMd rsmd2 = new RsMd() .withDateTime(ZonedDateTime.parse("2000-01-01T00:00:00.000Z").withZoneSameInstant(ZoneOffset.UTC)); item2.withMetadata(rsmd2); assertThat(item1.isZDTAfter(item2), is(0)); rsmd2.withDateTime(ZonedDateTime.parse("2000-01-01T00:00:00.001Z").withZoneSameInstant(ZoneOffset.UTC)); assertThat(item1.isZDTAfter(item2), is(-1)); assertThat(item2.isZDTAfter(item1), is(1)); assertThat(item1.isZDTAfter(item1), is(0)); UrlItem latest = item1.latest(item2); assertThat(latest, equalTo(item2)); latest = item2.latest(item1); assertThat(latest, equalTo(item2)); rsmd2.withDateTime(ZonedDateTime.parse("2000-01-01T00:00:00.000Z").withZoneSameInstant(ZoneOffset.UTC)); latest = item1.latest(item2); assertThat(latest, equalTo(item2)); latest = item2.latest(item1); assertThat(latest, equalTo(item1)); }
private void handleMouseUp(double eventX, double eventY) { if (null != selectedSpot) { long fromMins = Math.round((dragStartX - TwoDayViewPresenter.SPOT_NAME_WIDTH - presenter.getState() .getOffsetX()) / (presenter.getState().getWidthPerMinute() * presenter.getConfig().getEditMinuteGradality())) * presenter.getConfig() .getEditMinuteGradality(); LocalDateTime from = LocalDateTime.ofEpochSecond(60 * fromMins, 0, ZoneOffset.UTC).plusSeconds( presenter.getState().getViewStartDate().toEpochSecond(ZoneOffset.UTC) - presenter.getState() .getBaseDate().toEpochSecond( ZoneOffset.UTC)); long toMins = Math.max(0, Math.round((mouseX - TwoDayViewPresenter.SPOT_NAME_WIDTH - presenter.getState() .getOffsetX()) / (presenter.getState().getWidthPerMinute() * presenter.getConfig().getEditMinuteGradality()))) * presenter.getConfig() .getEditMinuteGradality(); LocalDateTime to = LocalDateTime.ofEpochSecond(60 * toMins, 0, ZoneOffset.UTC).plusSeconds( presenter.getState().getViewStartDate().toEpochSecond(ZoneOffset.UTC) - presenter.getState() .getBaseDate().toEpochSecond( ZoneOffset.UTC)); if (to.equals(from)) { return; } else if (to.isBefore(from)) { LocalDateTime tmp = to; to = from; from = tmp; } presenter.getCalendar().addShift(selectedSpot, from, to); } }
public void test_NewYork_getOffset_toDST() { ZoneRules test = americaNewYork(); ZoneOffset offset = ZoneOffset.ofHours(-5); assertEquals(test.getOffset(createInstant(2008, 3, 8, offset)), ZoneOffset.ofHours(-5)); assertEquals(test.getOffset(createInstant(2008, 3, 9, offset)), ZoneOffset.ofHours(-5)); assertEquals(test.getOffset(createInstant(2008, 3, 10, offset)), ZoneOffset.ofHours(-4)); assertEquals(test.getOffset(createInstant(2008, 3, 11, offset)), ZoneOffset.ofHours(-4)); assertEquals(test.getOffset(createInstant(2008, 3, 12, offset)), ZoneOffset.ofHours(-4)); assertEquals(test.getOffset(createInstant(2008, 3, 13, offset)), ZoneOffset.ofHours(-4)); assertEquals(test.getOffset(createInstant(2008, 3, 14, offset)), ZoneOffset.ofHours(-4)); // cutover at 02:00 local assertEquals(test.getOffset(createInstant(2008, 3, 9, 1, 59, 59, 999999999, offset)), ZoneOffset.ofHours(-5)); assertEquals(test.getOffset(createInstant(2008, 3, 9, 2, 0, 0, 0, offset)), ZoneOffset.ofHours(-4)); }
@BeforeMethod public void setUp() { TEST_2007_07_15 = LocalDate.of(2007, 7, 15); LocalDate max = LocalDate.MAX; LocalDate min = LocalDate.MIN; MAX_VALID_EPOCHDAYS = max.toEpochDay(); MIN_VALID_EPOCHDAYS = min.toEpochDay(); MAX_DATE = max; MIN_DATE = min; MAX_INSTANT = max.atStartOfDay(ZoneOffset.UTC).toInstant(); MIN_INSTANT = min.atStartOfDay(ZoneOffset.UTC).toInstant(); }