Search in sources :

Example 46 with Month

use of java.time.Month in project jdk8u_jdk by JetBrains.

the class TCKTemporalAdjusters method test_firstDayOfYear_nonLeap.

@Test
public void test_firstDayOfYear_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.firstDayOfYear().adjustInto(date);
            assertEquals(test.getYear(), 2007);
            assertEquals(test.getMonth(), Month.JANUARY);
            assertEquals(test.getDayOfMonth(), 1);
        }
    }
}
Also used : Month(java.time.Month) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 47 with Month

use of java.time.Month in project jdk8u_jdk by JetBrains.

the class TCKMonth method test_factory_int_singleton.

//-----------------------------------------------------------------------
@Test
public void test_factory_int_singleton() {
    for (int i = 1; i <= MAX_LENGTH; i++) {
        Month test = Month.of(i);
        assertEquals(test.getValue(), i);
    }
}
Also used : Month(java.time.Month) Test(org.testng.annotations.Test)

Example 48 with Month

use of java.time.Month in project jdk8u_jdk by JetBrains.

the class TCKDateTimeTextPrinting method test_appendTextMap.

//-----------------------------------------------------------------------
@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()));
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Month(java.time.Month) HashMap(java.util.HashMap) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 49 with Month

use of java.time.Month in project uhgroupings by uhawaii-system-its-ti-iam.

the class YearHolidayHolderTest method getYear.

@Test
public void getYear() {
    holder = new YearHolidayHolder() {

        @Override
        protected Integer currentYear() {
            return 2016;
        }
    };
    assertTrue(holder.isEmpty());
    assertThat(holder.currentYear(), equalTo(2016));
    // Weird.
    assertThat(holder.getYear(), equalTo(0));
    List<Holiday> holidays = new ArrayList<>();
    for (int year = 2000; year <= 2017; year++) {
        Date date = Dates.toDate(Dates.firstDateOfYear(year));
        holidays.add(new Holiday(date, date));
    }
    holder = new YearHolidayHolder(holidays) {

        @Override
        protected Integer currentYear() {
            return 2016;
        }
    };
    assertFalse(holder.isEmpty());
    assertThat(holder.currentYear(), equalTo(2016));
    assertThat(holder.getYear(), equalTo(2016));
    Set<Integer> years = holder.getYears();
    assertThat(years.size(), equalTo(18));
    // The year will be the current year if
    // the years range spans accross it.
    assertThat(holder.getYear(), equalTo(2016));
    holidays = new ArrayList<>();
    for (int year = 2000; year <= 2014; year++) {
        Date date = Dates.toDate(Dates.firstDateOfYear(year));
        holidays.add(new Holiday(date, date));
    }
    holder = new YearHolidayHolder(holidays) {

        @Override
        protected Integer currentYear() {
            return 2016;
        }
    };
    assertFalse(holder.isEmpty());
    assertThat(holder.currentYear(), equalTo(2016));
    assertThat(holder.getYear(), equalTo(2014));
    // The year will be the highest year if the
    // current year is outside the range of years.
    assertThat(holder.getYear(), equalTo(2014));
    holder.setYear(2013);
    assertThat(holder.getYear(), equalTo(2013));
    holidays = new ArrayList<>();
    for (int year = 2014; year <= 2015; year++) {
        for (Month month : Month.values()) {
            LocalDate localDate = Dates.newLocalDate(year, month, 1);
            Date date = Dates.toDate(localDate);
            holidays.add(new Holiday(date, date));
        }
    }
    holder = new YearHolidayHolder(holidays) {

        @Override
        protected Integer currentYear() {
            return 2016;
        }
    };
    assertThat(holder.getYear(), equalTo(2015));
}
Also used : Month(java.time.Month) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 50 with Month

use of java.time.Month in project uhgroupings by uhawaii-system-its-ti-iam.

the class YearHolidayHolderTest method getHolidays.

@Test
public void getHolidays() {
    List<Holiday> holidays = holder.getHolidays(2016);
    assertThat(holidays.size(), equalTo(0));
    for (int day = 1; day <= 31; day++) {
        LocalDate localDate = Dates.newLocalDate(2016, Month.JANUARY, day);
        Date date = Dates.toDate(localDate);
        holidays.add(new Holiday(date, date));
    }
    holder = new YearHolidayHolder(holidays);
    holidays = holder.getHolidays(2016);
    assertThat(holidays.size(), equalTo(31));
    holidays = new ArrayList<>();
    for (Month month : Month.values()) {
        LocalDate localDate = Dates.firstDateOfMonth(month, 2016);
        Date date = Dates.toDate(localDate);
        holidays.add(new Holiday(date, date));
    }
    holder = new YearHolidayHolder(holidays);
    holidays = holder.getHolidays(2016);
    assertThat(holidays.size(), equalTo(12));
}
Also used : Month(java.time.Month) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Aggregations

Month (java.time.Month)68 LocalDate (java.time.LocalDate)40 Test (org.junit.Test)30 Test (org.testng.annotations.Test)20 DayOfWeek (java.time.DayOfWeek)17 LocalDateTime (java.time.LocalDateTime)8 LocalTime (java.time.LocalTime)5 ZoneOffset (java.time.ZoneOffset)5 HashMap (java.util.HashMap)5 DateTimeFormatter (java.time.format.DateTimeFormatter)4 YearMonth (java.time.YearMonth)3 Date (java.util.Date)3 List (java.util.List)3 ArrayList (java.util.ArrayList)2 DateTimeRule (android.icu.util.DateTimeRule)1 UseLocalDateTime (com.baeldung.datetime.UseLocalDateTime)1 EnchantmentEventListener (com.lilithsthrone.controller.eventListeners.EnchantmentEventListener)1 InventorySelectedItemEventListener (com.lilithsthrone.controller.eventListeners.InventorySelectedItemEventListener)1 InventoryTooltipEventListener (com.lilithsthrone.controller.eventListeners.InventoryTooltipEventListener)1 SetContentEventListener (com.lilithsthrone.controller.eventListeners.SetContentEventListener)1