Refine search
@Test public void shouldRangeSeekInOrderAscendingDateArray() throws Exception { Object o0 = new LocalDate[]{LocalDate.of( 10, 10, 1 )}; Object o1 = new LocalDate[]{LocalDate.of( 10, 10, 2 )}; Object o2 = new LocalDate[]{LocalDate.of( 10, 10, 3 )}; Object o3 = new LocalDate[]{LocalDate.of( 10, 10, 4 )}; Object o4 = new LocalDate[]{LocalDate.of( 10, 10, 5 )}; Object o5 = new LocalDate[]{LocalDate.of( 10, 10, 6 )}; shouldRangeSeekInOrder( IndexOrder.ASCENDING, o0, o1, o2, o3, o4, o5 ); }
@Test public void testDateToTimestampCoercion() { // allow running tests with a connector that supports TIMESTAMP but not DATE // ordinary date MaterializedResult rows = h2QueryRunner.execute(TEST_SESSION, "SELECT DATE '2018-01-13'", ImmutableList.of(TIMESTAMP)); assertEquals(rows.getOnlyValue(), LocalDate.of(2018, 1, 13).atStartOfDay()); // date, which midnight was skipped in JVM zone LocalDate forwardOffsetChangeAtMidnightInJvmZone = LocalDate.of(1970, 1, 1); checkState(ZoneId.systemDefault().getRules().getValidOffsets(forwardOffsetChangeAtMidnightInJvmZone.atStartOfDay()).size() == 0, "This test assumes certain JVM time zone"); rows = h2QueryRunner.execute(TEST_SESSION, DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(forwardOffsetChangeAtMidnightInJvmZone), ImmutableList.of(TIMESTAMP)); assertEquals(rows.getOnlyValue(), forwardOffsetChangeAtMidnightInJvmZone.atStartOfDay()); } }
@Test public void testLocallyUnrepresentableTimeLiterals() { LocalDateTime localTimeThatDidNotExist = LocalDateTime.of(2017, 4, 2, 2, 10); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotExist).isEmpty(), "This test assumes certain JVM time zone"); // This tests that both Presto runner and H2 can return TIMESTAMP value that never happened in JVM's zone (e.g. is not representable using java.sql.Timestamp) @Language("SQL") String sql = DateTimeFormatter.ofPattern("'SELECT TIMESTAMP '''uuuu-MM-dd HH:mm:ss''").format(localTimeThatDidNotExist); assertEquals(computeScalar(sql), localTimeThatDidNotExist); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner LocalDate localDateThatDidNotHaveMidnight = LocalDate.of(1970, 1, 1); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localDateThatDidNotHaveMidnight.atStartOfDay()).isEmpty(), "This test assumes certain JVM time zone"); // This tests that both Presto runner and H2 can return DATE value for a day which midnight never happened in JVM's zone (e.g. is not exactly representable using java.sql.Date) sql = DateTimeFormatter.ofPattern("'SELECT DATE '''uuuu-MM-dd''").format(localDateThatDidNotHaveMidnight); assertEquals(computeScalar(sql), localDateThatDidNotHaveMidnight); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner LocalTime localTimeThatDidNotOccurOn19700101 = LocalTime.of(0, 10); checkState(ZoneId.systemDefault().getRules().getValidOffsets(localTimeThatDidNotOccurOn19700101.atDate(LocalDate.ofEpochDay(0))).isEmpty(), "This test assumes certain JVM time zone"); checkState(!Objects.equals(java.sql.Time.valueOf(localTimeThatDidNotOccurOn19700101).toLocalTime(), localTimeThatDidNotOccurOn19700101), "This test assumes certain JVM time zone"); sql = DateTimeFormatter.ofPattern("'SELECT TIME '''HH:mm:ss''").format(localTimeThatDidNotOccurOn19700101); assertEquals(computeScalar(sql), localTimeThatDidNotOccurOn19700101); // this tests Presto and the QueryRunner assertQuery(sql); // this tests H2QueryRunner } }
@Test public void shouldRangeSeekInOrderDescendingDateArray() throws Exception { Object o0 = new LocalDate[]{LocalDate.of( 10, 10, 1 )}; Object o1 = new LocalDate[]{LocalDate.of( 10, 10, 2 )}; Object o2 = new LocalDate[]{LocalDate.of( 10, 10, 3 )}; Object o3 = new LocalDate[]{LocalDate.of( 10, 10, 4 )}; Object o4 = new LocalDate[]{LocalDate.of( 10, 10, 5 )}; Object o5 = new LocalDate[]{LocalDate.of( 10, 10, 6 )}; shouldRangeSeekInOrder( IndexOrder.DESCENDING, o0, o1, o2, o3, o4, o5 ); }
@Test(dataProvider = "yearFraction") public void test_yearFraction(DayCount dayCount, int y1, int m1, int d1, int y2, int m2, int d2, Double value) { double expected = (value == SIMPLE_30_360 ? calc360(y1, m1, d1, y2, m2, d2) : value); LocalDate date1 = LocalDate.of(y1, m1, d1); LocalDate date2 = LocalDate.of(y2, m2, d2); assertEquals(dayCount.yearFraction(date1, date2), expected, TOLERANCE_ZERO); }
@Test public void shouldRangeSeekInOrderDescendingDateArray() throws Exception { Object o0 = new LocalDate[]{LocalDate.of( 10, 10, 1 )}; Object o1 = new LocalDate[]{LocalDate.of( 10, 10, 2 )}; Object o2 = new LocalDate[]{LocalDate.of( 10, 10, 3 )}; Object o3 = new LocalDate[]{LocalDate.of( 10, 10, 4 )}; Object o4 = new LocalDate[]{LocalDate.of( 10, 10, 5 )}; Object o5 = new LocalDate[]{LocalDate.of( 10, 10, 6 )}; shouldSeekInOrderExactWithRange( IndexOrder.DESCENDING, o0, o1, o2, o3, o4, o5 ); }
public void test_actActIcma_longInitialStub_eomFlagEom_long() { // nominals, 2011-08-31 (P91D) 2011-11-30 (P91D) 2012-02-29 LocalDate start = LocalDate.of(2011, 10, 1); LocalDate periodEnd = LocalDate.of(2012, 2, 29); LocalDate end = LocalDate.of(2012, 1, 12); // after first nominal ScheduleInfo info = new Info(start, periodEnd.plus(P3M), periodEnd, true, P3M); assertEquals(ACT_ACT_ICMA.yearFraction(start, end, info), (60d / (91d * 4d)) + (43d / (91d * 4d)), TOLERANCE_ZERO); }
@Test public void shouldRangeSeekInOrderAscendingDateArray() throws Exception { Object o0 = new LocalDate[]{LocalDate.of( 10, 10, 1 )}; Object o1 = new LocalDate[]{LocalDate.of( 10, 10, 2 )}; Object o2 = new LocalDate[]{LocalDate.of( 10, 10, 3 )}; Object o3 = new LocalDate[]{LocalDate.of( 10, 10, 4 )}; Object o4 = new LocalDate[]{LocalDate.of( 10, 10, 5 )}; Object o5 = new LocalDate[]{LocalDate.of( 10, 10, 6 )}; shouldSeekInOrderExactWithRange( IndexOrder.ASCENDING, o0, o1, o2, o3, o4, o5 ); }
public void test_actActIcma_singlePeriod() { LocalDate start = LocalDate.of(2003, 11, 1); LocalDate end = LocalDate.of(2004, 5, 1); ScheduleInfo info = new Info(start, end, end, true, P6M); assertEquals(ACT_ACT_ICMA.yearFraction(start, end.minusDays(1), info), (181d / (182d * 2d)), TOLERANCE_ZERO); assertEquals(ACT_ACT_ICMA.yearFraction(start, end, info), (182d / (182d * 2d)), TOLERANCE_ZERO); }
@Test public void testFromToBy() { assertContentEquals( create("dates", new LocalDate[5]) .fillWith( range(LocalDate.of(2018, 3, 1), // year, month, day LocalDate.of(2019, 3, 1), 1, ChronoUnit.DAYS)), LocalDate.of(2018, 3, 1), // year, month, day LocalDate.of(2018, 3, 2), LocalDate.of(2018, 3, 3), LocalDate.of(2018, 3, 4), LocalDate.of(2018, 3, 5)); assertContentEquals(create("dates", new LocalDate[5]) .fillWith(range(LocalDate.of(2018, 3, 1), // year, month, day LocalDate.of(2019, 3, 1), 1, ChronoUnit.MONTHS)), LocalDate.of(2018, 3, 1), // year, month, day LocalDate.of(2018, 4, 1), LocalDate.of(2018, 5, 1), LocalDate.of(2018, 6, 1), LocalDate.of(2018, 7, 1)); } }
@Test(dataProvider = "hubu") public void test_hubu(int year, List<LocalDate> holidays, List<LocalDate> workDays) { LocalDate date = LocalDate.of(year, 1, 1); int len = date.lengthOfYear(); for (int i = 0; i < len; i++) { boolean isHoliday = (holidays.contains(date) || date.getDayOfWeek() == SATURDAY || date.getDayOfWeek() == SUNDAY) && !workDays.contains(date); assertEquals(HUBU.isHoliday(date), isHoliday, date.toString()); date = date.plusDays(1); } }
@Test public void testRollingMaxDate() { LocalDateTime[] data = new LocalDateTime[]{ LocalDate.of(2011, 1, 1).atStartOfDay(), LocalDate.of(2011, 1, 3).atStartOfDay(), LocalDate.of(2011, 1, 5).atStartOfDay(), LocalDate.of(2011, 1, 7).atStartOfDay(), LocalDate.of(2011, 1, 9).atStartOfDay() }; LocalDateTime[] sma5 = new LocalDateTime[]{ null, LocalDate.of(2011, 1, 3).atStartOfDay(), LocalDate.of(2011, 1, 5).atStartOfDay(), LocalDate.of(2011, 1, 7).atStartOfDay(), LocalDate.of(2011, 1, 9).atStartOfDay() }; DateTimeColumn result = (DateTimeColumn) DateTimeColumn.create("data", data).rolling(2).calc(latestDateTime); assertArrayEquals(sma5, result.asObjectArray()); }
@Test(dataProvider = "nyse") public void test_nyse(int year, List<LocalDate> holidays) { LocalDate date = LocalDate.of(year, 1, 1); int len = date.lengthOfYear(); for (int i = 0; i < len; i++) { boolean isHoliday = holidays.contains(date) || date.getDayOfWeek() == SATURDAY || date.getDayOfWeek() == SUNDAY; assertEquals(NYSE.isHoliday(date), isHoliday, date.toString()); date = date.plusDays(1); } }
@Test public void testConversion() throws ParseException { Calendar cal = Calendar.getInstance(); cal.set(2016, Calendar.MAY, 1, 0, 0, 0); cal.clear(Calendar.MILLISECOND); assertFormat(LocalDate.of(2016, 5, 1), cal.getTime()); compare(LocalDate.class, LocalDate.now()); compare(LocalDate.class, LocalDate.of(14478, 10, 15)); } }
@Test(dataProvider = "brbd") public void test_brbd(int year, List<LocalDate> holidays) { LocalDate date = LocalDate.of(year, 1, 1); int len = date.lengthOfYear(); for (int i = 0; i < len; i++) { boolean isHoliday = holidays.contains(date) || date.getDayOfWeek() == SATURDAY || date.getDayOfWeek() == SUNDAY; assertEquals(BRBD.isHoliday(date), isHoliday, date.toString()); date = date.plusDays(1); } }
@Test public void createOriginalIteratorForLocalDate() { LocalDate from = LocalDate.of(2016, 7, 1); LocalDate to = LocalDate.of(2016, 7, 10); assertAllElementsOfIterator(new TemporalValueRange<>(from, to, 1, ChronoUnit.DAYS).createOriginalIterator(), LocalDate.of(2016, 7, 1), LocalDate.of(2016, 7, 2), LocalDate.of(2016, 7, 3), LocalDate.of(2016, 7, 4), LocalDate.of(2016, 7, 5), LocalDate.of(2016, 7, 6), LocalDate.of(2016, 7, 7), LocalDate.of(2016, 7, 8), LocalDate.of(2016, 7, 9)); assertAllElementsOfIterator(new TemporalValueRange<>(from, to, 3, ChronoUnit.DAYS).createOriginalIterator(), LocalDate.of(2016, 7, 1), LocalDate.of(2016, 7, 4), LocalDate.of(2016, 7, 7)); from = LocalDate.of(2016, 9, 3); to = LocalDate.of(2017, 3, 3); assertAllElementsOfIterator(new TemporalValueRange<>(from, to, 1, ChronoUnit.MONTHS).createOriginalIterator(), LocalDate.of(2016, 9, 3), LocalDate.of(2016, 10, 3), LocalDate.of(2016, 11, 3), LocalDate.of(2016, 12, 3), LocalDate.of(2017, 1, 3), LocalDate.of(2017, 2, 3)); from = LocalDate.of(1999, 9, 3);
@Test(dataProvider = "noos") public void test_noos(int year, List<LocalDate> holidays) { LocalDate date = LocalDate.of(year, 1, 1); int len = date.lengthOfYear(); for (int i = 0; i < len; i++) { boolean isHoliday = holidays.contains(date) || date.getDayOfWeek() == SATURDAY || date.getDayOfWeek() == SUNDAY; assertEquals(NOOS.isHoliday(date), isHoliday, date.toString()); date = date.plusDays(1); } }
@Test public void createRandomIteratorForLocalDate() { Random workingRandom = mock(Random.class); LocalDate from = LocalDate.of(2016, 7, 1); LocalDate to = LocalDate.of(2016, 7, 11); when(workingRandom.nextInt(anyInt())).thenReturn(3, 0); assertElementsOfIterator(new TemporalValueRange<>(from, to, 1, ChronoUnit.DAYS).createRandomIterator(workingRandom), LocalDate.of(2016, 7, 4)); when(workingRandom.nextInt(anyInt())).thenReturn(0, 0); assertElementsOfIterator(new TemporalValueRange<>(from, to, 1, ChronoUnit.DAYS).createRandomIterator(workingRandom), LocalDate.of(2016, 7, 1)); when(workingRandom.nextInt(anyInt())).thenReturn(1, 0); assertElementsOfIterator(new TemporalValueRange<>(from, to, 5, ChronoUnit.DAYS).createRandomIterator(workingRandom), LocalDate.of(2016, 7, 6)); }
@Test public void testBindLocalDate() throws SQLException { ArgumentFactory factory = new JavaTimeArgumentFactory(); LocalDate date = LocalDate.of(2001, 1, 1); Optional<Argument> optionalArgument = factory.build(LocalDate.class, date, null); assertThat(optionalArgument).isPresent(); Argument argument = optionalArgument.get(); argument.apply(5, stmt, ctx); verify(stmt).setDate(5, java.sql.Date.valueOf(date)); }