surprising return value from Period.getDays()

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

surprising return value from Period.getDays()

Lowell Kirsh
I'm new to joda an am seeing surprising behavior. I have created a Period from 2 DateTimes, one which is 15 days ago and one which is now. Looking at their toString() values, they look like they have been constructed properly. However, Period(then, now).getDays() returns 1. Am I doing something wrong?

code:
    @Test
    public void testJodaTime() {
        DateTime then = new DateTime(System.currentTimeMillis() - 15L * 24L * 60L * 60L * 1000L); // 15 days ago
        DateTime now = new DateTime();
        Period period = new Period(then, now);
        System.out.println(then);
        System.out.println(now);
        System.out.println(period.getDays());
    }


output:

2011-08-06T20:23:16.307-07:00
2011-08-21T20:23:16.344-07:00
1

Thanks!
Lowell

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
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: surprising return value from Period.getDays()

Yohan Yudanara
I think that's because 15 days is: 2 weeks 1 day.
So getDays() will return 1, and getWeeks will return 2.

CMIIW...

On Mon, Aug 22, 2011 at 10:28 AM, Lowell Kirsh <[hidden email]> wrote:
I'm new to joda an am seeing surprising behavior. I have created a Period from 2 DateTimes, one which is 15 days ago and one which is now. Looking at their toString() values, they look like they have been constructed properly. However, Period(then, now).getDays() returns 1. Am I doing something wrong?

code:
    @Test
    public void testJodaTime() {
        DateTime then = new DateTime(System.currentTimeMillis() - 15L * 24L * 60L * 60L * 1000L); // 15 days ago
        DateTime now = new DateTime();
        Period period = new Period(then, now);
        System.out.println(then);
        System.out.println(now);
        System.out.println(period.getDays());
    }


output:

2011-08-06T20:23:16.307-07:00
2011-08-21T20:23:16.344-07:00
1

Thanks!
Lowell

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest



------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
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: surprising return value from Period.getDays()

Lowell Kirsh
Ah, that makes sense. Is there a way to get the number I'm looking for? That is, 15 in this case?

On Sun, Aug 21, 2011 at 8:50 PM, Yohan Yudanara <[hidden email]> wrote:
I think that's because 15 days is: 2 weeks 1 day.
So getDays() will return 1, and getWeeks will return 2.

CMIIW...

On Mon, Aug 22, 2011 at 10:28 AM, Lowell Kirsh <[hidden email]> wrote:
I'm new to joda an am seeing surprising behavior. I have created a Period from 2 DateTimes, one which is 15 days ago and one which is now. Looking at their toString() values, they look like they have been constructed properly. However, Period(then, now).getDays() returns 1. Am I doing something wrong?

code:
    @Test
    public void testJodaTime() {
        DateTime then = new DateTime(System.currentTimeMillis() - 15L * 24L * 60L * 60L * 1000L); // 15 days ago
        DateTime now = new DateTime();
        Period period = new Period(then, now);
        System.out.println(then);
        System.out.println(now);
        System.out.println(period.getDays());
    }


output:

2011-08-06T20:23:16.307-07:00
2011-08-21T20:23:16.344-07:00
1

Thanks!
Lowell

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest



------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest




--
http://lowellkirsh.com


------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
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: surprising return value from Period.getDays()

Yohan Yudanara
hmm.. I also looking for an answer. :)
Hopefully someone on this list can answer that question.

On Mon, Aug 22, 2011 at 10:56 AM, Lowell Kirsh <[hidden email]> wrote:
Ah, that makes sense. Is there a way to get the number I'm looking for? That is, 15 in this case?


On Sun, Aug 21, 2011 at 8:50 PM, Yohan Yudanara <[hidden email]> wrote:
I think that's because 15 days is: 2 weeks 1 day.
So getDays() will return 1, and getWeeks will return 2.

CMIIW...

On Mon, Aug 22, 2011 at 10:28 AM, Lowell Kirsh <[hidden email]> wrote:
I'm new to joda an am seeing surprising behavior. I have created a Period from 2 DateTimes, one which is 15 days ago and one which is now. Looking at their toString() values, they look like they have been constructed properly. However, Period(then, now).getDays() returns 1. Am I doing something wrong?

