本文整理匯總了Java中java.time.Month.values方法的典型用法代碼示例。如果您正苦於以下問題:Java Month.values方法的具體用法?Java Month.values怎麽用?Java Month.values使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.time.Month
的用法示例。
在下文中一共展示了Month.values方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_previous
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_previous() {
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.previous(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow, date + " " + test);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test);
} else {
assertSame(month, Month.JANUARY);
assertTrue(date.getDayOfMonth() < 8);
assertEquals(test.getYear(), 2006);
assertSame(test.getMonth(), Month.DECEMBER);
assertTrue(test.getDayOfMonth() > 24);
}
}
}
}
}
示例2: test_appendTextMap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_appendTextMap() throws Exception {
Map<Long, String> map = new HashMap<Long, String>();
map.put(1L, "JNY");
map.put(2L, "FBY");
map.put(3L, "MCH");
map.put(4L, "APL");
map.put(5L, "MAY");
map.put(6L, "JUN");
map.put(7L, "JLY");
map.put(8L, "AGT");
map.put(9L, "SPT");
map.put(10L, "OBR");
map.put(11L, "NVR");
map.put(12L, "DBR");
builder.appendText(MONTH_OF_YEAR, map);
DateTimeFormatter f = builder.toFormatter();
LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0);
for (Month month : Month.values()) {
assertEquals(f.format(dt.with(month)), map.get((long) month.getValue()));
}
}
示例3: test_firstDayOfNextYear_nonLeap
import java.time.Month; //導入方法依賴的package包/類
@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);
}
}
}
示例4: HelloCalendar
import java.time.Month; //導入方法依賴的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);
}
}
}
}
示例5: YearView
import java.time.Month; //導入方法依賴的package包/類
/**
* Constructs a new year view.
*/
public YearView() {
getStyleClass().add(DEFAULT_STYLE_CLASS);
dateProperty().addListener(evt -> year.set(Year.from(getDate())));
for (Month month : Month.values()) {
YearMonthView view = new YearMonthView();
viewMap.put(month, view);
view.setShowYear(false);
}
}
示例6: test_previousOrCurrent
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_previousOrCurrent() {
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.previousOrSame(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff <= 0 && dayDiff > -7);
assertEquals(date.equals(test), date.getDayOfWeek() == dow);
} else {
assertFalse(date.getDayOfWeek() == dow);
assertSame(month, Month.JANUARY);
assertTrue(date.getDayOfMonth() < 7);
assertEquals(test.getYear(), 2006);
assertSame(test.getMonth(), Month.DECEMBER);
assertTrue(test.getDayOfMonth() > 25);
}
}
}
}
}
示例7: test_getDayOfWeek
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_getDayOfWeek() {
DayOfWeek dow = DayOfWeek.MONDAY;
for (Month month : Month.values()) {
int length = month.length(false);
for (int i = 1; i <= length; i++) {
LocalDateTime d = LocalDateTime.of(LocalDate.of(2007, month, i),
TEST_2007_07_15_12_30_40_987654321.toLocalTime());
assertSame(d.getDayOfWeek(), dow);
dow = dow.plus(1);
}
}
}
示例8: test_nextOrCurrent
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_nextOrCurrent() {
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.nextOrSame(dow).adjustInto(date);
assertSame(test.getDayOfWeek(), dow);
if (test.getYear() == 2007) {
int dayDiff = test.getDayOfYear() - date.getDayOfYear();
assertTrue(dayDiff < 8);
assertEquals(date.equals(test), date.getDayOfWeek() == dow);
} else {
assertFalse(date.getDayOfWeek() == dow);
assertSame(month, Month.DECEMBER);
assertTrue(date.getDayOfMonth() > 24);
assertEquals(test.getYear(), 2008);
assertSame(test.getMonth(), Month.JANUARY);
assertTrue(test.getDayOfMonth() < 8);
}
}
}
}
}
示例9: test_firstDayOfMonth_leap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_firstDayOfMonth_leap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfMonth().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), month);
assertEquals(test.getDayOfMonth(), 1);
}
}
}
示例10: test_getDayOfWeek
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_getDayOfWeek() {
DayOfWeek dow = DayOfWeek.MONDAY;
for (Month month : Month.values()) {
int length = month.length(false);
for (int i = 1; i <= length; i++) {
LocalDate d = LocalDate.of(2007, month, i);
assertSame(d.getDayOfWeek(), dow);
dow = dow.plus(1);
}
}
}
示例11: test_firstDayOfNextMonth_nonLeap
import java.time.Month; //導入方法依賴的package包/類
@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);
}
}
}
示例12: test_lastDayOfYear_leap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_lastDayOfYear_leap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.lastDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), Month.DECEMBER);
assertEquals(test.getDayOfMonth(), 31);
}
}
}
示例13: test_lastDayOfYear_nonLeap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_lastDayOfYear_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.lastDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2007);
assertEquals(test.getMonth(), Month.DECEMBER);
assertEquals(test.getDayOfMonth(), 31);
}
}
}
示例14: test_firstDayOfYear_leap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_firstDayOfYear_leap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfYear().adjustInto(date);
assertEquals(test.getYear(), 2008);
assertEquals(test.getMonth(), Month.JANUARY);
assertEquals(test.getDayOfMonth(), 1);
}
}
}
示例15: test_firstDayOfNextYear_leap
import java.time.Month; //導入方法依賴的package包/類
@Test
public void test_firstDayOfNextYear_leap() {
for (Month month : Month.values()) {
for (int i = 1; i <= month.length(true); i++) {
LocalDate date = date(2008, month, i);
LocalDate test = (LocalDate) TemporalAdjusters.firstDayOfNextYear().adjustInto(date);
assertEquals(test.getYear(), 2009);
assertEquals(test.getMonth(), JANUARY);
assertEquals(test.getDayOfMonth(), 1);
}
}
}