This should also work with YearMonthDay, and yes you can divide using
the days. (It was late!)

Stephen

On 08/11/06, Richard HALLIER <[EMAIL PROTECTED]> wrote:
> Thank you Stephen for your solution.
> Does the cvs/svn snapshot support your example ? Is it stable enough and
> when the next release is planned ? In this case, I will download the latest
> snapshot.
>
> Moreover, I still reference dates with YearMonthDay, is LocalDate more
> relevant ?
> At last, is it necessary to convert days in seconds to operate the division
> ?
> Thank you for your support.
> Richard
>
> > -----Message d'origine-----
> > De : [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] De la
> > part de Stephen Colebourne
> > Envoyé : mardi 7 novembre 2006 22:06
> > À : Discussion of the Joda project
> > Objet : Re: [Joda-interest] Need advice - Fractional Periods
> >
> > Richard HALLIER wrote:
> > > My customer asks me for calculating the number of months between 2
> > > dates with the following pattern (actually an example):
> > >
> > > start date = 17 january 2006
> > > end date = 28 april 2006
> > >
> > > The expected result is :
> > >   (31-17+1)/31   (31 days in january)
> > > + 2              (february and march)
> > > + (28/30)        (30 days in april)
> > > = 3.42
> >
> > That feels like an unusual calculation design, although I'd
> > welcome anyone else's comments on the merits of the algorithm.
> >
> > Joda-Time, does not really have any support for this at
> > present. So, you will need to treat the three parts (first
> > month, in between months, last
> > month) separately.
> >
> > The new Joda-Time 1.4 will contain classes named Days, Hours,
> > Minutes and Seconds. These may be useful here:
> >
> > LocalDate start = new LocalDate(2006, 1, 17); LocalDate
> > endOfMonth = start.dayOfMonth().withMaximumValue();
> >
> > Days days = Days.daysBetween(firstOfMonth, start); days =
> > days.plus(1);  // needed to to count days inclusively Seconds
> > secs = days.toStandardSeconds();
> >
> > Days daysInMonth = Days.days(start.dayOfMonth().getMaximumValue());
> > Seconds secondsInMonth = daysInMonth.toStandardSeconds();
> >
> > double fractionInMonth = secs.getSeconds() /
> > secondsInMonth.getSeconds();
> >
> > Although this algorithm could be repeated for each month, it
> > will be more efficient to only use it on those months which
> > are fractional.
> >
> >
> > I guess the question for Joda-Time is whether support for decimal
> > calculations like this is needed. For example, the Days class has a
> > dividedBy(int) method which returns another Days and uses int
> > division.
> > Maybe we should have a dividedBy(Days) that returns a double or a
> > BigDecimal?
> >
> > Stephen
> >
> > --------------------------------------------------------------
> > -----------
> > Using Tomcat but need to do more? Need to support web
> > services, security?
> > Get stuff done quickly with pre-integrated technology to make
> > your job easier
> > Download IBM WebSphere Application Server v.1.0.1 based on
> > Apache Geronimo
> > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&;
> > dat=121642
> > _______________________________________________
> > Joda-interest mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/joda-interest
> >
>
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Joda-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to