code:
    @Test
    public void testJodaTime() {
        DateTime then = new DateTime(System.currentTimeMillis() - 15L * 24L * 60L * 60L * 1000L); // 15 days ago
        DateTime now = new DateTime();
        Period period = new Period(then, now);
        System.out.println(then);
        System.out.println(now);
        System.out.println(period.getDays());
    }


output:

2011-08-06T20:23:16.307-07:00
2011-08-21T20:23:16.344-07:00
1

Thanks!
Lowell

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest



------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest




--
http://lowellkirsh.com


------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest



------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
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: surprising return value from Period.getDays()

Yohan Yudanara
I've found it.

You can use period.toStandardDays().getDays();

On Mon, Aug 22, 2011 at 11:01 AM, Yohan Yudanara <[hidden email]> wrote:
hmm.. I also looking for an answer. :)
Hopefully someone on this list can answer that question.


On Mon, Aug 22, 2011 at 10:56 AM, Lowell Kirsh <[hidden email]> wrote:
Ah, that makes sense. Is there a way to get the number I'm looking for? That is, 15 in this case?


On Sun, Aug 21, 2011 at 8:50 PM, Yohan Yudanara <[hidden email]> wrote:
I think that's because 15 days is: 2 weeks 1 day.
So getDays() will return 1, and getWeeks will return 2.

CMIIW...

On Mon, Aug 22, 2011 at 10:28 AM, Lowell Kirsh <[hidden email]> wrote:
I'm new to joda an am seeing surprising behavior. I have created a Period from 2 DateTimes, one which is 15 days ago and one which is now. Looking at their toString() values, they look like they have been constructed properly. However, Period(then, now).getDays() returns 1. Am I doing something wrong?

code:
    @Test
    public void testJodaTime() {
        DateTime then = new DateTime(System.currentTimeMillis() - 15L * 24L * 60L * 60L * 1000L); // 15 days ago
        DateTime now = new DateTime();
        Period period = new Period(then, now);
        System.out.println(then);
        System.out.println(now);
        System.out.println(period.getDays());
    }


output:

2011-08-06T20:23:16.307-07:00
2011-08-21T20:23:16.344-07:00
1

Thanks!
Lowell

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest



------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest




--
http://lowellkirsh.com


------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest




------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
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: surprising return value from Period.getDays()

Lowell Kirsh
Thanks!



On Aug 21, 2011, at 9:07 PM, Yohan Yudanara <[hidden email]> wrote:

I've found it.

You can use period.toStandardDays().getDays();

On Mon, Aug 22, 2011 at 11:01 AM, Yohan Yudanara <[hidden email]> wrote:
hmm.. I also looking for an answer. :)
Hopefully someone on this list can answer that question.


On Mon, Aug 22, 2011 at 10:56 AM, Lowell Kirsh <[hidden email]> wrote:
Ah, that makes sense. Is there a way to get the number I'm looking for? That is, 15 in this case?


On Sun, Aug 21, 2011 at 8:50 PM, Yohan Yudanara <[hidden email]> wrote:
I think that's because 15 days is: 2 weeks 1 day.
So getDays() will return 1, and getWeeks will return 2.

CMIIW...

On Mon, Aug 22, 2011 at 10:28 AM, Lowell Kirsh <[hidden email]> wrote:
I'm new to joda an am seeing surprising behavior. I have created a Period from 2 DateTimes, one which is 15 days ago and one which is now. Looking at their toString() values, they look like they have been constructed properly. However, Period(then, now).getDays() returns 1. Am I doing something wrong?

code:
    @Test
    public void testJodaTime() {
        DateTime then = new DateTime(System.currentTimeMillis() - 15L * 24L * 60L * 60L * 1000L); // 15 days ago
        DateTime now = new DateTime();
        Period period = new Period(then, now);
        System.out.println(then);
        System.out.println(now);
        System.out.println(period.getDays());
    }


output:

2011-08-06T20:23:16.307-07:00
2011-08-21T20:23:16.344-07:00
1

