@Test public void testSetInParameter_mapperForLocalDate() throws ParseException, SQLException { LocalDate localDate = LocalDate.of(2002, Month.JANUARY, 1); Date date = DateUtils.parseDate("2002-01-01", new String[] { "yyyy-MM-dd" }); try (SqlAgent agent = config.agent()) { SqlContext ctx = agent.contextFrom("test/PARAM_MAPPING1").param("targetDate", localDate); try (ResultSet rs = agent.query(ctx)) { assertThat("結果が0件です。", rs.next(), is(true)); assertThat(rs.getDate("TARGET_DATE"), is(new java.sql.Date(date.getTime()))); assertThat("取得データが多すぎます", rs.next(), is(false)); } } }
@Test public void test_next() { for (Month month : Month.values()) { for (int i = 1; i <= month.length(false); i++) { LocalDate date = date(2007, month, i); for (DayOfWeek dow : DayOfWeek.values()) { LocalDate test = (LocalDate) TemporalAdjusters.next(dow).adjustInto(date); assertSame(test.getDayOfWeek(), dow, date + " " + test); if (test.getYear() == 2007) { int dayDiff = test.getDayOfYear() - date.getDayOfYear(); assertTrue(dayDiff > 0 && dayDiff < 8); } else { assertSame(month, Month.DECEMBER); assertTrue(date.getDayOfMonth() > 24); assertEquals(test.getYear(), 2008); assertSame(test.getMonth(), Month.JANUARY); assertTrue(test.getDayOfMonth() < 8); } } } } }
public static void demo1_speedModel() { double timeSec = 10.0; TrafficUnit trafficUnit = FactoryTraffic.getOneUnit(Month.APRIL, DayOfWeek.FRIDAY, 17, "USA", "Denver", "Main103S"); Vehicle vehicle = FactoryVehicle.build(trafficUnit); SpeedModel speedModel = FactorySpeedModel.generateSpeedModel(trafficUnit); vehicle.setSpeedModel(speedModel); printResult(trafficUnit, timeSec, vehicle.getSpeedMph(timeSec)); speedModel = (t, wp, hp) -> calculateSpeed(trafficUnit, t, wp, hp); vehicle.setSpeedModel(speedModel); printResult(trafficUnit, timeSec, vehicle.getSpeedMph(timeSec)); speedModel = (t, wp, hp) -> { double tr = trafficUnit.getTraction(); double weightPower = 2.0 * hp * 746 * 32.174 / wp; return Math.round(Math.sqrt(t * weightPower) * 0.68 * tr); }; vehicle.setSpeedModel(speedModel); printResult(trafficUnit, timeSec, vehicle.getSpeedMph(timeSec)); }
@Test public void testInsert() throws Exception { try (SqlAgent agent = config.agent()) { agent.required(() -> { // INSERT TestEntity test = new TestEntity(); test.setId(100); test.setName("name100"); test.setAge(20); test.setBirthday(LocalDate.of(1990, Month.APRIL, 1)); test.setMemo(Optional.of("memo text")); agent.insert(test); // check TestEntity data = agent.find(TestEntity.class, 100).orElse(null); assertThat(data, is(test)); }); } }
/** * {@link M5#instantOfNextFrame(Instant)} should return the instant with the minutes set to the earliest possible * {@link Instant} that is later than the {@link Instant} past and thats minutes are a multiple of 5. */ @Test public void m5InstantOfNextFrameShouldReturnTheNextInstantThatsMinutesAreAMultipleOfFive() { final M5 cut = new M5(); assertThat(cut.instantOfNextFrame(LocalDate.of(2074, Month.MARCH, 30).atTime(20, 4, 0, 0).toInstant(UTC))) .isEqualTo(LocalDate.of(2074, Month.MARCH, 30).atTime(20, 5, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(LocalDate.of(1999, Month.APRIL, 23).atTime(15, 59, 0, 0).toInstant(UTC))) .isEqualTo(LocalDate.of(1999, Month.APRIL, 23).atTime(16, 0, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(LocalDate.of(2007, Month.SEPTEMBER, 6).atTime(17, 29, 0, 0).toInstant(UTC))) .isEqualTo(LocalDate.of(2007, Month.SEPTEMBER, 6).atTime(17, 30, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(LocalDate.of(2021, Month.JUNE, 8).atTime(8, 34, 0, 0).toInstant(UTC))) .isEqualTo(LocalDate.of(2021, Month.JUNE, 8).atTime(8, 35, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(LocalDate.of(1570, Month.NOVEMBER, 24).atTime(23, 7, 0, 0).toInstant(UTC))) .isEqualTo(LocalDate.of(1570, Month.NOVEMBER, 24).atTime(23, 10, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(LocalDate.of(2047, Month.JANUARY, 24).atTime(16, 15, 0, 0).toInstant(UTC))) .isEqualTo(LocalDate.of(2047, Month.JANUARY, 24).atTime(16, 20, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(LocalDate.of(1989, Month.JUNE, 10).atTime(15, 14, 37, 0).toInstant(UTC))) .isEqualTo(LocalDate.of(1989, Month.JUNE, 10).atTime(15, 15, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(LocalDate.of(2006, Month.AUGUST, 10).atTime(3, 29, 0, 7521).toInstant(UTC))) .isEqualTo(LocalDate.of(2006, Month.AUGUST, 10).atTime(3, 30, 0, 0).toInstant(UTC)); assertThat( cut.instantOfNextFrame(LocalDate.of(3057, Month.NOVEMBER, 10).atTime(8, 54, 12, 45720).toInstant(UTC))) .isEqualTo(LocalDate.of(3057, Month.NOVEMBER, 10).atTime(8, 55, 0, 0).toInstant(UTC)); }
/** * {@link M15#instantOfNextFrame(Instant)} should return the instant with the minutes set to the earliest possible * {@link Instant} that is later than the {@link Instant} past and thats minutes are a multiple of 15. */ @Test public void m15InstantOfNextFrameShouldReturnTheNextInstantWhereTheMinutesAreAMultipleOf15() { final M15 cut = new M15(); final LocalDate someDay = LocalDate.of(2015, Month.SEPTEMBER, 11); assertThat(cut.instantOfNextFrame(someDay.atTime(20, 4, 0, 0).toInstant(UTC))) .isEqualTo(someDay.atTime(20, 15, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(someDay.atTime(15, 59, 0, 0).toInstant(UTC))) .isEqualTo(someDay.atTime(16, 0, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(someDay.atTime(17, 29, 0, 0).toInstant(UTC))) .isEqualTo(someDay.atTime(17, 30, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(someDay.atTime(23, 14, 59, 99999).toInstant(UTC))) .isEqualTo(someDay.atTime(23, 15, 0, 0).toInstant(UTC)); assertThat(cut.instantOfNextFrame(someDay.atTime(23, 53, 25, 82).toInstant(UTC))) .isEqualTo(someDay.plusDays(1).atTime(0, 0, 0, 0).toInstant(UTC)); }
@Test public void test_toString_floatingWeekBackwards_last() { ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, OFFSET_0200, OFFSET_0200, OFFSET_0300); assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, SUNDAY on or before last day of MARCH at 01:00 WALL, standard offset +02:00]"); }
@Test public void testUpdate1() throws Exception { try (SqlAgent agent = config.agent()) { agent.required(() -> { TestEntity test = new TestEntity(1, "name1", 20, LocalDate.of(1990, Month.APRIL, 1), Optional .of("memo1")); agent.insert(test); test.setName("updatename"); agent.update(test); TestEntity data = agent.find(TestEntity.class, 1).orElse(null); assertThat(data, is(test)); assertThat(data.getName(), is("updatename")); }); } }
@Test public void shouldReturnOneCustomerById() throws Exception { final LocalDate birthDate = LocalDate.of(1990, Month.JULY, 31); final Customer mockCustomer = Customer.ofType(PERSON).withBirthDate(birthDate).build(); final ObjectId id = ObjectId.get(); given(repo.findById(any(ObjectId.class))).willReturn(Mono.just(mockCustomer)); webClient.get().uri(String.format("/customers/%s", id)).accept(APPLICATION_JSON_UTF8).exchange() .expectStatus().isOk() // HTTP 200 .expectBody(Customer.class) .consumeWith(customer -> { assertThat(customer.getResponseBody().getCustomerType()).isEqualTo(PERSON); assertThat(customer.getResponseBody().getBirthDate()).isEqualTo(LocalDate.of(1990, 07, 31)); }); }
private void initTimeline(LocalDate start, LocalDate end) { this.timelineStart = start; this.timelineEnd = end; for(int m = start.getMonthValue(); m <= end.getMonthValue(); m++) { TableColumn<GanttTask,GanttBarPiece> monthCol = new TableColumn<GanttTask,GanttBarPiece>(); Label month = new Label(Month.of(m).toString()); monthCol.setGraphic(month); monthCol.setResizable(false); LocalDate tmp = LocalDate.of(start.getYear(), m, 1); LocalDate chartStart = start.compareTo(tmp) > 0 ? start : tmp; for(int d = chartStart.getDayOfMonth(); d <= chartStart.lengthOfMonth(); d++) { GanttDayColumn c = new GanttDayColumn(chartStart.getYear(), m, d); c.setPrefWidth(20); Label day = new Label(Integer.toString(d)); c.setGraphic(day); monthCol.getColumns().add(c); } this.getColumns().add(monthCol); } // TODO make timeline right-left scrollable with wheel on windows }
@Test public void test2() throws NoSuchMethodException, SecurityException, SQLException { PropertyMapperManager mapper = new PropertyMapperManager(); assertThat(mapper.getValue(JavaType.of(Year.class), newResultSet("getInt", 2000), 1), is(Year.of(2000))); assertThat(mapper.getValue(JavaType.of(YearMonth.class), newResultSet("getInt", 200004), 1), is(YearMonth.of(2000, 4))); assertThat(mapper.getValue(JavaType.of(MonthDay.class), newResultSet("getInt", 401), 1), is(MonthDay.of(4, 1))); assertThat(mapper.getValue(JavaType.of(Month.class), newResultSet("getInt", 4), 1), is(Month.APRIL)); assertThat(mapper.getValue(JavaType.of(DayOfWeek.class), newResultSet("getInt", 4), 1), is(DayOfWeek.THURSDAY)); assertThat(mapper.getValue(JavaType.of(Year.class), newResultSet("getInt", 0, "wasNull", true), 1), is(nullValue())); assertThat(mapper.getValue(JavaType.of(YearMonth.class), newResultSet("getInt", 0, "wasNull", true), 1), is(nullValue())); assertThat(mapper.getValue(JavaType.of(MonthDay.class), newResultSet("getInt", 0, "wasNull", true), 1), is(nullValue())); assertThat(mapper.getValue(JavaType.of(Month.class), newResultSet("getInt", 0, "wasNull", true), 1), is(nullValue())); assertThat(mapper.getValue(JavaType.of(DayOfWeek.class), newResultSet("getInt", 0, "wasNull", true), 1), is(nullValue())); }
@Override // override for performance LocalDate resolveYMD(Map <TemporalField, Long> fieldValues, ResolverStyle resolverStyle) { int y = YEAR.checkValidIntValue(fieldValues.remove(YEAR)); if (resolverStyle == ResolverStyle.LENIENT) { long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1); long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1); return LocalDate.of(y, 1, 1).plusMonths(months).plusDays(days); } int moy = MONTH_OF_YEAR.checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR)); int dom = DAY_OF_MONTH.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH)); if (resolverStyle == ResolverStyle.SMART) { // previous valid if (moy == 4 || moy == 6 || moy == 9 || moy == 11) { dom = Math.min(dom, 30); } else if (moy == 2) { dom = Math.min(dom, Month.FEBRUARY.length(Year.isLeap(y))); } } return LocalDate.of(y, moy, dom); }
@DataProvider(name="adjustInto") Object[][] data_adjustInto() { return new Object[][]{ {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 23, 5, 0, 0), null}, {LocalDateTime.of(2012, Month.MARCH, 4, 0, 0), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 0, 0), null}, {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), null}, {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), null}, {LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, null}, {LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, null}, {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZoneOffset.UTC), null}, {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, OFFSET_PONE), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null}, {LocalDateTime.of(2012, 3, 4, 23, 5), ZonedDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZONE_PARIS), ZonedDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZONE_PARIS), null}, {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class}, {LocalDateTime.of(2012, 3, 4, 23, 5), LocalTime.of(22, 3, 0), null, DateTimeException.class}, {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetTime.of(22, 3, 0, 0, ZoneOffset.UTC), null, DateTimeException.class}, {LocalDateTime.of(2012, 3, 4, 23, 5), null, null, NullPointerException.class}, }; }
@Test public void testCreateSelectContext() throws Exception { try (SqlAgent agent = config.agent()) { TestEntity test = new TestEntity(1, "name1", 20, LocalDate.of(1990, Month.APRIL, 1), Optional .of("memo1")); agent.insert(test); agent.commit(); EntityHandler<?> handler = config.getEntityHandler(); TableMetadata metadata = TableMetadata.createTableEntityMetadata(agent, MappingUtils.getTable(TestEntity.class)); SqlContext ctx = handler.createSelectContext(agent, metadata, null); try (ResultSet rs = agent.query(ctx)) { assertThat(rs.next(), is(true)); } } }
/** * 取得季度月的第一天 * * @param date 日期 * @return 返回一个当前季度月的数组 */ public static LocalDate[] getSeasonDate(LocalDate date) { LocalDate[] season = new LocalDate[3]; int nSeason = getSeason(date); int year = date.getYear(); // 第一季度 if (nSeason == FIRST_QUARTER) { season[0] = LocalDate.of(year, Month.JANUARY, 1); season[1] = LocalDate.of(year, Month.FEBRUARY, 1); season[2] = LocalDate.of(year, Month.MARCH, 1); // 第二季度 } else if (nSeason == SECOND_QUARTER) { season[0] = LocalDate.of(year, Month.APRIL, 1); season[1] = LocalDate.of(year, Month.MAY, 1); season[2] = LocalDate.of(year, Month.JUNE, 1); // 第三季度 } else if (nSeason ==THREE_QUARTER) { season[0] = LocalDate.of(year, Month.JULY, 1); season[1] = LocalDate.of(year, Month.AUGUST, 1); season[2] = LocalDate.of(year, Month.SEPTEMBER, 1); // 第四季度 } else if (nSeason == FOUR_QUARTER) { season[0] = LocalDate.of(year, Month.OCTOBER, 1); season[1] = LocalDate.of(year, Month.NOVEMBER, 1); season[2] = LocalDate.of(year, Month.DECEMBER, 1); } return season; }
@Test public void factory_ofInstant_allSecsInDay() { for (int i = 0; i < (24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_0100); assertEquals(test.getYear(), 1970); assertEquals(test.getMonth(), Month.JANUARY); 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); } }
@Test public void test_firstDayOfMonth_nonLeap() { for (Month month : Month.values()) { for (int i = 1; i <= month.length(false); i++) { LocalDate date = date(2007, month, i); LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfMonth().adjustInto(date); assertEquals(test.getYear(), 2007); assertEquals(test.getMonth(), month); assertEquals(test.getDayOfMonth(), 1); } } }
@Test public void testTemporalFormats() { LocalizationContext ctx = LocalizationContext.builder().build(); ctx.localize(Locale.ITALIAN); LocalDate date = LocalDate.of(1979, Month.MARCH, 9); LocalTime time = LocalTime.of(18, 30, 15); LocalDateTime dt = LocalDateTime.of(1979, Month.MARCH, 9, 18, 30, 15); assertEquals("09/03/79", ctx.format(date)); assertEquals("09/03/79", ctx.format(date, TemporalFormat.SHORT, null)); assertEquals("9-mar-1979", ctx.format(date, TemporalFormat.MEDIUM, null)); assertEquals("9 marzo 1979", ctx.format(date, TemporalFormat.LONG, null)); assertEquals("venerdì 9 marzo 1979", ctx.format(date, TemporalFormat.FULL, null)); assertEquals("18.30", ctx.format(time)); assertEquals("18.30.15", ctx.format(time, null, TemporalFormat.MEDIUM)); assertEquals("18.30.15", ctx.format(time, null, TemporalFormat.LONG)); assertEquals("18.30.15", ctx.format(time, null, TemporalFormat.FULL)); assertEquals("09/03/79 18.30", ctx.format(dt)); assertEquals("09/03/79 18.30", ctx.format(dt, TemporalFormat.SHORT, null)); assertEquals("9-mar-1979 18.30.15", ctx.format(dt, TemporalFormat.MEDIUM, TemporalFormat.MEDIUM)); assertEquals("9 marzo 1979 18.30.15", ctx.format(dt, TemporalFormat.LONG, TemporalFormat.MEDIUM)); assertEquals("9 marzo 1979 18.30.15", ctx.format(dt, TemporalFormat.LONG, TemporalFormat.LONG)); assertEquals("venerdì 9 marzo 1979 18.30.15", ctx.format(dt, TemporalFormat.FULL, TemporalFormat.MEDIUM)); ctx.localize(Localization.builder(Locale.ITALY).defaultDateTemporalFormat(TemporalFormat.MEDIUM).build()); assertEquals("9-mar-1979", ctx.format(date)); assertEquals("9-mar-1979", ctx.format(date, TemporalFormat.DEFAULT, null)); ctx.localize(Localization.builder(Locale.ITALY).defaultDateTemporalFormat(TemporalFormat.SHORT) .defaultTimeTemporalFormat(TemporalFormat.MEDIUM).build()); assertEquals("18.30.15", ctx.format(time)); }
@Test public void now_Clock_allSecsInDay_utc() { for (int i = 0; i < (2 * 24 * 60 * 60); i++) { Instant instant = Instant.ofEpochSecond(i); Clock clock = Clock.fixed(instant, ZoneOffset.UTC); LocalDate test = LocalDate.now(clock); assertEquals(test.getYear(), 1970); assertEquals(test.getMonth(), Month.JANUARY); assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2)); } }
public static TrafficUnit generateOneUnit(Month month, DayOfWeek dayOfWeek, int hour, String country, String city, String trafficLight){ double r0 = Math.random(); VehicleType vehicleType = r0<0.4?VehicleType.CAR:(r0>0.6?VehicleType.TRUCK: VehicleType.CAB_CREW); double r1 = Math.random(); double r2 = Math.random(); double r3 = Math.random(); return new TrafficModelImpl(vehicleType, gen(4,1), gen(3300,1000), gen(246,100), gen(4000,2000), (r1>0.5? RoadCondition.WET: RoadCondition.DRY), (r2>0.5? TireCondition.WORN: TireCondition.NEW), r1>0.5?(r3>0.5?63:50):63); }
@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); LocalDateTime test = LocalDateTime.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); } }
@Test public void test_firstDayOfNextYear_nonLeap() { for (Month month : Month.values()) { for (int i = 1; i <= month.length(false); i++) { LocalDate date = date(2007, month, i); LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextYear().adjustInto(date); assertEquals(test.getYear(), 2008); assertEquals(test.getMonth(), JANUARY); assertEquals(test.getDayOfMonth(), 1); } } }
@Test public void test_hashCode_floatingWeekBackwards() { ZoneOffsetTransitionRule a = ZoneOffsetTransitionRule.of( Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, OFFSET_0200, OFFSET_0200, OFFSET_0300); ZoneOffsetTransitionRule b = ZoneOffsetTransitionRule.of( Month.MARCH, -1, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, OFFSET_0200, OFFSET_0200, OFFSET_0300); assertEquals(a.hashCode(), b.hashCode()); }
@Test public void chronoSeriesTest1() { ChronoSeries chronoSeries = ChronoSeries.of( Instant.parse("2011-11-25T08:48:11Z"), Instant.parse("2012-11-30T09:23:16Z"), Instant.parse("2013-11-29T09:51:49Z"), Instant.parse("2014-11-28T08:43:00Z"), Instant.parse("2015-11-27T08:22:25Z") ); ISeq<ChronoAllele> alleleSeq = ISeq.of( new ChronoFrequency(ChronoUnit.YEARS, 0, 1, 1, Instant.now()), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.HOURS), 0, 8), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.HOURS), 0, 9), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.HOURS), 0, 10), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.DAYS), 0, DayOfWeek.FRIDAY.getValue()), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.MONTHS), 0, Month.NOVEMBER.getValue()), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.YEARS), 0, 2011), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.YEARS), 0, 2012), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.YEARS), 0, 2013), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.YEARS), 0, 2014), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.YEARS), 0, 2015) ); ISeq<ChronoGene> geneSeq = ISeq.of(alleleSeq.map(ChronoGene::new)); ChronoRange chronoRange = ChronoRange.getChronoRange(chronoSeries, geneSeq); int actualCount = chronoSeries.countEventsBetween(chronoRange); assertTrue(actualCount == 5); }
@Test public void test() throws Exception { try (SqlAgent agent = config.agent()) { agent.required(() -> { TransientAnnoTestEntity test1 = new TransientAnnoTestEntity(1, "name1", 20, LocalDate.of(1990, Month.APRIL, 1)); agent.insert(test1); TransientAnnoTestEntity data = agent.find(TransientAnnoTestEntity.class, 1).orElse(null); assertThat(data.name, is(nullValue())); assertThat(data.birthday, is(nullValue())); }); } }
private LocalDate previous(LocalDate date) { int newDayOfMonth = date.getDayOfMonth() - 1; if (newDayOfMonth > 0) { return date.withDayOfMonth(newDayOfMonth); } date = date.with(date.getMonth().minus(1)); if (date.getMonth() == Month.DECEMBER) { date = date.withYear(date.getYear() - 1); } return date.withDayOfMonth(date.getMonth().length(isIsoLeap(date.getYear()))); }
@Test public void test_firstDayOfNextMonth_nonLeap() { for (Month month : Month.values()) { for (int i = 1; i <= month.length(false); i++) { LocalDate date = date(2007, month, i); LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextMonth().adjustInto(date); assertEquals(test.getYear(), month == DECEMBER ? 2008 : 2007); assertEquals(test.getMonth(), month.plus(1)); assertEquals(test.getDayOfMonth(), 1); } } }
@Test public void chronoFitnessCompareTest6() { ChronoSeries chronoSeries = ChronoSeries.of( Instant.parse("2011-11-04T08:48:11Z"), Instant.parse("2012-11-02T09:23:16Z"), Instant.parse("2013-11-01T09:51:49Z"), Instant.parse("2014-11-07T08:43:00Z"), Instant.parse("2015-11-06T08:22:25Z") ); //once a year ISeq<ChronoAllele> alleleSeq = ISeq.of( new ChronoFrequency(ChronoUnit.YEARS, 0, 1, 1, Instant.now()) ); ISeq<ChronoGene> geneSeq = ISeq.of(alleleSeq.map(ChronoGene::new)); Chronosome chronosome = new Chronosome(geneSeq, chronoSeries); Chronotype chronotype1 = new Chronotype(chronoSeries, ISeq.of(Collections.singleton(chronosome))); //once a year on November alleleSeq = ISeq.of( new ChronoFrequency(ChronoUnit.YEARS, 0, 1, 1, Instant.now()), new ChronoPattern(ChronoScaleUnit.asFactual(chronoSeries, ChronoUnit.MONTHS), 0, Month.NOVEMBER.getValue()) ); geneSeq = ISeq.of(alleleSeq.map(ChronoGene::new)); chronosome = new Chronosome(geneSeq, chronoSeries); Chronotype chronotype2 = new Chronotype(chronoSeries, ISeq.of(Collections.singleton(chronosome))); ChronoFitness chronoFitness1 = ChronoFitness.evaluate(chronotype1); ChronoFitness chronoFitness2 = ChronoFitness.evaluate(chronotype2); assertTrue(chronoFitness1.isValidFitness()); assertTrue(chronoFitness2.isValidFitness()); assertTrue(chronoFitness2.score().compareTo(chronoFitness1.score()) > 0); }
/** * Sorts compressed logs into a new folder * * @param folder The log * @param logFolder The logFolder name * @return The result */ public static boolean sortCompressedLogs(File folder, String logFolder) { File[] files = folder.listFiles(); if(files == null) return false; for(File file : files) { if(!file.getName().endsWith(".log.gz")) continue; String fileName = file.getName(); String[] firstSplit = fileName.split("\\.log\\.gz", 2); fileName = firstSplit[0]; String[] secondSplit = fileName.split("-"); int count = Integer.parseInt(secondSplit[secondSplit.length - 1]); String fileNameWithoutCount = fileName.replace("-" + count, ""); String[] spl = fileName.split("-"); if(spl.length < 3) continue; // list the foldername (e.g. October, 2016) String folderName = ""; try { int monthId = Integer.parseInt(spl[1]); int year = Integer.parseInt(spl[2]); Month month = Month.of(monthId); folderName = StringUtil.upperFirstLetter(month.name().toLowerCase()) + ", " + year; } catch(Exception ex) { continue; } if(folderName.isEmpty()) continue; // create the folder File targetFolder = new File(logFolder + "/" + folderName); int newCount = IOUtil.getNextId(targetFolder, fileNameWithoutCount, "-", ".log.gz", 0); IOUtil.moveFiles(file, fileNameWithoutCount + "-" + newCount + ".log.gz", targetFolder); } return true; }
@Test public void test_toString_fixedDate() { ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of( Month.MARCH, 20, null, TIME_0100, false, TimeDefinition.STANDARD, OFFSET_0200, OFFSET_0200, OFFSET_0300); assertEquals(test.toString(), "TransitionRule[Gap +02:00 to +03:00, MARCH 20 at 01:00 STANDARD, standard offset +02:00]"); }
@Test public void getMeetingsForMonthOf() { FullMonth month = this.calendar.getMeetingsForYearMonth(2017, Month.JULY); Assert.assertEquals(6, month.getNumberOfMeetings()); System.out.println(month); }
@Test(dataProvider="sampleDates") public void test_get(int y, int m) { YearMonth a = YearMonth.of(y, m); assertEquals(a.getYear(), y); assertEquals(a.getMonth(), Month.of(m)); assertEquals(a.getMonthValue(), m); }
@Test public void test_factory_int_singleton() { for (int i = 1; i <= MAX_LENGTH; i++) { Month test = Month.of(i); assertEquals(test.getValue(), i); } }
@Test public void test_pattern_String() { DateTimeFormatter test = DateTimeFormatter.ofPattern("d MMM yyyy"); Locale fmtLocale = Locale.getDefault(Locale.Category.FORMAT); assertEquals(test.format(LocalDate.of(2012, 6, 30)), "30 " + Month.JUNE.getDisplayName(TextStyle.SHORT, fmtLocale) + " 2012"); assertEquals(test.getLocale(), fmtLocale, "Locale.Category.FORMAT"); }
@Test public void test_length_boolean_leapYear() { assertEquals(Month.JANUARY.length(true), 31); assertEquals(Month.FEBRUARY.length(true), 29); assertEquals(Month.MARCH.length(true), 31); assertEquals(Month.APRIL.length(true), 30); assertEquals(Month.MAY.length(true), 31); assertEquals(Month.JUNE.length(true), 30); assertEquals(Month.JULY.length(true), 31); assertEquals(Month.AUGUST.length(true), 31); assertEquals(Month.SEPTEMBER.length(true), 30); assertEquals(Month.OCTOBER.length(true), 31); assertEquals(Month.NOVEMBER.length(true), 30); assertEquals(Month.DECEMBER.length(true), 31); }