本文整理汇总了Java中java.time.Month类的典型用法代码示例。如果您正苦于以下问题:Java Month类的具体用法?Java Month怎么用?Java Month使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Month类属于java.time包,在下文中一共展示了Month类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSetInParameter_mapperForLocalDate
import java.time.Month; //导入依赖的package包/类
@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));
}
}
}
示例2: test_next
import java.time.Month; //导入依赖的package包/类
@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);
}
}
}
}
}
示例3: demo1_speedModel
import java.time.Month; //导入依赖的package包/类
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));
}
示例4: testInsert
import java.time.Month; //导入依赖的package包/类
@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));
});
}
}
示例5: m5InstantOfNextFrameShouldReturnTheNextInstantThatsMinutesAreAMultipleOfFive
import java.time.Month; //导入依赖的package包/类
/**
* {@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));
}
示例6: m15InstantOfNextFrameShouldReturnTheNextInstantWhereTheMinutesAreAMultipleOf15
import java.time.Month; //导入依赖的package包/类
/**
* {@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));
}
示例7: test_toString_floatingWeekBackwards_last
import java.time.Month; //导入依赖的package包/类
@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]");
}
示例8: testUpdate1
import java.time.Month; //导入依赖的package包/类
@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"));
});
}
}
示例9: shouldReturnOneCustomerById
import java.time.Month; //导入依赖的package包/类
@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));
});
}
示例10: initTimeline
import java.time.Month; //导入依赖的package包/类
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
}
示例11: test2
import java.time.Month; //导入依赖的package包/类
@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()));
}
示例12: resolveYMD
import java.time.Month; //导入依赖的package包/类
@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);
}
示例13: data_adjustInto
import java.time.Month; //导入依赖的package包/类
@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},
};
}
示例14: testCreateSelectContext
import java.time.Month; //导入依赖的package包/类
@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));
}
}
}
示例15: getSeasonDate
import java.time.Month; //导入依赖的package包/类
/**
* 取得季度月的第一天
*
* @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;
}