Mark Volkmann wrote:
> On Dec 21, 2008, at 6:34 PM, Stephen Colebourne wrote:
> 
>> Joda-Time doesn't have anything to help with this particular  
>> calculation
>> (JSR-310 does).
> 
> I'm new to Joda-Time. Perhaps some of my assumptions were wrong. I  
> thought JSR-310 was all based on Joda-Time and assumed that anything  
> new in JSR-310 would be tested by adding it to Joda-Time. When you say  
> JSR-310 has it, do you mean that it's in the spec or that there is  
> different library I could download now that has it?

JSR-310 is inspired by Joda-Time, rather than a straight adoption of it. 
Thus, there are key differences in the APIs. JSR-310 isn't at the 
download and use stage yet.

> Here's the implementation I came up with. If it looks useful, feel  
> free to add it to Joda-Time under whatever name you think is best.
> 
>      /**
>       * Gets the nth given weekday of a given month.
>       * For example, to find the 4th Thursday of the month of November  
> in 2008,
>       * getNthWeekday(2008, 11, DateTimeConstants.THURSDAY, 4)
>       * @param year the year
>       * @param month the month
>       * @param weekday the day of the week (such as Thursday)
>       * @param n the number of that day within the month (such as the  
> 4th)
>       * @return the LocalDate
>       */
>      private static LocalDate getNthWeekday(
>          int year, int month, int weekday, int n) {
> 
>          // Get the 1st day of the month.
>          LocalDate ld = new LocalDate(year, month, 1);
> 
>          // Determine the number of days to advance to get to
>          // the first requested weekday of the month.
>          int firstWeekday = ld.getDayOfWeek();
>          int diff = (7 - firstWeekday + weekday) % 7;
> 
>          return ld.plusDays(diff).plusWeeks(n - 1);
>      }

I do remember having something like this on the Partial class at one 
point, but taking it out. I might see if it can go back at some point.

Stephen

------------------------------------------------------------------------------
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to