Thanks!
Lowell

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest



------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest




--
http://lowellkirsh.com


------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest



------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev

_______________________________________________
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: surprising return value from Period.getDays()

jodastephen
In reply to this post by Yohan Yudanara
When you construct it, pass in the PeriodType parameter.
Stephen

On 22 August 2011 05:01, Yohan Yudanara <[hidden email]> wrote:

> hmm.. I also looking for an answer. :)
> Hopefully someone on this list can answer that question.
>
> On Mon, Aug 22, 2011 at 10:56 AM, Lowell Kirsh <[hidden email]> wrote:
>>
>> Ah, that makes sense. Is there a way to get the number I'm looking for?
>> That is, 15 in this case?
>>
>> On Sun, Aug 21, 2011 at 8:50 PM, Yohan Yudanara <[hidden email]>
>> wrote:
>>>
>>> I think that's because 15 days is: 2 weeks 1 day.
>>> So getDays() will return 1, and getWeeks will return 2.
>>> CMIIW...
>>> On Mon, Aug 22, 2011 at 10:28 AM, Lowell Kirsh <[hidden email]> wrote:
>>>>
>>>> I'm new to joda an am seeing surprising behavior. I have created a
>>>> Period from 2 DateTimes, one which is 15 days ago and one which is now.
>>>> Looking at their toString() values, they look like they have been
>>>> constructed properly. However, Period(then, now).getDays() returns 1. Am I
>>>> doing something wrong?
>>>> code:
>>>>     @Test
>>>>     public void testJodaTime() {
>>>>         DateTime then = new DateTime(System.currentTimeMillis() - 15L *
>>>> 24L * 60L * 60L * 1000L); // 15 days ago
>>>>         DateTime now = new DateTime();
>>>>         Period period = new Period(then, now);
>>>>         System.out.println(then);
>>>>         System.out.println(now);
>>>>         System.out.println(period.getDays());
>>>>     }
>>>>
>>>> output:
>>>> 2011-08-06T20:23:16.307-07:00
>>>> 2011-08-21T20:23:16.344-07:00
>>>> 1
>>>> Thanks!
>>>> Lowell
>>>>
>>>> ------------------------------------------------------------------------------
>>>> uberSVN's rich system and user administration capabilities and model
>>>> configuration take the hassle out of deploying and managing Subversion
>>>> and
>>>> the tools developers use with it. Learn more about uberSVN and get a
>>>> free
>>>> download at:  http://p.sf.net/sfu/wandisco-dev2dev
>>>>
>>>> _______________________________________________
>>>> Joda-interest mailing list
>>>> [hidden email]
>>>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> uberSVN's rich system and user administration capabilities and model
>>> configuration take the hassle out of deploying and managing Subversion
>>> and
>>> the tools developers use with it. Learn more about uberSVN and get a free
>>> download at:  http://p.sf.net/sfu/wandisco-dev2dev
>>>
>>> _______________________________________________
>>> Joda-interest mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>>
>>
>>
>>
>> --
>> http://lowellkirsh.com
>>
>>
>>
>> ------------------------------------------------------------------------------
>> uberSVN's rich system and user administration capabilities and model
>> configuration take the hassle out of deploying and managing Subversion and
>> the tools developers use with it. Learn more about uberSVN and get a free
>> download at:  http://p.sf.net/sfu/wandisco-dev2dev
>>
>> _______________________________________________
>> Joda-interest mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/joda-interest
>>
>
>
> ------------------------------------------------------------------------------
> uberSVN's rich system and user administration capabilities and model
> configuration take the hassle out of deploying and managing Subversion and
> the tools developers use with it. Learn more about uberSVN and get a free
> download at:  http://p.sf.net/sfu/wandisco-dev2dev
>
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
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: surprising return value from Period.getDays()

Adam Vartanian
In reply to this post by Yohan Yudanara
> You can use period.toStandardDays().getDays();

You can also use Days.daysBetween(then, now).

- Adam

------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model
configuration take the hassle out of deploying and managing Subversion and
the tools developers use with it. Learn more about uberSVN and get a free
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...