• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

util date validation

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have a current scenario where in an external application invokes my application code. I am in the process of writing an input validation utility.
One of the input parameter is a java.util.Date object.
My question here is if the client will be invoking my application with a Date input parameter then I can be rest assured that the incoming Date object is a proper one and I don't have to worry about invalid/absurd dates as it is the case when date value is passed as a String object.
Is there anything that can go wrong when the input is a java.util.Date object.
In this case say if I want to reject all valid dates prior to year 1900 how is that normally done something like checking boundary date conditions.

Let me know.

Thanks,
Mohit
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're getting a proper java.util.Date object, you can be sure that it is legitimate. IE the day of the month won't be greater than 31, the year won't be negative, etc. You can always do validation, but unfortunately the methods in java.util.Date are deprecated so you'll have to pass the Date into a Calendar object and then use the get methods to determine whether the day, month, year, etc. are within your valid ranges.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Careful passing numbers to a java.util.Date; it is liable to interpret 123 as 2023 in the year field.

Go to www.toedter.de and you find a lovely GUI component which enters dates; you can get year month day from that and text the values as you enter them.
 
reply
    Bookmark Topic Watch Topic
  • New Topic