Java Code Examples for java.time.LocalDate#getDayOfYear()

The following examples show how to use java.time.LocalDate#getDayOfYear() . 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 jdk8u_jdk 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 openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_next() {
    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.next(dow).adjustInto(date);

                assertSame(test.getDayOfWeek(), dow, date + " " + test);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff > 0 && dayDiff < 8);
                } else {
                    assertSame(month, Month.DECEMBER);
                    assertTrue(date.getDayOfMonth() > 24);
                    assertEquals(test.getYear(), 2008);
                    assertSame(test.getMonth(), Month.JANUARY);
                    assertTrue(test.getDayOfMonth() < 8);
                }
            }
        }
    }
}
 
Example 3
Source File: TCKTemporalAdjusters.java    From jdk8u60 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 4
Source File: TCKTemporalAdjusters.java    From openjdk-8 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 5
Source File: IsoFields.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static int getWeek(LocalDate date) {
    int dow0 = date.getDayOfWeek().ordinal();
    int doy0 = date.getDayOfYear() - 1;
    int doyThu0 = doy0 + (3 - dow0);  // adjust to mid-week Thursday (which is 3 indexed from zero)
    int alignedWeek = doyThu0 / 7;
    int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
    int firstMonDoy0 = firstThuDoy0 - 3;
    if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
    }
    if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
    }
    int week = ((doy0 - firstMonDoy0) / 7) + 1;
    if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
            week = 1;
        }
    }
    return week;
}
 
Example 6
Source File: TCKTemporalAdjusters.java    From j2objc with Apache License 2.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(date + " " + test, test.getDayOfWeek(), dow);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff + " " + test, dayDiff < 0 && dayDiff > -8);
                } else {
                    assertSame(month, Month.JANUARY);
                    assertTrue(date.getDayOfMonth() < 8);
                    assertEquals(test.getYear(), 2006);
                    assertSame(test.getMonth(), Month.DECEMBER);
                    assertTrue(test.getDayOfMonth() > 24);
                }
            }
        }
    }
}
 
Example 7
Source File: IsoFields.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static int getWeek(LocalDate date) {
    int dow0 = date.getDayOfWeek().ordinal();
    int doy0 = date.getDayOfYear() - 1;
    int doyThu0 = doy0 + (3 - dow0);  // adjust to mid-week Thursday (which is 3 indexed from zero)
    int alignedWeek = doyThu0 / 7;
    int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
    int firstMonDoy0 = firstThuDoy0 - 3;
    if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
    }
    if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
    }
    int week = ((doy0 - firstMonDoy0) / 7) + 1;
    if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
            week = 1;
        }
    }
    return week;
}
 
Example 8
Source File: IsoFields.java    From desugar_jdk_libs with GNU General Public License v2.0 6 votes vote down vote up
private static int getWeek(LocalDate date) {
    int dow0 = date.getDayOfWeek().ordinal();
    int doy0 = date.getDayOfYear() - 1;
    int doyThu0 = doy0 + (3 - dow0);  // adjust to mid-week Thursday (which is 3 indexed from zero)
    int alignedWeek = doyThu0 / 7;
    int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
    int firstMonDoy0 = firstThuDoy0 - 3;
    if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
    }
    if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
    }
    int week = ((doy0 - firstMonDoy0) / 7) + 1;
    if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
            week = 1;
        }
    }
    return week;
}
 
Example 9
Source File: IsoFields.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static int getWeek(LocalDate date) {
    int dow0 = date.getDayOfWeek().ordinal();
    int doy0 = date.getDayOfYear() - 1;
    int doyThu0 = doy0 + (3 - dow0);  // adjust to mid-week Thursday (which is 3 indexed from zero)
    int alignedWeek = doyThu0 / 7;
    int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
    int firstMonDoy0 = firstThuDoy0 - 3;
    if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
    }
    if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
    }
    int week = ((doy0 - firstMonDoy0) / 7) + 1;
    if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
            week = 1;
        }
    }
    return week;
}
 
Example 10
Source File: TCKTemporalAdjusters.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_next() {
    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.next(dow).adjustInto(date);

                assertSame(test.getDayOfWeek(), dow, date + " " + test);

                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff > 0 && dayDiff < 8);
                } else {
                    assertSame(month, Month.DECEMBER);
                    assertTrue(date.getDayOfMonth() > 24);
                    assertEquals(test.getYear(), 2008);
                    assertSame(test.getMonth(), Month.JANUARY);
                    assertTrue(test.getDayOfMonth() < 8);
                }
            }
        }
    }
}
 
Example 11
Source File: IsoFields.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static int getWeek(LocalDate date) {
    int dow0 = date.getDayOfWeek().ordinal();
    int doy0 = date.getDayOfYear() - 1;
    int doyThu0 = doy0 + (3 - dow0);  // adjust to mid-week Thursday (which is 3 indexed from zero)
    int alignedWeek = doyThu0 / 7;
    int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
    int firstMonDoy0 = firstThuDoy0 - 3;
    if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
    }
    if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
    }
    int week = ((doy0 - firstMonDoy0) / 7) + 1;
    if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
            week = 1;
        }
    }
    return week;
}
 
Example 12
Source File: IsoFields.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static int getWeek(LocalDate date) {
    int dow0 = date.getDayOfWeek().ordinal();
    int doy0 = date.getDayOfYear() - 1;
    int doyThu0 = doy0 + (3 - dow0);  // adjust to mid-week Thursday (which is 3 indexed from zero)
    int alignedWeek = doyThu0 / 7;
    int firstThuDoy0 = doyThu0 - (alignedWeek * 7);
    int firstMonDoy0 = firstThuDoy0 - 3;
    if (firstMonDoy0 < -3) {
        firstMonDoy0 += 7;
    }
    if (doy0 < firstMonDoy0) {
        return (int) getWeekRange(date.withDayOfYear(180).minusYears(1)).getMaximum();
    }
    int week = ((doy0 - firstMonDoy0) / 7) + 1;
    if (week == 53) {
        if ((firstMonDoy0 == -3 || (firstMonDoy0 == -2 && date.isLeapYear())) == false) {
            week = 1;
        }
    }
    return week;
}
 
Example 13
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 14
Source File: TCKTemporalAdjusters.java    From jdk8u-jdk 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 15
Source File: TCKTemporalAdjusters.java    From TencentKona-8 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 16
Source File: TCKTemporalAdjusters.java    From jdk8u60 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 17
Source File: TCKTemporalAdjusters.java    From openjdk-jdk9 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 18
Source File: DateUtils.java    From archivo with GNU General Public License v3.0 5 votes vote down vote up
public static String formatArchivedOnDate(LocalDate date) {
    if (date.getDayOfYear() == today) {
        return "today";
    } else if (date.getDayOfYear() == yesterday) {
        return "yesterday";
    } else if (date.getYear() == currentYear) {
        // Don't include the year for recordings from the current year
        return "on " + date.format(DATE_RECORDED_SHORT_DATE_FORMATTER);
    } else {
        return "on " + date.format(DATE_RECORDED_LONG_DATE_FORMATTER);
    }
}
 
Example 19
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 20
Source File: EngineVersionCheck.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
@VisibleForTesting
static String formatUpdateCheckDate(final LocalDate updateCheckDate) {
  return updateCheckDate.getYear() + ":" + updateCheckDate.getDayOfYear();
}