How to print negative Duration/Period values ?

classic Classic list List threaded Threaded
5 messages Options
fed
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to print negative Duration/Period values ?

fed
Hi,

i have a negative Duration that indicates some hours/minutes, i want
to print it in the form hours:minutes,  i use this way for example:

                DateTime start= new DateTime(2011, 1, 1, 15, 30 ,0 ,0);
               
                DateTime end = new DateTime(2011, 1, 1, 0, 0, 0 ,0);
               
                Duration duration = new Duration(start, end);
               
                PeriodFormatter formatter = new PeriodFormatterBuilder()
                        .minimumPrintedDigits(2).printZeroAlways().appendHours()
                        .appendSeparator(":").appendMinutes().toFormatter();
               
                System.out.println(formatter.print(duration.toPeriod()));

but in this case i get "-15:-30"  not "-15:30",   in the case that i
use as start  new DateTime(2011, 1, 1, 15, 0 ,0 ,0);   i get "-15:00"
and this is correct, no sign on the minutes.

What is the right way to print this negative value in terms of hours:minutes ?

Thanks for the help

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to print negative Duration/Period values ?

jodastephen
I haven't tried it, but I suspect that calling normalizedStandard() on
the period before printing will do what you want.
Stephen

On 1 September 2011 10:29, fed <[hidden email]> wrote:

> Hi,
>
> i have a negative Duration that indicates some hours/minutes, i want
> to print it in the form hours:minutes,  i use this way for example:
>
>                DateTime start= new DateTime(2011, 1, 1, 15, 30 ,0 ,0);
>
>                DateTime end = new DateTime(2011, 1, 1, 0, 0, 0 ,0);
>
>                Duration duration = new Duration(start, end);
>
>                PeriodFormatter formatter = new PeriodFormatterBuilder()
>                        .minimumPrintedDigits(2).printZeroAlways().appendHours()
>                        .appendSeparator(":").appendMinutes().toFormatter();
>
>                System.out.println(formatter.print(duration.toPeriod()));
>
> but in this case i get "-15:-30"  not "-15:30",   in the case that i
> use as start  new DateTime(2011, 1, 1, 15, 0 ,0 ,0);   i get "-15:00"
> and this is correct, no sign on the minutes.
>
> What is the right way to print this negative value in terms of hours:minutes ?
>
> Thanks for the help
>
> ------------------------------------------------------------------------------
> Special Offer -- Download ArcSight Logger for FREE!
> Finally, a world-class log management solution at an even better
> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
> download Logger. Secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsisghtdev2dev
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
fed
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to print negative Duration/Period values ?

fed
Hi Stephen,

i tried:

System.out.println(formatter.print(duration.toPeriod().normalizedStandard()));

but it's the same, i tried also with serveral PeriodType on
normalizedStandard() but same results.


On 1 September 2011 11:38, Stephen Colebourne <[hidden email]> wrote:

> I haven't tried it, but I suspect that calling normalizedStandard() on
> the period before printing will do what you want.
> Stephen
>
> On 1 September 2011 10:29, fed <[hidden email]> wrote:
>> Hi,
>>
>> i have a negative Duration that indicates some hours/minutes, i want
>> to print it in the form hours:minutes,  i use this way for example:
>>
>>                DateTime start= new DateTime(2011, 1, 1, 15, 30 ,0 ,0);
>>
>>                DateTime end = new DateTime(2011, 1, 1, 0, 0, 0 ,0);
>>
>>                Duration duration = new Duration(start, end);
>>
>>                PeriodFormatter formatter = new PeriodFormatterBuilder()
>>                        .minimumPrintedDigits(2).printZeroAlways().appendHours()
>>                        .appendSeparator(":").appendMinutes().toFormatter();
>>
>>                System.out.println(formatter.print(duration.toPeriod()));
>>
>> but in this case i get "-15:-30"  not "-15:30",   in the case that i
>> use as start  new DateTime(2011, 1, 1, 15, 0 ,0 ,0);   i get "-15:00"
>> and this is correct, no sign on the minutes.
>>
>> What is the right way to print this negative value in terms of hours:minutes ?
>>
>> Thanks for the help
>>
>> ------------------------------------------------------------------------------
>> Special Offer -- Download ArcSight Logger for FREE!
>> Finally, a world-class log management solution at an even better
>> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
>> download Logger. Secure your free ArcSight Logger TODAY!
>> http://p.sf.net/sfu/arcsisghtdev2dev
>> _______________________________________________
>> Joda-interest mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>
>
> ------------------------------------------------------------------------------
> Special Offer -- Download ArcSight Logger for FREE!
> Finally, a world-class log management solution at an even better
> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
> download Logger. Secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsisghtdev2dev
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to print negative Duration/Period values ?

