Re: [Joda-interest] how to calculate weeks between 2 dates ?

 Re: [Joda-interest] how to calculate weeks between 2 dates ? From: Stephen Colebourne - 2009-03-07 16:51:01 ```I'd suggest writing a few test cases and then tweaking the logic. To calclate the numberr of fortnights you'll still need plusDays(1) first. Stephen adwin grails wrote: > Thank you Stephen, > > for Fortnightly calculations, should I add plusDays(1) to endDate ? > because If between 1/03/2009 - 21/03/2009 I got 2.5 fortnightly, while > it should be 2 (set scale to round_down ?) > > regards > adwin > > > On Sat, Mar 7, 2009 at 10:48 PM, Stephen Colebourne > wrote: >> adwin grails wrote: >>> at the moment i am using Weeks.weeksBetwee(start,end) but it seems >>> produce result not same with what I need. >>> >>> for example : >>> import org.joda.time.DateTime; >>> import org.joda.time.* ; >>> >>> def x = new DateTime().withDate(2009,03,01); >>> def y = new DateTime().withDate(2009,03,21); >>> >>> def z = Days.daysBetween(x,y).getDays(); // produce 20 days >>> def w = Weeks.weeksBetween(x,y).getWeeks(); // produce 2 weeks --> >>> while it should be 3 weeks. >> The calculation is exclusive of the end date. Simply add one day to the >> end date to make it inclusive >> >> def w = Weeks.weeksBetween(x,y.plusDays(1)).getWeeks(); >> >>> also how to calculate, for example the payment date is on every >>> tuesday fortnightly (2 weeks) >>> for example on 3/03/2009 and then 17/03/2009 and then 31/03/2009 ... >>> if I have date range between 01.march.2009 - 31.july.2009 ... how to >>> calculate how many fortnightly payments occurs during that period ? >> Calculate the number of weeks, divide by 2 and add one. >> >> Stephen >> >> ------------------------------------------------------------------------------ >> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA >> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise >> -Strategies to boost innovation and cut costs with open source participation >> -Receive a \$600 discount off the registration fee with the source code: SFAD >> http://p.sf.net/sfu/XcvMzF8H >> _______________________________________________ >> Joda-interest mailing list >> Joda-interest@... >> https://lists.sourceforge.net/lists/listinfo/joda-interest >> > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a \$600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Joda-interest mailing list > Joda-interest@... > https://lists.sourceforge.net/lists/listinfo/joda-interest > ```

 [Joda-interest] how to calculate weeks between 2 dates ? From: adwin grails - 2009-03-07 15:38:42 ```Hi, I am new in Joda Time :) I have problem calculating how many weeks between 2 dates. at the moment i am using Weeks.weeksBetwee(start,end) but it seems produce result not same with what I need. for example : import org.joda.time.DateTime; import org.joda.time.* ; def x = new DateTime().withDate(2009,03,01); def y = new DateTime().withDate(2009,03,21); def z = Days.daysBetween(x,y).getDays(); // produce 20 days def w = Weeks.weeksBetween(x,y).getWeeks(); // produce 2 weeks --> while it should be 3 weeks. also how to calculate, for example the payment date is on every tuesday fortnightly (2 weeks) for example on 3/03/2009 and then 17/03/2009 and then 31/03/2009 ... if I have date range between 01.march.2009 - 31.july.2009 ... how to calculate how many fortnightly payments occurs during that period ? thank you for your answers !! regards adwin ```
 Re: [Joda-interest] how to calculate weeks between 2 dates ? From: Stephen Colebourne - 2009-03-07 15:48:30 ```adwin grails wrote: > at the moment i am using Weeks.weeksBetwee(start,end) but it seems > produce result not same with what I need. > > for example : > import org.joda.time.DateTime; > import org.joda.time.* ; > > def x = new DateTime().withDate(2009,03,01); > def y = new DateTime().withDate(2009,03,21); > > def z = Days.daysBetween(x,y).getDays(); // produce 20 days > def w = Weeks.weeksBetween(x,y).getWeeks(); // produce 2 weeks --> > while it should be 3 weeks. The calculation is exclusive of the end date. Simply add one day to the end date to make it inclusive def w = Weeks.weeksBetween(x,y.plusDays(1)).getWeeks(); > also how to calculate, for example the payment date is on every > tuesday fortnightly (2 weeks) > for example on 3/03/2009 and then 17/03/2009 and then 31/03/2009 ... > if I have date range between 01.march.2009 - 31.july.2009 ... how to > calculate how many fortnightly payments occurs during that period ? Calculate the number of weeks, divide by 2 and add one. Stephen ```
 Re: [Joda-interest] how to calculate weeks between 2 dates ? From: adwin grails - 2009-03-07 16:06:03 ```Thank you Stephen, for Fortnightly calculations, should I add plusDays(1) to endDate ? because If between 1/03/2009 - 21/03/2009 I got 2.5 fortnightly, while it should be 2 (set scale to round_down ?) regards adwin On Sat, Mar 7, 2009 at 10:48 PM, Stephen Colebourne wrote: > adwin grails wrote: >> at the moment i am using Weeks.weeksBetwee(start,end)  but it seems >> produce result not same with what I need. >> >> for example : >> import org.joda.time.DateTime; >> import org.joda.time.* ; >> >> def x = new DateTime().withDate(2009,03,01); >> def y = new DateTime().withDate(2009,03,21); >> >> def z = Days.daysBetween(x,y).getDays();  // produce 20 days >> def w = Weeks.weeksBetween(x,y).getWeeks();  // produce 2 weeks --> >> while it should be 3 weeks. > > The calculation is exclusive of the end date. Simply add one day to the > end date to make it inclusive > > def w = Weeks.weeksBetween(x,y.plusDays(1)).getWeeks(); > >> also how to calculate, for example the payment date is on every >> tuesday fortnightly (2 weeks) >> for example on 3/03/2009 and then 17/03/2009 and then 31/03/2009 ... >> if I have date range between 01.march.2009 - 31.july.2009  ... how to >> calculate how many fortnightly payments occurs during that period ? > > Calculate the number of weeks, divide by 2 and add one. > > Stephen > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a \$600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Joda-interest mailing list > Joda-interest@... > https://lists.sourceforge.net/lists/listinfo/joda-interest > ```
 Re: [Joda-interest] how to calculate weeks between 2 dates ? From: Stephen Colebourne - 2009-03-07 16:51:01 ```I'd suggest writing a few test cases and then tweaking the logic. To calclate the numberr of fortnights you'll still need plusDays(1) first. Stephen adwin grails wrote: > Thank you Stephen, > > for Fortnightly calculations, should I add plusDays(1) to endDate ? > because If between 1/03/2009 - 21/03/2009 I got 2.5 fortnightly, while > it should be 2 (set scale to round_down ?) > > regards > adwin > > > On Sat, Mar 7, 2009 at 10:48 PM, Stephen Colebourne > wrote: >> adwin grails wrote: >>> at the moment i am using Weeks.weeksBetwee(start,end) but it seems >>> produce result not same with what I need. >>> >>> for example : >>> import org.joda.time.DateTime; >>> import org.joda.time.* ; >>> >>> def x = new DateTime().withDate(2009,03,01); >>> def y = new DateTime().withDate(2009,03,21); >>> >>> def z = Days.daysBetween(x,y).getDays(); // produce 20 days >>> def w = Weeks.weeksBetween(x,y).getWeeks(); // produce 2 weeks --> >>> while it should be 3 weeks. >> The calculation is exclusive of the end date. Simply add one day to the >> end date to make it inclusive >> >> def w = Weeks.weeksBetween(x,y.plusDays(1)).getWeeks(); >> >>> also how to calculate, for example the payment date is on every >>> tuesday fortnightly (2 weeks) >>> for example on 3/03/2009 and then 17/03/2009 and then 31/03/2009 ... >>> if I have date range between 01.march.2009 - 31.july.2009 ... how to >>> calculate how many fortnightly payments occurs during that period ? >> Calculate the number of weeks, divide by 2 and add one. >> >> Stephen >> >> ------------------------------------------------------------------------------ >> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA >> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise >> -Strategies to boost innovation and cut costs with open source participation >> -Receive a \$600 discount off the registration fee with the source code: SFAD >> http://p.sf.net/sfu/XcvMzF8H >> _______________________________________________ >> Joda-interest mailing list >> Joda-interest@... >> https://lists.sourceforge.net/lists/listinfo/joda-interest >> > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a \$600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Joda-interest mailing list > Joda-interest@... > https://lists.sourceforge.net/lists/listinfo/joda-interest > ```