Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

verifying a date is valid based on integer values for year, month and day of month

Thread view: 
lbrtchx@hotmail.com - 22 Dec 2006 19:46 GMT
Say you have a Calendar instance.
.
  Calendar Klndr = java.util.Calendar.getInstance();
  Klndr.setLenient(false);
  Klndr.clear();
  Klndr.set(Calendar.YEAR, iYOD);
  Klndr.set(Calendar.MONTH, iIxMonth);
  Klndr.set(Calendar.DAY_OF_MONTH, iDOD);
.
 How could you see if the date was write?
.
I don't see any exceptions being thrown in the class to complain for
invalid dates
.
lbrtchx
Steve W. Jackson - 22 Dec 2006 20:24 GMT
>  Say you have a Calendar instance.
> .
[quoted text clipped - 11 lines]
> .
>  lbrtchx

If you read the discussion in the Javadocs on Calendar, you might want
to reconsider three separate calls to set() because of potential
interactions between fields.  Instead, I suggest using the alternate
method set(year, month, date) to set all three at once.  Once that's
done, I suspect that the easiest way to validate your three values is to
then compare each to what's in the Calendar.

Of course, that overlooks your call to setLenient(false) above.  The API
says you should get an exception if any of those values is out of bounds
when calling set() for individual fields.  But my reading suggests that
doesn't cover all your bases (and I haven't tested it).  I think it
means you can't pass 15 for a month, for instance.  But what happens
when you pass 30 for a day when you've previously set the month to
February isn't obvious.  That's why I think you might be better off
letting it stay lenient, using the set() version that takes all three
values, and then comparing the result against the ones you sent in.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.