本文整理汇总了Java中java.time.YearMonth类的典型用法代码示例。如果您正苦于以下问题:Java YearMonth类的具体用法?Java YearMonth怎么用?Java YearMonth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
YearMonth类属于java.time包,在下文中一共展示了YearMonth类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateData
import java.time.YearMonth; //导入依赖的package包/类
private Map<String, Object> generateData() {
Map<String, Object> data = new HashMap<>();
data.put("stage", 0);
Map<Integer, Object> stageLabels = new HashMap<>();
stageLabels.put(0, "TODO");
stageLabels.put(1, "ALLOW");
data.put("stageLabels", stageLabels);
List<Map<String, Object>> rows = new ArrayList<>();
data.put("rows", rows);
Map<String, Object> row;
for (int i = 0; i < 10; i++) {
row = new HashMap<>();
rows.add(row);
row.put("yearMonth", YearMonth.now());
row.put("dateTime", LocalDateTime.now());
row.put("str", "test");
row.put("money", new BigDecimal("100.01").add(new BigDecimal((float) i / 1000)).setScale(2, BigDecimal.ROUND_HALF_UP));
row.put("stage", i % 2);
if (i % 2 == 0) {
row.put("remark", "remark" + (i + 1));
}
}
return data;
}
示例2: getBill
import java.time.YearMonth; //导入依赖的package包/类
@GET
@Path("/{month}")
@ApiOperation(value = "Facturation d'un mois", response = Bill.class)
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid input"),
@ApiResponse(code = 404, message = "Billing not found")}
)
public Response getBill(@PathParam("month") final String month, @Context Request request) {
Optional<Bill> bill = repository.get(YearMonth.parse(month));
if (!bill.isPresent()) {
return Response.status(Response.Status.NOT_FOUND).build();
}
EntityTag etag = new EntityTag(Integer.toString(bill.get().hashCode()));
Response.ResponseBuilder preconditions = request == null ? null : request.evaluatePreconditions(etag);
// cached resource did change -> serve updated content
if (preconditions == null) {
preconditions = Response.ok(bill.get()).tag(etag);
}
return preconditions.build();
}
示例3: doTest_comparisons_YearMonth
import java.time.YearMonth; //导入依赖的package包/类
void doTest_comparisons_YearMonth(YearMonth... localDates) {
for (int i = 0; i < localDates.length; i++) {
YearMonth a = localDates[i];
for (int j = 0; j < localDates.length; j++) {
YearMonth b = localDates[j];
if (i < j) {
assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
assertEquals(a.isBefore(b), true, a + " <=> " + b);
assertEquals(a.isAfter(b), false, a + " <=> " + b);
assertEquals(a.equals(b), false, a + " <=> " + b);
} else if (i > j) {
assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
assertEquals(a.isBefore(b), false, a + " <=> " + b);
assertEquals(a.isAfter(b), true, a + " <=> " + b);
assertEquals(a.equals(b), false, a + " <=> " + b);
} else {
assertEquals(a.compareTo(b), 0, a + " <=> " + b);
assertEquals(a.isBefore(b), false, a + " <=> " + b);
assertEquals(a.isAfter(b), false, a + " <=> " + b);
assertEquals(a.equals(b), true, a + " <=> " + b);
}
}
}
}
示例4: data_atEndOfMonth
import java.time.YearMonth; //导入依赖的package包/类
@DataProvider(name="atEndOfMonth")
Object[][] data_atEndOfMonth() {
return new Object[][] {
{YearMonth.of(2008, 1), LocalDate.of(2008, 1, 31)},
{YearMonth.of(2008, 2), LocalDate.of(2008, 2, 29)},
{YearMonth.of(2008, 3), LocalDate.of(2008, 3, 31)},
{YearMonth.of(2008, 4), LocalDate.of(2008, 4, 30)},
{YearMonth.of(2008, 5), LocalDate.of(2008, 5, 31)},
{YearMonth.of(2008, 6), LocalDate.of(2008, 6, 30)},
{YearMonth.of(2008, 12), LocalDate.of(2008, 12, 31)},
{YearMonth.of(2009, 1), LocalDate.of(2009, 1, 31)},
{YearMonth.of(2009, 2), LocalDate.of(2009, 2, 28)},
{YearMonth.of(2009, 3), LocalDate.of(2009, 3, 31)},
{YearMonth.of(2009, 4), LocalDate.of(2009, 4, 30)},
{YearMonth.of(2009, 5), LocalDate.of(2009, 5, 31)},
{YearMonth.of(2009, 6), LocalDate.of(2009, 6, 30)},
{YearMonth.of(2009, 12), LocalDate.of(2009, 12, 31)},
};
}
示例5: data_minus_long_TemporalUnit
import java.time.YearMonth; //导入依赖的package包/类
@DataProvider(name="minus_long_TemporalUnit")
Object[][] data_minus_long_TemporalUnit() {
return new Object[][] {
{YearMonth.of(1, 10), 1, ChronoUnit.YEARS, YearMonth.of(0, 10), null},
{YearMonth.of(1, 10), 12, ChronoUnit.YEARS, YearMonth.of(-11, 10), null},
{YearMonth.of(1, 10), 0, ChronoUnit.YEARS, YearMonth.of(1, 10), null},
{YearMonth.of(999999999, 12), 0, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), 0, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 1), 999999999, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
{YearMonth.of(0, 12), -999999999, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 10), 1, ChronoUnit.MONTHS, YearMonth.of(1, 9), null},
{YearMonth.of(1, 10), 12, ChronoUnit.MONTHS, YearMonth.of(0, 10), null},
{YearMonth.of(1, 10), 0, ChronoUnit.MONTHS, YearMonth.of(1, 10), null},
{YearMonth.of(999999999, 12), 0, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},
{YearMonth.of(-999999999, 1), 0, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
{YearMonth.of(-999999999, 2), 1, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
{YearMonth.of(999999999, 11), -1, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},
{YearMonth.of(1, 10), 1, ChronoUnit.ERAS, YearMonth.of(0, 10), null},
{YearMonth.of(5, 10), 1, ChronoUnit.CENTURIES, YearMonth.of(-95, 10), null},
{YearMonth.of(5, 10), 1, ChronoUnit.DECADES, YearMonth.of(-5, 10), null},
{YearMonth.of(999999999, 12), -1, ChronoUnit.MONTHS, null, DateTimeException.class},
{YearMonth.of(-999999999, 1), 1, ChronoUnit.MONTHS, null, DateTimeException.class},
{YearMonth.of(1, 1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
{YearMonth.of(1, 1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
};
}
示例6: createEntries
import java.time.YearMonth; //导入依赖的package包/类
private void createEntries(YearMonth month) {
for (int i = 1; i < 28; i++) {
LocalDate date = month.atDay(i);
for (int j = 0; j < (int) (Math.random() * 7); j++) {
Entry<?> entry = new Entry<>();
entry.changeStartDate(date);
entry.changeEndDate(date);
entry.setTitle("Entry " + (j + 1));
int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(24 - hour,
(int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime.plusHours(durationInHours);
entry.changeStartTime(startTime);
entry.changeEndTime(endTime);
if (Math.random() < .3) {
entry.setFullDay(true);
}
entry.setCalendar(this);
}
}
}
示例7: HelloCalendar
import java.time.YearMonth; //导入依赖的package包/类
public HelloCalendar() {
for (Month month : Month.values()) {
YearMonth yearMonth = YearMonth.of(LocalDate.now().getYear(), month);
for (int i = 1; i < 28; i++) {
LocalDate date = yearMonth.atDay(i);
for (int j = 0; j < (int) (Math.random() * 7); j++) {
Entry<?> entry = new Entry<>();
entry.changeStartDate(date);
entry.changeEndDate(date);
entry.setTitle("Entry " + (j + 1));
int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(24 - hour,
(int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime
.plusHours(durationInHours);
entry.changeStartTime(startTime);
entry.changeEndTime(endTime);
if (Math.random() < .3) {
entry.setFullDay(true);
}
entry.setCalendar(this);
}
}
}
}
示例8: HelloCalendar
import java.time.YearMonth; //导入依赖的package包/类
public HelloCalendar() {
for (int i = 1; i < 28; i++) {
LocalDate date = YearMonth.now().atDay(i);
for (int j = 0; j < (int) (Math.random() * 7); j++) {
Entry<?> entry = new Entry<>();
entry.changeStartDate(date);
entry.changeEndDate(date.plusDays((int) (Math.random() * 4)));
entry.setTitle("Entry " + (j + 1));
int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(24 - hour,
(int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime.plusHours(durationInHours);
entry.changeStartTime(startTime);
entry.changeEndTime(endTime);
if (Math.random() < .3) {
entry.setFullDay(true);
}
entry.setCalendar(this);
}
}
}
示例9: test_hashCode_unique
import java.time.YearMonth; //导入依赖的package包/类
@Test
public void test_hashCode_unique() {
Set<Integer> uniques = new HashSet<Integer>(201 * 12);
for (int i = 1900; i <= 2100; i++) {
for (int j = 1; j <= 12; j++) {
assertTrue(uniques.add(YearMonth.of(i, j).hashCode()));
}
}
}
示例10: test_serialization_format
import java.time.YearMonth; //导入依赖的package包/类
@Test
public void test_serialization_format() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (DataOutputStream dos = new DataOutputStream(baos) ) {
dos.writeByte(12); // java.time.temporal.Ser.YEAR_MONTH_TYPE
dos.writeInt(2012);
dos.writeByte(9);
}
byte[] bytes = baos.toByteArray();
assertSerializedBySer(YearMonth.of(2012, 9), bytes);
}
示例11: test_plus_long_TemporalUnit
import java.time.YearMonth; //导入依赖的package包/类
@Test(dataProvider="plus_long_TemporalUnit")
public void test_plus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class<?> expectedEx) {
if (expectedEx == null) {
assertEquals(base.plus(amount, unit), expectedYearMonth);
} else {
try {
YearMonth result = base.plus(amount, unit);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
}
示例12: test_isValidDay_int_febLeap
import java.time.YearMonth; //导入依赖的package包/类
@Test
public void test_isValidDay_int_febLeap() {
YearMonth test = YearMonth.of(2008, 2);
assertEquals(test.isValidDay(1), true);
assertEquals(test.isValidDay(29), true);
assertEquals(test.isValidDay(-1), false);
assertEquals(test.isValidDay(0), false);
assertEquals(test.isValidDay(30), false);
assertEquals(test.isValidDay(32), false);
}
示例13: test_minus_long_TemporalUnit
import java.time.YearMonth; //导入依赖的package包/类
@Test(dataProvider="minus_long_TemporalUnit")
public void test_minus_long_TemporalUnit(YearMonth base, long amount, TemporalUnit unit, YearMonth expectedYearMonth, Class<?> expectedEx) {
if (expectedEx == null) {
assertEquals(base.minus(amount, unit), expectedYearMonth);
} else {
try {
YearMonth result = base.minus(amount, unit);
fail();
} catch (Exception ex) {
assertTrue(expectedEx.isInstance(ex));
}
}
}
示例14: test_parse_errorMessage
import java.time.YearMonth; //导入依赖的package包/类
@Test
public void test_parse_errorMessage() throws Exception {
assertGoodErrorDate(DayOfWeek::from, "DayOfWeek");
assertGoodErrorDate(Month::from, "Month");
assertGoodErrorDate(YearMonth::from, "YearMonth");
assertGoodErrorDate(MonthDay::from, "MonthDay");
assertGoodErrorDate(LocalDate::from, "LocalDate");
assertGoodErrorDate(LocalTime::from, "LocalTime");
assertGoodErrorDate(LocalDateTime::from, "LocalDateTime");
assertGoodErrorDate(OffsetTime::from, "OffsetTime");
assertGoodErrorDate(OffsetDateTime::from, "OffsetDateTime");
assertGoodErrorDate(ZonedDateTime::from, "ZonedDateTime");
assertGoodErrorDate(Instant::from, "Instant");
assertGoodErrorDate(ZoneOffset::from, "ZoneOffset");
assertGoodErrorDate(ZoneId::from, "ZoneId");
assertGoodErrorDate(ThaiBuddhistChronology.INSTANCE::date, "");
assertGoodErrorTime(DayOfWeek::from, "DayOfWeek");
assertGoodErrorTime(Month::from, "Month");
assertGoodErrorTime(Year::from, "Year");
assertGoodErrorTime(YearMonth::from, "YearMonth");
assertGoodErrorTime(MonthDay::from, "MonthDay");
assertGoodErrorTime(LocalDate::from, "LocalDate");
assertGoodErrorTime(LocalTime::from, "LocalTime");
assertGoodErrorTime(LocalDateTime::from, "LocalDateTime");
assertGoodErrorTime(OffsetTime::from, "OffsetTime");
assertGoodErrorTime(OffsetDateTime::from, "OffsetDateTime");
assertGoodErrorTime(ZonedDateTime::from, "ZonedDateTime");
assertGoodErrorTime(Instant::from, "Instant");
assertGoodErrorTime(ZoneOffset::from, "ZoneOffset");
assertGoodErrorTime(ZoneId::from, "ZoneId");
assertGoodErrorTime(ThaiBuddhistChronology.INSTANCE::date, "");
}
示例15: test_padOptional
import java.time.YearMonth; //导入依赖的package包/类
@Test
public void test_padOptional() throws Exception {
builder.appendValue(MONTH_OF_YEAR).appendLiteral(':')
.padNext(5).optionalStart().appendValue(DAY_OF_MONTH).optionalEnd()
.appendLiteral(':').appendValue(YEAR);
assertEquals(builder.toFormatter().format(LocalDate.of(2013, 2, 1)), "2: 1:2013");
assertEquals(builder.toFormatter().format(YearMonth.of(2013, 2)), "2: :2013");
}