< prev index next >

src/java.base/share/classes/java/time/temporal/WeekFields.java

Print this page




 110  * {@linkplain ChronoField#DAY_OF_WEEK ISO day-of-week} which are based on the
 111  * {@linkplain ChronoField#EPOCH_DAY epoch-day} and the chronology.
 112  * The values may not be aligned with the {@linkplain ChronoField#YEAR_OF_ERA year-of-Era}
 113  * depending on the Chronology.
 114  * <p>A week is defined by:
 115  * <ul>
 116  * <li>The first day-of-week.
 117  * For example, the ISO-8601 standard considers Monday to be the first day-of-week.
 118  * <li>The minimal number of days in the first week.
 119  * For example, the ISO-8601 standard counts the first week as needing at least 4 days.
 120  * </ul>
 121  * Together these two values allow a year or month to be divided into weeks.
 122  *
 123  * <h3>Week of Month</h3>
 124  * One field is used: week-of-month.
 125  * The calculation ensures that weeks never overlap a month boundary.
 126  * The month is divided into periods where each period starts on the defined first day-of-week.
 127  * The earliest period is referred to as week 0 if it has less than the minimal number of days
 128  * and week 1 if it has at least the minimal number of days.
 129  *
 130  * <table cellpadding="0" cellspacing="3" border="0" style="text-align: left; width: 50%;">
 131  * <caption>Examples of WeekFields</caption>

 132  * <tr><th>Date</th><td>Day-of-week</td>
 133  *  <td>First day: Monday<br>Minimal days: 4</td><td>First day: Monday<br>Minimal days: 5</td></tr>


 134  * <tr><th>2008-12-31</th><td>Wednesday</td>
 135  *  <td>Week 5 of December 2008</td><td>Week 5 of December 2008</td></tr>
 136  * <tr><th>2009-01-01</th><td>Thursday</td>
 137  *  <td>Week 1 of January 2009</td><td>Week 0 of January 2009</td></tr>
 138  * <tr><th>2009-01-04</th><td>Sunday</td>
 139  *  <td>Week 1 of January 2009</td><td>Week 0 of January 2009</td></tr>
 140  * <tr><th>2009-01-05</th><td>Monday</td>
 141  *  <td>Week 2 of January 2009</td><td>Week 1 of January 2009</td></tr>

 142  * </table>
 143  *
 144  * <h3>Week of Year</h3>
 145  * One field is used: week-of-year.
 146  * The calculation ensures that weeks never overlap a year boundary.
 147  * The year is divided into periods where each period starts on the defined first day-of-week.
 148  * The earliest period is referred to as week 0 if it has less than the minimal number of days
 149  * and week 1 if it has at least the minimal number of days.
 150  *
 151  * <h3>Week Based Year</h3>
 152  * Two fields are used for week-based-year, one for the
 153  * {@link #weekOfWeekBasedYear() week-of-week-based-year} and one for
 154  * {@link #weekBasedYear() week-based-year}.  In a week-based-year, each week
 155  * belongs to only a single year.  Week 1 of a year is the first week that
 156  * starts on the first day-of-week and has at least the minimum number of days.
 157  * The first and last weeks of a year may contain days from the
 158  * previous calendar year or next calendar year respectively.
 159  *
 160  * <table cellpadding="0" cellspacing="3" border="0" style="text-align: left; width: 50%;">
 161  * <caption>Examples of WeekFields for week-based-year</caption>

 162  * <tr><th>Date</th><td>Day-of-week</td>
 163  *  <td>First day: Monday<br>Minimal days: 4</td><td>First day: Monday<br>Minimal days: 5</td></tr>


 164  * <tr><th>2008-12-31</th><td>Wednesday</td>
 165  *  <td>Week 1 of 2009</td><td>Week 53 of 2008</td></tr>
 166  * <tr><th>2009-01-01</th><td>Thursday</td>
 167  *  <td>Week 1 of 2009</td><td>Week 53 of 2008</td></tr>
 168  * <tr><th>2009-01-04</th><td>Sunday</td>
 169  *  <td>Week 1 of 2009</td><td>Week 53 of 2008</td></tr>
 170  * <tr><th>2009-01-05</th><td>Monday</td>
 171  *  <td>Week 2 of 2009</td><td>Week 1 of 2009</td></tr>

 172  * </table>
 173  *
 174  * @implSpec
 175  * This class is immutable and thread-safe.
 176  *
 177  * @since 1.8
 178  */
 179 public final class WeekFields implements Serializable {
 180     // implementation notes
 181     // querying week-of-month or week-of-year should return the week value bound within the month/year
 182     // however, setting the week value should be lenient (use plus/minus weeks)
 183     // allow week-of-month outer range [0 to 6]
 184     // allow week-of-year outer range [0 to 54]
 185     // this is because callers shouldn't be expected to know the details of validity
 186 
 187     /**
 188      * The cache of rules by firstDayOfWeek plus minimalDays.
 189      * Initialized first to be available for definition of ISO, etc.
 190      */
 191     private static final ConcurrentMap<String, WeekFields> CACHE = new ConcurrentHashMap<>(4, 0.75f, 2);




 110  * {@linkplain ChronoField#DAY_OF_WEEK ISO day-of-week} which are based on the
 111  * {@linkplain ChronoField#EPOCH_DAY epoch-day} and the chronology.
 112  * The values may not be aligned with the {@linkplain ChronoField#YEAR_OF_ERA year-of-Era}
 113  * depending on the Chronology.
 114  * <p>A week is defined by:
 115  * <ul>
 116  * <li>The first day-of-week.
 117  * For example, the ISO-8601 standard considers Monday to be the first day-of-week.
 118  * <li>The minimal number of days in the first week.
 119  * For example, the ISO-8601 standard counts the first week as needing at least 4 days.
 120  * </ul>
 121  * Together these two values allow a year or month to be divided into weeks.
 122  *
 123  * <h3>Week of Month</h3>
 124  * One field is used: week-of-month.
 125  * The calculation ensures that weeks never overlap a month boundary.
 126  * The month is divided into periods where each period starts on the defined first day-of-week.
 127  * The earliest period is referred to as week 0 if it has less than the minimal number of days
 128  * and week 1 if it has at least the minimal number of days.
 129  *
 130  * <table style="text-align: left">
 131  * <caption>Examples of WeekFields</caption>
 132  * <thead>
 133  * <tr><th>Date</th><td>Day-of-week</td>
 134  *  <td>First day: Monday<br>Minimal days: 4</td><td>First day: Monday<br>Minimal days: 5</td></tr>
 135  * </thead>
 136  * <tbody>
 137  * <tr><th>2008-12-31</th><td>Wednesday</td>
 138  *  <td>Week 5 of December 2008</td><td>Week 5 of December 2008</td></tr>
 139  * <tr><th>2009-01-01</th><td>Thursday</td>
 140  *  <td>Week 1 of January 2009</td><td>Week 0 of January 2009</td></tr>
 141  * <tr><th>2009-01-04</th><td>Sunday</td>
 142  *  <td>Week 1 of January 2009</td><td>Week 0 of January 2009</td></tr>
 143  * <tr><th>2009-01-05</th><td>Monday</td>
 144  *  <td>Week 2 of January 2009</td><td>Week 1 of January 2009</td></tr>
 145  * </tbody>
 146  * </table>
 147  *
 148  * <h3>Week of Year</h3>
 149  * One field is used: week-of-year.
 150  * The calculation ensures that weeks never overlap a year boundary.
 151  * The year is divided into periods where each period starts on the defined first day-of-week.
 152  * The earliest period is referred to as week 0 if it has less than the minimal number of days
 153  * and week 1 if it has at least the minimal number of days.
 154  *
 155  * <h3>Week Based Year</h3>
 156  * Two fields are used for week-based-year, one for the
 157  * {@link #weekOfWeekBasedYear() week-of-week-based-year} and one for
 158  * {@link #weekBasedYear() week-based-year}.  In a week-based-year, each week
 159  * belongs to only a single year.  Week 1 of a year is the first week that
 160  * starts on the first day-of-week and has at least the minimum number of days.
 161  * The first and last weeks of a year may contain days from the
 162  * previous calendar year or next calendar year respectively.
 163  *
 164  * <table style="text-align: left;">
 165  * <caption>Examples of WeekFields for week-based-year</caption>
 166  * <thead>
 167  * <tr><th>Date</th><td>Day-of-week</td>
 168  *  <td>First day: Monday<br>Minimal days: 4</td><td>First day: Monday<br>Minimal days: 5</td></tr>
 169  * </thead>
 170  * <tbody>
 171  * <tr><th>2008-12-31</th><td>Wednesday</td>
 172  *  <td>Week 1 of 2009</td><td>Week 53 of 2008</td></tr>
 173  * <tr><th>2009-01-01</th><td>Thursday</td>
 174  *  <td>Week 1 of 2009</td><td>Week 53 of 2008</td></tr>
 175  * <tr><th>2009-01-04</th><td>Sunday</td>
 176  *  <td>Week 1 of 2009</td><td>Week 53 of 2008</td></tr>
 177  * <tr><th>2009-01-05</th><td>Monday</td>
 178  *  <td>Week 2 of 2009</td><td>Week 1 of 2009</td></tr>
 179  * </tbody>
 180  * </table>
 181  *
 182  * @implSpec
 183  * This class is immutable and thread-safe.
 184  *
 185  * @since 1.8
 186  */
 187 public final class WeekFields implements Serializable {
 188     // implementation notes
 189     // querying week-of-month or week-of-year should return the week value bound within the month/year
 190     // however, setting the week value should be lenient (use plus/minus weeks)
 191     // allow week-of-month outer range [0 to 6]
 192     // allow week-of-year outer range [0 to 54]
 193     // this is because callers shouldn't be expected to know the details of validity
 194 
 195     /**
 196      * The cache of rules by firstDayOfWeek plus minimalDays.
 197      * Initialized first to be available for definition of ISO, etc.
 198      */
 199     private static final ConcurrentMap<String, WeekFields> CACHE = new ConcurrentHashMap<>(4, 0.75f, 2);


< prev index next >