How do I get the maximum number of weeks for a particular year with Joda-Time?
org.threeten.extra.YearWeek.of( 2018 , 1 ).is53WeekYear()
…or…
org.threeten.extra.YearWeek.of( 2018 , 1 ).lengthOfYear()
The Joda-Time project is now in maintenance mode, with the team advising migration to the java.time classes.
What is your definition of week? Does week # 1 contain January 1st? Or does week # 1 contain a particular day-of-week such as Sunday? Is week # 1 the first week to contain only days of the new year? Some other definition?
If your definition agrees with the ISO 8601 standard, that would mean week # 1 contains the first Thursday of the calendar year and Monday starts each week. So there are either 52 or 53 weeks in the year. And the last few or first few days of the calendar may land in the previous/next week-based year.
YearWeek
classFor standard weeks, add the ThreeTen-Extra library to your project. These classes further the functionality of the java.time classes built into Java 8 and later.
Get a week from your desired week-based year number.
YearWeek yw = YearWeek.of( 2018 , 1 ) ;
Perhaps you want the current year-week.
LocalDate ld = LocalDate.now( ZoneId.of( "America/Montreal" ) ) ;
YearWeek yw = YearWeek.from( ld ) ;
Get the number of weeks in that year, either 52 or 53.
int weeksCount = yw.lengthOfYear() ;
Or simply ask if that year has 53 weeks.
boolean has53 = yw.is53WeekYear() ;
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.