< prev index next >

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

Print this page
rev 47480 : [mq]: 8176841


 269      * <p>
 270      * This field allows the week of the week-based-year value to be queried and set.
 271      * <p>
 272      * This unit is an immutable and thread-safe singleton.
 273      */
 274     private final transient TemporalField weekOfWeekBasedYear = ComputedDayOfField.ofWeekOfWeekBasedYearField(this);
 275     /**
 276      * The field that represents the week-based-year.
 277      * <p>
 278      * This field allows the week-based-year value to be queried and set.
 279      * <p>
 280      * This unit is an immutable and thread-safe singleton.
 281      */
 282     private final transient TemporalField weekBasedYear = ComputedDayOfField.ofWeekBasedYearField(this);
 283 
 284     //-----------------------------------------------------------------------
 285     /**
 286      * Obtains an instance of {@code WeekFields} appropriate for a locale.
 287      * <p>
 288      * This will look up appropriate values from the provider of localization data.





 289      *
 290      * @param locale  the locale to use, not null
 291      * @return the week-definition, not null
 292      */
 293     public static WeekFields of(Locale locale) {
 294         Objects.requireNonNull(locale, "locale");
 295         locale = new Locale(locale.getLanguage(), locale.getCountry());  // elminate variants
 296 
 297         int calDow = CalendarDataUtility.retrieveFirstDayOfWeek(locale);
 298         DayOfWeek dow = DayOfWeek.SUNDAY.plus(calDow - 1);
 299         int minDays = CalendarDataUtility.retrieveMinimalDaysInFirstWeek(locale);
 300         return WeekFields.of(dow, minDays);
 301     }
 302 
 303     /**
 304      * Obtains an instance of {@code WeekFields} from the first day-of-week and minimal days.
 305      * <p>
 306      * The first day-of-week defines the ISO {@code DayOfWeek} that is day 1 of the week.
 307      * The minimal number of days in the first week defines how many days must be present
 308      * in a month or year, starting from the first day-of-week, before the week is counted
 309      * as the first week. A value of 1 will count the first day of the month or year as part
 310      * of the first week, whereas a value of 7 will require the whole seven days to be in
 311      * the new month or year.
 312      * <p>
 313      * WeekFields instances are singletons; for each unique combination
 314      * of {@code firstDayOfWeek} and {@code minimalDaysInFirstWeek}
 315      * the same instance will be returned.




 269      * <p>
 270      * This field allows the week of the week-based-year value to be queried and set.
 271      * <p>
 272      * This unit is an immutable and thread-safe singleton.
 273      */
 274     private final transient TemporalField weekOfWeekBasedYear = ComputedDayOfField.ofWeekOfWeekBasedYearField(this);
 275     /**
 276      * The field that represents the week-based-year.
 277      * <p>
 278      * This field allows the week-based-year value to be queried and set.
 279      * <p>
 280      * This unit is an immutable and thread-safe singleton.
 281      */
 282     private final transient TemporalField weekBasedYear = ComputedDayOfField.ofWeekBasedYearField(this);
 283 
 284     //-----------------------------------------------------------------------
 285     /**
 286      * Obtains an instance of {@code WeekFields} appropriate for a locale.
 287      * <p>
 288      * This will look up appropriate values from the provider of localization data.
 289      * If the locale contains "fw" (First day of week) and/or "rg"
 290      * (Region Override) <a href="../../util/Locale.html#def_locale_extension">
 291      * Unicode extensions</a>, returned instance will reflect the values specified with
 292      * those extensions. If both "fw" and "rg" are specified, the value from
 293      * "fw" extension supersedes the implicit one from "rg" extension.
 294      *
 295      * @param locale  the locale to use, not null
 296      * @return the week-definition, not null
 297      */
 298     public static WeekFields of(Locale locale) {
 299         Objects.requireNonNull(locale, "locale");

 300 
 301         int calDow = CalendarDataUtility.retrieveFirstDayOfWeek(locale);
 302         DayOfWeek dow = DayOfWeek.SUNDAY.plus(calDow - 1);
 303         int minDays = CalendarDataUtility.retrieveMinimalDaysInFirstWeek(locale);
 304         return WeekFields.of(dow, minDays);
 305     }
 306 
 307     /**
 308      * Obtains an instance of {@code WeekFields} from the first day-of-week and minimal days.
 309      * <p>
 310      * The first day-of-week defines the ISO {@code DayOfWeek} that is day 1 of the week.
 311      * The minimal number of days in the first week defines how many days must be present
 312      * in a month or year, starting from the first day-of-week, before the week is counted
 313      * as the first week. A value of 1 will count the first day of the month or year as part
 314      * of the first week, whereas a value of 7 will require the whole seven days to be in
 315      * the new month or year.
 316      * <p>
 317      * WeekFields instances are singletons; for each unique combination
 318      * of {@code firstDayOfWeek} and {@code minimalDaysInFirstWeek}
 319      * the same instance will be returned.


< prev index next >