commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 33825] New: - [lang] PATCH-New methods for DateUtils
Date Thu, 03 Mar 2005 06:45:18 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=33825>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=33825

           Summary: [lang] PATCH-New methods for DateUtils
           Product: Commons
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P3
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: fzammetti@omnytex.com


The other day I had a requirement at work to write a function to determine if 
a time fell within a given range.  The problem was, the range could span days, 
i.e., it might start at 8pm and end at 3am.

I've expanded on the function I wrote and now offer it for inclusion in the 
DateUtils class.  The base method, isTimeInRange(), accepts three ints: the 
start of the range, end end of the range and the time to check against the 
range.  The times are to be in 24-hour form (i.e., 1200, 1600, etc.)  Note 
that 0800 should be passed as 800, otherwise it'd be Octal!

I also provide two overloaded versions: 

* One accepts three Calendar objects

* The other accepts four String objects (the three times as Strings, and a 
fourth parameter that tell the method whether the times are in 24-hour form or 
12-hour 99:99ap form).  Note that the hour can be a single or double-digit, as 
can the minute technically (although 12:9 would be interpreted as 12:09 in 
essence).  Also, the meridian can be a single letter a/A or p/P, or the actual 
value AM/PM.

All methods can throw an IllegalArgumentException for various conditions, and 
the version that accepts Strings can also throw NumberFormatException.

Attached is a single source file, DateUtils.java creatively :)  I included in 
it a standard main() method that runs a series of unit tests (I was having 
trouble with jUnit for some reason, but I didn't want that to hold up the 
submission).  In addition to the three versions of isTimeInRange(), you'll 
also find two static finals that can be used for convenience when using the 
version that accepts Strings to tell it what form the times are in (or you can 
just pass the int values 12 or 24).  Lastly, there is a private string12To24() 
method that is used to convert a time string in 12-hour form to 24-hour form.

I know one person on the mailing list is very interested in seeing this, and 
it is my hope that others will find it interesting as well, and worthy of 
addition to DateUtils.  Thanks very much, feel free to contact me if I can be 
of assistance!

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

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


Mime
View raw message