Java Code Examples for java.time.Month#values()

The following examples show how to use java.time.Month#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKTemporalAdjusters.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@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);
                }
            }
        }
    }
}
 
Example 2
Source File: TCKTemporalAdjusters.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 3
Source File: TCKTemporalAdjusters.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 4
Source File: TCKLocalDate.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 5
Source File: TCKTemporalAdjusters.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@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);
                }
            }
        }
    }
}
 
Example 6
Source File: TCKTemporalAdjusters.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@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);
                }
            }
        }
    }
}
 
Example 7
Source File: TCKTemporalAdjusters.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_lastDayOfMonth_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.lastDayOfMonth().adjustInto(date);
            assertEquals(test.getYear(), 2008);
            assertEquals(test.getMonth(), month);
            assertEquals(test.getDayOfMonth(), month.length(true));
        }
    }
}
 
Example 8
Source File: TCKTemporalAdjusters.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 9
Source File: TCKTemporalAdjusters.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_lastDayOfMonth_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.lastDayOfMonth().adjustInto(date);
            assertEquals(test.getYear(), 2008);
            assertEquals(test.getMonth(), month);
            assertEquals(test.getDayOfMonth(), month.length(true));
        }
    }
}
 
Example 10
Source File: TCKTemporalAdjusters.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 11
Source File: TCKTemporalAdjusters.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_lastDayOfMonth_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.lastDayOfMonth().adjustInto(date);
            assertEquals(test.getYear(), 2007);
            assertEquals(test.getMonth(), month);
            assertEquals(test.getDayOfMonth(), month.length(false));
        }
    }
}
 
Example 12
Source File: TCKTemporalAdjusters.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 13
Source File: TCKTemporalAdjusters.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@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);
                }
            }
        }
    }
}
 
Example 14
Source File: TCKTemporalAdjusters.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void test_lastDayOfMonth_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.lastDayOfMonth().adjustInto(date);
            assertEquals(test.getYear(), 2008);
            assertEquals(test.getMonth(), month);
            assertEquals(test.getDayOfMonth(), month.length(true));
        }
    }
}
 
Example 15
Source File: ExtraDateStrings.java    From LGoodDatePicker with MIT License 5 votes vote down vote up
/**
 * getStandaloneMonthNamesArray, This returns an array with the standalone version of all the
 * full month names.
 */
private static String[] getStandaloneMonthNamesArray(Locale locale, boolean capitalize,
        boolean shortVersion) {
    Month[] monthEnums = Month.values();
    ArrayList<String> monthNamesArrayList = new ArrayList<String>();
    for (Month monthEnum : monthEnums) {
        monthNamesArrayList.add(getStandaloneMonthName(monthEnum, locale, capitalize, shortVersion));
    }
    // Convert the arraylist to a string array, and return the array.
    String[] monthNames = monthNamesArrayList.toArray(new String[]{});
    return monthNames;
}
 
Example 16
Source File: TCKTemporalAdjusters.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 17
Source File: TCKLocalDateTime.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 18
Source File: TCKTemporalAdjusters.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@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);
        }
    }
}
 
Example 19
Source File: TCKTemporalAdjusters.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_lastDayOfMonth_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.lastDayOfMonth().adjustInto(date);
            assertEquals(test.getYear(), 2007);
            assertEquals(test.getMonth(), month);
            assertEquals(test.getDayOfMonth(), month.length(false));
        }
    }
}
 
Example 20
Source File: TCKTemporalAdjusters.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_lastDayOfMonth_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.lastDayOfMonth().adjustInto(date);
            assertEquals(test.getYear(), 2007);
            assertEquals(test.getMonth(), month);
            assertEquals(test.getDayOfMonth(), month.length(false));
        }
    }
}