Java Code Examples for java.time.YearMonth#now()

The following examples show how to use java.time.YearMonth#now() . 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: TCKYearMonth.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now() {
    YearMonth expected = YearMonth.now(Clock.systemDefaultZone());
    YearMonth test = YearMonth.now();
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = YearMonth.now(Clock.systemDefaultZone());
        test = YearMonth.now();
    }
    assertEquals(test, expected);
}
 
Example 2
Source File: TCKYearMonth.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock() {
    Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
    Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
    YearMonth test = YearMonth.now(clock);
    assertEquals(test.getYear(), 2010);
    assertEquals(test.getMonth(), Month.DECEMBER);
}
 
Example 3
Source File: TCKYearMonth.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock() {
    Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
    Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
    YearMonth test = YearMonth.now(clock);
    assertEquals(test.getYear(), 2010);
    assertEquals(test.getMonth(), Month.DECEMBER);
}
 
Example 4
Source File: TCKYearMonth.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now() {
    YearMonth expected = YearMonth.now(Clock.systemDefaultZone());
    YearMonth test = YearMonth.now();
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = YearMonth.now(Clock.systemDefaultZone());
        test = YearMonth.now();
    }
    assertEquals(test, expected);
}
 
Example 5
Source File: TCKYearMonth.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    YearMonth expected = YearMonth.now(Clock.system(zone));
    YearMonth test = YearMonth.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = YearMonth.now(Clock.system(zone));
        test = YearMonth.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 6
Source File: TCKYearMonth.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    YearMonth expected = YearMonth.now(Clock.system(zone));
    YearMonth test = YearMonth.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = YearMonth.now(Clock.system(zone));
        test = YearMonth.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 7
Source File: TCKYearMonth.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now() {
    YearMonth expected = YearMonth.now(Clock.systemDefaultZone());
    YearMonth test = YearMonth.now();
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = YearMonth.now(Clock.systemDefaultZone());
        test = YearMonth.now();
    }
    assertEquals(test, expected);
}
 
Example 8
Source File: TCKYearMonth.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_Clock() {
    Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
    Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
    YearMonth test = YearMonth.now(clock);
    assertEquals(test.getYear(), 2010);
    assertEquals(test.getMonth(), Month.DECEMBER);
}
 
Example 9
Source File: TCKYearMonth.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void now_ZoneId() {
    ZoneId zone = ZoneId.of("UTC+01:02:03");
    YearMonth expected = YearMonth.now(Clock.system(zone));
    YearMonth test = YearMonth.now(zone);
    for (int i = 0; i < 100; i++) {
        if (expected.equals(test)) {
            return;
        }
        expected = YearMonth.now(Clock.system(zone));
        test = YearMonth.now(zone);
    }
    assertEquals(test, expected);
}
 
Example 10
Source File: TCKYearMonth.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_ZoneId_nullZoneId() {
    YearMonth.now((ZoneId) null);
}
 
Example 11
Source File: CalendarUtil.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
void initDates() {
  Calendar calendarSunday = getCalendarInstance();
  Calendar calendarMonday = getCalendarInstance();
  Calendar calendarTuesday = getCalendarInstance();
  Calendar calendarWednesday = getCalendarInstance();
  Calendar calendarThursday = getCalendarInstance();
  Calendar calendarFriday = getCalendarInstance();
  Calendar calendarSaturday = getCalendarInstance();

  calendarSunday.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
  calendarMonday.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
  calendarTuesday.set(Calendar.DAY_OF_WEEK, Calendar.TUESDAY);
  calendarWednesday.set(Calendar.DAY_OF_WEEK, Calendar.WEDNESDAY);
  calendarThursday.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
  calendarFriday.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
  calendarSaturday.set(Calendar.DAY_OF_WEEK, Calendar.SATURDAY);

  dateSunday = calendarSunday.getTime();
  dateMonday = calendarMonday.getTime();
  dateTuesday = calendarTuesday.getTime();
  dateWednesday = calendarWednesday.getTime();
  dateThursday = calendarThursday.getTime();
  dateFriday = calendarFriday.getTime();
  dateSaturday = calendarSaturday.getTime();

  // Previously Calendar was used, but it had problems getting the month right
  // when the current day of the month was 31.
  YearMonth currentYearMonth = YearMonth.now(clock);
  YearMonth jan = currentYearMonth.with(Month.JANUARY);
  YearMonth feb = currentYearMonth.with(Month.FEBRUARY);
  YearMonth mar = currentYearMonth.with(Month.MARCH);
  YearMonth apr = currentYearMonth.with(Month.APRIL);
  YearMonth may = currentYearMonth.with(Month.MAY);
  YearMonth jun = currentYearMonth.with(Month.JUNE);
  YearMonth jul = currentYearMonth.with(Month.JULY);
  YearMonth aug = currentYearMonth.with(Month.AUGUST);
  YearMonth sep = currentYearMonth.with(Month.SEPTEMBER);
  YearMonth oct = currentYearMonth.with(Month.OCTOBER);
  YearMonth nov = currentYearMonth.with(Month.NOVEMBER);
  YearMonth dec = currentYearMonth.with(Month.DECEMBER);

  dateJanuary = getDateFromYearMonth(jan);
  dateFebruary = getDateFromYearMonth(feb);
  dateMarch = getDateFromYearMonth(mar);
  dateApril = getDateFromYearMonth(apr);
  dateMay = getDateFromYearMonth(may);
  dateJune = getDateFromYearMonth(jun);
  dateJuly = getDateFromYearMonth(jul);
  dateAugust = getDateFromYearMonth(aug);
  dateSeptember = getDateFromYearMonth(sep);
  dateOctober = getDateFromYearMonth(oct);
  dateNovember = getDateFromYearMonth(nov);
  dateDecember = getDateFromYearMonth(dec);

}
 
Example 12
Source File: TCKYearMonth.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
    YearMonth.now((Clock) null);
}
 
Example 13
Source File: TCKYearMonth.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
    YearMonth.now((Clock) null);
}
 
Example 14
Source File: PDTFactory.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnegative
public static YearMonth getCurrentYearMonth ()
{
  return YearMonth.now (_getZoneId ());
}
 
Example 15
Source File: TCKYearMonth.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_ZoneId_nullZoneId() {
    YearMonth.now((ZoneId) null);
}
 
Example 16
Source File: TCKYearMonth.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_ZoneId_nullZoneId() {
    YearMonth.now((ZoneId) null);
}
 
Example 17
Source File: TCKYearMonth.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=NullPointerException.class)
public void now_ZoneId_nullZoneId() {
    YearMonth.now((ZoneId) null);
}
 
Example 18
Source File: TCKYearMonth.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
    YearMonth.now((Clock) null);
}
 
Example 19
Source File: TCKYearMonth.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=NullPointerException.class)
public void now_Clock_nullClock() {
    YearMonth.now((Clock) null);
}
 
Example 20
Source File: CronExpressionTest.java    From cron with Apache License 2.0 4 votes vote down vote up
@Test
public void shall_give_last_day_of_month() throws Exception {
    CronExpression.DayOfMonthField field = new DayOfMonthField("L");
    YearMonth now = YearMonth.now();
    assertTrue("L matches to the last day of month", field.matches(LocalDate.of(now.getYear(), now.getMonthValue(), now.lengthOfMonth())));
}