jodastephen
I've taken a look, and I don't see anything that will help you (which
is a surprise to me). The period formatter was intended originally for
output like PT-15H-30M which would be correct.

Best you can do is to change the period (for formatting only) to have
a positive minutes.

period.withMinutes(Math.abs(period.getMinutes()))

Stephen


On 1 September 2011 11:02, fed <[hidden email]> wrote:

> Hi Stephen,
>
> i tried:
>
> System.out.println(formatter.print(duration.toPeriod().normalizedStandard()));
>
> but it's the same, i tried also with serveral PeriodType on
> normalizedStandard() but same results.
>
>
> On 1 September 2011 11:38, Stephen Colebourne <[hidden email]> wrote:
>> I haven't tried it, but I suspect that calling normalizedStandard() on
>> the period before printing will do what you want.
>> Stephen
>>
>> On 1 September 2011 10:29, fed <[hidden email]> wrote:
>>> Hi,
>>>
>>> i have a negative Duration that indicates some hours/minutes, i want
>>> to print it in the form hours:minutes,  i use this way for example:
>>>
>>>                DateTime start= new DateTime(2011, 1, 1, 15, 30 ,0 ,0);
>>>
>>>                DateTime end = new DateTime(2011, 1, 1, 0, 0, 0 ,0);
>>>
>>>                Duration duration = new Duration(start, end);
>>>
>>>                PeriodFormatter formatter = new PeriodFormatterBuilder()
>>>                        .minimumPrintedDigits(2).printZeroAlways().appendHours()
>>>                        .appendSeparator(":").appendMinutes().toFormatter();
>>>
>>>                System.out.println(formatter.print(duration.toPeriod()));
>>>
>>> but in this case i get "-15:-30"  not "-15:30",   in the case that i
>>> use as start  new DateTime(2011, 1, 1, 15, 0 ,0 ,0);   i get "-15:00"
>>> and this is correct, no sign on the minutes.
>>>
>>> What is the right way to print this negative value in terms of hours:minutes ?
>>>
>>> Thanks for the help
>>>
>>> ------------------------------------------------------------------------------
>>> Special Offer -- Download ArcSight Logger for FREE!
>>> Finally, a world-class log management solution at an even better
>>> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
>>> download Logger. Secure your free ArcSight Logger TODAY!
>>> http://p.sf.net/sfu/arcsisghtdev2dev
>>> _______________________________________________
>>> Joda-interest mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>
>>
>> ------------------------------------------------------------------------------
>> Special Offer -- Download ArcSight Logger for FREE!
>> Finally, a world-class log management solution at an even better
>> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
>> download Logger. Secure your free ArcSight Logger TODAY!
>> http://p.sf.net/sfu/arcsisghtdev2dev
>> _______________________________________________
>> Joda-interest mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>
>
> ------------------------------------------------------------------------------
> Special Offer -- Download ArcSight Logger for FREE!
> Finally, a world-class log management solution at an even better
> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
> download Logger. Secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsisghtdev2dev
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
fed
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to print negative Duration/Period values ?

