Some Period Questions

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

Some Period Questions

Matt Hughes
One of my programming bugbears is when coders use a primitive such as 'int' to represent some unit of time so I was pleased when I found the Period class in joda-time but dismayed to find no milliseconds support.

Why is there no Milliseconds class to parallel all the others (Seconds, Hours, Days, etc).  My code base interacts with many APIs that expect their timeouts to be in milliseconds.  What I would like to do is pass around a Period instance for as long as I can until I bump up to one of those APIs and convert that value into milliseconds.  Is there any reason that class couldn't be added and the added toStandardMilliseconds?  I'd be happy to submit a patch.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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: Some Period Questions

jodastephen
There is no Milliseconds class because Duration models time in
milliseconds. The latest SVN has more methods to convert between the
different types if I remember correctly.

Stephen


Matt Hughes wrote:

> One of my programming bugbears is when coders use a primitive such as
> 'int' to represent some unit of time so I was pleased when I found the
> Period class in joda-time but dismayed to find no milliseconds support.
>
> Why is there no Milliseconds class to parallel all the others (Seconds,
> Hours, Days, etc).  My code base interacts with many APIs that expect
> their timeouts to be in milliseconds.  What I would like to do is pass
> around a Period instance for as long as I can until I bump up to one of
> those APIs and convert that value into milliseconds.  Is there any
> reason that class couldn't be added and the added
> toStandardMilliseconds?  I'd be happy to submit a patch.
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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: Some Period Questions

Matt Hughes
So...Period and Duration represent basically the same thing right, except Duration can only retrieve the milliseconds while Period gives access to all individual fields with the potential for loss of precision?  Is there any reason the two classes couldn't be combined?  

For example, a lot of timeout APIs normally have something looking like this:

public void setTimeout(long timeoutInMilliseconds) {}

A normal call for 2 seconds would look something like this (with added doc to help readers know the unit):

setTimeout(2000); // in milliseconds

What type would you recommend to replace the long here?  Duration or Period?  I like Period because it allows easy construction of time durations using non-millisecond units.

If I made it take Duration, calls would look something like:

setTimeout(Period.seconds(2).toStandardDuration().getMillis());

Not that pretty.  Period would be much more concise.:

setTimeout(Period.seconds(2));


Again I think these two classes could be combined and make the API more uniform.  What do you think?


On Mon, Aug 25, 2008 at 5:51 AM, Stephen Colebourne <[hidden email]> wrote:
There is no Milliseconds class because Duration models time in
milliseconds. The latest SVN has more methods to convert between the
different types if I remember correctly.

Stephen


Matt Hughes wrote:
> One of my programming bugbears is when coders use a primitive such as
> 'int' to represent some unit of time so I was pleased when I found the
> Period class in joda-time but dismayed to find no milliseconds support.
>
> Why is there no Milliseconds class to parallel all the others (Seconds,
> Hours, Days, etc).  My code base interacts with many APIs that expect
> their timeouts to be in milliseconds.  What I would like to do is pass
> around a Period instance for as long as I can until I bump up to one of
> those APIs and convert that value into milliseconds.  Is there any
> reason that class couldn't be added and the added
> toStandardMilliseconds?  I'd be happy to submit a patch.
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
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: Some Period Questions

jodastephen
Period and Duration represent different concepts.

Duration is the scientific definition of an amount of time, where a
millisecond is defined by the international standards organisations.

Period represents the human definition of time, where a
year/month/day/hour/minute/second is defined by humans for general purposes.

Now, typically, these two concepts coincide such that one second
duration equals one second period, but that does not have to be the
case. Hence two classes.

For a timeout, you usually add it to a time-source, so a Duration is
more appropriate.

For the 1.6 release the issue will be less significant, as you'll be
able to create a Duration using "standard" days, hours, minutes and
seconds instead of just millis.

Stephen


Matt Hughes wrote:

> So...Period and Duration represent basically the same thing right,
> except Duration can only retrieve the milliseconds while Period gives
> access to all individual fields with the potential for loss of
> precision?  Is there any reason the two classes couldn't be combined?  
>
> For example, a lot of timeout APIs normally have something looking like
> this:
>
> public void setTimeout(long timeoutInMilliseconds) {}
>
> A normal call for 2 seconds would look something like this (with added
> doc to help readers know the unit):
>
> setTimeout(2000); // in milliseconds
>
> What type would you recommend to replace the long here?  Duration or
> Period?  I like Period because it allows easy construction of time
> durations using non-millisecond units.
>
> If I made it take Duration, calls would look something like:
>
> setTimeout(Period.seconds(2).toStandardDuration().getMillis());
>
> Not that pretty.  Period would be much more concise.:
>
> setTimeout(Period.seconds(2));
>
>
> Again I think these two classes could be combined and make the API more
> uniform.  What do you think?
>
>
> On Mon, Aug 25, 2008 at 5:51 AM, Stephen Colebourne
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>     There is no Milliseconds class because Duration models time in
>     milliseconds. The latest SVN has more methods to convert between the
>     different types if I remember correctly.
>
>     Stephen
>
>
>     Matt Hughes wrote:
>      > One of my programming bugbears is when coders use a primitive such as
>      > 'int' to represent some unit of time so I was pleased when I
>     found the
>      > Period class in joda-time but dismayed to find no milliseconds
>     support.
>      >
>      > Why is there no Milliseconds class to parallel all the others
>     (Seconds,
>      > Hours, Days, etc).  My code base interacts with many APIs that expect
>      > their timeouts to be in milliseconds.  What I would like to do is
>     pass
>      > around a Period instance for as long as I can until I bump up to
>     one of
>      > those APIs and convert that value into milliseconds.  Is there any
>      > reason that class couldn't be added and the added
>      > toStandardMilliseconds?  I'd be happy to submit a patch.
>      >
>      >
>      >
>     ------------------------------------------------------------------------
>      >
>      >
>     -------------------------------------------------------------------------
>      > This SF.Net email is sponsored by the Moblin Your Move
>     Developer's challenge
>      > Build the coolest Linux based applications with Moblin SDK & win
>     great prizes
>      > Grand prize is a trip for two to an Open Source event anywhere in
>     the world
>      > http://moblin-contest.org/redirect.php?banner_id=100&url=/
>     <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
>      >
>      >
>      >
>     ------------------------------------------------------------------------
>      >
>      > _______________________________________________
>      > Joda-interest mailing list
>      > [hidden email]
>     <mailto:[hidden email]>
>      > https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>     -------------------------------------------------------------------------
>     This SF.Net email is sponsored by the Moblin Your Move Developer's
>     challenge
>     Build the coolest Linux based applications with Moblin SDK & win
>     great prizes
>     Grand prize is a trip for two to an Open Source event anywhere in
>     the world
>     http://moblin-contest.org/redirect.php?banner_id=100&url=/
>     <http://moblin-contest.org/redirect.php?banner_id=100&url=/>
>     _______________________________________________
>     Joda-interest mailing list
>     [hidden email]
>     <mailto:[hidden email]>
>     https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...