java.util.Date issues

Dear all,

I have to handle a period with "fromDate" and "toDate".

The idea is to provide default values for these two dates.

For "fromDate", I can use "new Date(0) ".

For "toDate", I can use "new Date(Long.MAX_VALUE )".

However, I don't think that the above ideas are the best way of handle the issue.

Do you have a better idea?

Cheers,

Pengyou

[401 byte] By [pengyoua] at [2007-10-2 2:06:01]
# 1

Why do you need this? There is no logical reason to have such min/max dates (or is it just a technical way to have some boundaries?). If these values are "default", and you have the default case, then you have 2 invalid dates (or at least 2 dates that you probably don't want to). First think of the real min and max values your application should process and then hard wire them instead of 0 and Long.MAX_VALUE.

MartinHilperta at 2007-7-15 19:47:27 > top of Java-index,Java Essentials,Java Programming...
# 2
if you're only after some reasonable default values, why not set fromDate to new Date() and toDate to fromDate plus 24 hours, or plus a week, or plus a fortnight.. depends on the application
jsalonena at 2007-7-15 19:47:27 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks for both of you.My real problem is to handle the case that fromDate is filled by user via GUI but the toDate is not filled, or vice versa.Any new wisdom?
pengyoua at 2007-7-15 19:47:27 > top of Java-index,Java Essentials,Java Programming...
# 4

well then depends on the context, no?

if this is for a reservation system of some kind, for example, it wouldn't be unreasonable to assume that fromDate would be for instance the day after tomorrow and toDate a week later?

you could also consider issuing an error message if the dates have not been filled, it would be on the benefit of the user.

jsalonena at 2007-7-15 19:47:27 > top of Java-index,Java Essentials,Java Programming...
# 5
Thanks. I would that the default "fromDate" and 'toDate" cover all the possible business period for a file management system.But i don't know it should be from 1990 - 2008 or 1950 - 2020 or ...Any new wisdom?PY
pengyoua at 2007-7-15 19:47:27 > top of Java-index,Java Essentials,Java Programming...