fed
I saw that this works but only if the duration is more than 1 hour, so
i have the sign on the hours too, but in case of less that 1 hours the
original string is like  "00:-30"  and with positive minutes i get
"00:30"  instead of  "-00:30".

For now i find more simple to formatting the result string
adding/removing the "-" sign if necessary.


On 1 September 2011 12:26, Stephen Colebourne <[hidden email]> wrote:

> I've taken a look, and I don't see anything that will help you (which
> is a surprise to me). The period formatter was intended originally for
> output like PT-15H-30M which would be correct.
>
> Best you can do is to change the period (for formatting only) to have
> a positive minutes.
>
> period.withMinutes(Math.abs(period.getMinutes()))
>
> Stephen
>
>
> On 1 September 2011 11:02, fed <[hidden email]> wrote:
>> Hi Stephen,
>>
>> i tried:
>>
>> System.out.println(formatter.print(duration.toPeriod().normalizedStandard()));
>>
>> but it's the same, i tried also with serveral PeriodType on
>> normalizedStandard() but same results.
>>
>>
>> On 1 September 2011 11:38, Stephen Colebourne <[hidden email]> wrote:
>>> I haven't tried it, but I suspect that calling normalizedStandard() on
>>> the period before printing will do what you want.
>>> Stephen
>>>
>>> On 1 September 2011 10:29, fed <[hidden email]> wrote:
>>>> Hi,
>>>>
>>>> i have a negative Duration that indicates some hours/minutes, i want
>>>> to print it in the form hours:minutes,  i use this way for example:
>>>>
>>>>                DateTime start= new DateTime(2011, 1, 1, 15, 30 ,0 ,0);
>>>>
>>>>                DateTime end = new DateTime(2011, 1, 1, 0, 0, 0 ,0);
>>>>
>>>>                Duration duration = new Duration(start, end);
>>>>
>>>>                PeriodFormatter formatter = new PeriodFormatterBuilder()
>>>>                        .minimumPrintedDigits(2).printZeroAlways().appendHours()
>>>>                        .appendSeparator(":").appendMinutes().toFormatter();
>>>>
>>>>                System.out.println(formatter.print(duration.toPeriod()));
>>>>
>>>> but in this case i get "-15:-30"  not "-15:30",   in the case that i
>>>> use as start  new DateTime(2011, 1, 1, 15, 0 ,0 ,0);   i get "-15:00"
>>>> and this is correct, no sign on the minutes.
>>>>
>>>> What is the right way to print this negative value in terms of hours:minutes ?
>>>>
>>>> Thanks for the help
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Special Offer -- Download ArcSight Logger for FREE!
>>>> Finally, a world-class log management solution at an even better
>>>> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
>>>> download Logger. Secure your free ArcSight Logger TODAY!
>>>> http://p.sf.net/sfu/arcsisghtdev2dev
>>>> _______________________________________________
>>>> Joda-interest mailing list
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Special Offer -- Download ArcSight Logger for FREE!
>>> Finally, a world-class log management solution at an even better
>>> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
>>> download Logger. Secure your free ArcSight Logger TODAY!
>>> http://p.sf.net/sfu/arcsisghtdev2dev
>>> _______________________________________________
>>> Joda-interest mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>
>>
>> ------------------------------------------------------------------------------
>> Special Offer -- Download ArcSight Logger for FREE!
>> Finally, a world-class log management solution at an even better
>> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
>> download Logger. Secure your free ArcSight Logger TODAY!
>> http://p.sf.net/sfu/arcsisghtdev2dev
>> _______________________________________________
>> Joda-interest mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>
>
> ------------------------------------------------------------------------------
> Special Offer -- Download ArcSight Logger for FREE!
> Finally, a world-class log management solution at an even better
> price-free! And you'll get a free "Love Thy Logs" t-shirt when you
> download Logger. Secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsisghtdev2dev
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...