commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Serge Knystautas <ser...@lokitech.com>
Subject Lang addition: CalendarUtils
Date Sun, 28 Jul 2002 04:37:53 GMT
I've got a CalendarUtils class I wrote this past summer that I'd like to 
offer up to the Lang project.  Here are the highlights...

- truncate - you pass a date/calendar and a calendar field (i.e., 
Calendar.MINUTE, Calendar.MONTH, or whatever), and it will truncate the 
date.  So if I did new java.util.Date() and that was 2002 July 28 
12:31:49.410 am and I truncated that to the HOUR, I would get 2002 July 
28 12:00:00.000 am.

- round - same as above, except it rounds.  So with the same data, the 
rounding would give me 2002 July 28 1:00:00.000 am.

Those are the main ones I seem to always need.  Here's another one I 
just added which is useful if you're creating month or calendar views...

getCalendarIterator() - you pass it a Date/Calendar, and a calendar type 
that also represents how you want to represent it.  It will then give 
you an iteration of calendar objects for each day in the range it will 
calculate.  So... if I asked for the month view (weeks starting with 
Sunday), with the above datetime, I would get an Iterator of Calendar 
objects starting Sunday June 30th through Saturday August 3rd.  You can 
also do week views, and you can do weeks starting on Sunday or Saturday, 
or have the week centered on the date provided, or the week starting on 
the date provided.  Like I said, it's very useful if you're building 
dynamic month or week calendar views.

I've spec'd out and really would like to get a String -> Calendar parser 
that can handle all the syntaxes supported by CVS, including 
"Yesterday", "one week ago", and "last monday".  This really shouldn't 
be too difficult if someone wants to add that (or if I get a chance), 
and it would make date entry so much more friendly for users.

Let me know what format you'd like it in, assuming you'd want to include 
it.  I don't have nice junit tests setup, but I had hacked some simple 
tests together at one point... not sure how rigorous you're after for 
initial contributions.

Thanks!

-- 
Serge Knystautas
Loki Technologies - Unstoppable Websites
http://www.lokitech.com/


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message