Custom calendars using Joda

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

Custom calendars using Joda

Ron Olson-2
Hello all-

I'm interested in using Joda in a project where we have some specific
calendar requirements, and I've been going through the Java Docs but
I'm not sure I'm looking in the right places to determine whether what
I want to do is feasible or not.

Basically, I want to create a "business" calendar that calculates
dates based on days of the week, excluding holidays and weekends; thus
if today is Friday, 2 days from now is Tuesday in this particular
calendar. What would also be nice is some way to also feed it specific
holidays so that they would not be considered when calculating date
ranges.

I know I could create my own calendar class that does all this, but I
don't want to have to provide a facade and suddenly be responsible for
providing methods for all the functions in the member DateTime class.

I was looking at the Chronology and derived classes as a way of doing
it, considering that's how the various built-in chronologies
(Buddhist, Islamic, etc.) do it, and even the docs suggest this is
possible (it mentions a WeirdChronology with a week of 10 days and a
month of 40 days), but it doesn't mention any particular strategies
for doing this.

Might anyone have any tips, suggestions, etc., on how to write a
custom Chronology class?

Thanks,

Ron

-------------------------------------------------------------------------
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: Custom calendars using Joda

jodastephen
There is a related project http://joda-time.sourceforge.net/related.html 
that handles non-working days. That may be your easiest solution.

Writing a chronology is basically creating a subclass of Chronology or
BaseChronology and implementing as many methods as you can/want. For
example, you may only care about dates and not times.

The classes in the field package provide most of the common fields that
you need. The basic concept is that you are interpretting the long
millisecond value to something meaningful. Its a big task though (with
time zones causing even more problems).

Stephen


Ron Olson wrote:

> Hello all-
>
> I'm interested in using Joda in a project where we have some specific
> calendar requirements, and I've been going through the Java Docs but
> I'm not sure I'm looking in the right places to determine whether what
> I want to do is feasible or not.
>
> Basically, I want to create a "business" calendar that calculates
> dates based on days of the week, excluding holidays and weekends; thus
> if today is Friday, 2 days from now is Tuesday in this particular
> calendar. What would also be nice is some way to also feed it specific
> holidays so that they would not be considered when calculating date
> ranges.
>
> I know I could create my own calendar class that does all this, but I
> don't want to have to provide a facade and suddenly be responsible for
> providing methods for all the functions in the member DateTime class.
>
> I was looking at the Chronology and derived classes as a way of doing
> it, considering that's how the various built-in chronologies
> (Buddhist, Islamic, etc.) do it, and even the docs suggest this is
> possible (it mentions a WeirdChronology with a week of 10 days and a
> month of 40 days), but it doesn't mention any particular strategies
> for doing this.
>
> Might anyone have any tips, suggestions, etc., on how to write a
> custom Chronology class?
>
> Thanks,
>
> Ron
>
> -------------------------------------------------------------------------
> 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: Custom calendars using Joda

Ron Olson-2
Thanks a lot Stephen, that pretty much does exactly what I want!

On 11/22/08, Stephen Colebourne <[hidden email]> wrote:

> There is a related project http://joda-time.sourceforge.net/related.html
>  that handles non-working days. That may be your easiest solution.
>
>  Writing a chronology is basically creating a subclass of Chronology or
>  BaseChronology and implementing as many methods as you can/want. For
>  example, you may only care about dates and not times.
>
>  The classes in the field package provide most of the common fields that
>  you need. The basic concept is that you are interpretting the long
>  millisecond value to something meaningful. Its a big task though (with
>  time zones causing even more problems).
>
>  Stephen
>
>
>
>  Ron Olson wrote:
>  > Hello all-
>  >
>  > I'm interested in using Joda in a project where we have some specific
>  > calendar requirements, and I've been going through the Java Docs but
>  > I'm not sure I'm looking in the right places to determine whether what
>  > I want to do is feasible or not.
>  >
>  > Basically, I want to create a "business" calendar that calculates
>  > dates based on days of the week, excluding holidays and weekends; thus
>  > if today is Friday, 2 days from now is Tuesday in this particular
>  > calendar. What would also be nice is some way to also feed it specific
>  > holidays so that they would not be considered when calculating date
>  > ranges.
>  >
>  > I know I could create my own calendar class that does all this, but I
>  > don't want to have to provide a facade and suddenly be responsible for
>  > providing methods for all the functions in the member DateTime class.
>  >
>  > I was looking at the Chronology and derived classes as a way of doing
>  > it, considering that's how the various built-in chronologies
>  > (Buddhist, Islamic, etc.) do it, and even the docs suggest this is
>  > possible (it mentions a WeirdChronology with a week of 10 days and a
>  > month of 40 days), but it doesn't mention any particular strategies
>  > for doing this.
>  >
>  > Might anyone have any tips, suggestions, etc., on how to write a
>  > custom Chronology class?
>  >
>  > Thanks,
>  >
>  > Ron
>  >
>
> > -------------------------------------------------------------------------
>  > 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
Loading...