Hi Pascal,
This is a little bit of a challenge, as the period model is setup to 
treat each field (hours/minutes/seconds etc) separately. This is because 
there is no guarantee that there are 60 seconds in a minute, or 60 
minutes in an hour.

The simplest way for you to achieve this is to re-resolve the period 
using the instant 1970-01-01.

Period period = new Period();
Period p1 = Period.seconds(40);
period = period.plus(p1);
Period p2 = Period.seconds(30);
period = period.plus(p2);

Duration dur = period.toDurationFrom(new Instant(0L));
period = new Period(new Instant(0L), dur);

This mechanism works so long as the period is not too large.

Stephen


Pascal Dimassimo wrote:
> Hi,
> 
> I have a question regarding the following code:
> -----------------------------------------------
> 
> // The desired format is hh:mm:ss
> PeriodFormatter pf = new PeriodFormatterBuilder()
>         .minimumPrintedDigits(2)
>         .printZeroIfSupported()
>         .appendHours()
>         .appendSeparator(":")
>         .appendMinutes()
>         .appendSeparator(":")
>         .appendSeconds()
>         .toFormatter();
> 
> MutablePeriod period = new MutablePeriod(0);
> 
> Period p1 = pf.parsePeriod("00:00:40");
> period.add(p1);
> 
> Period p2 = pf.parsePeriod("00:00:30");
> period.add(p2);
> 
> // This will print 00:00:70
> System.out.println(pf.print(period));
> 
> -----------------------------------------------
> 
> how can I have 00:01:10 instead of 00:00:70 ?
> 
> thanks!
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Joda-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
> 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to