Daylight Saving time: How to identify if a given time is invalid?

P

Pranav Kantawala

Hi,

I'm writing a web application in Java to schedule tasks at specified
times. I need to figure out if user has entered a date/time
combination that is invalid with respect to daylight saving time
shifts.

For instance, in US Pacific time, the clock will spring forward from
1:59am to 3:00am on Sunday, April 4, 2004. Therefore, the time
interval between 2:00am and 2:59am is not defined.

If user enters time as, say, 2:30am April 4, I need to figure out that
this is not a valid time. What is the best way to do this in Java?
The solution needs to be locale-independent.

I'm using a Calendar object for date/time representation. I get/set
time in the object using Calendar.get and Calendar.set methods. If I
set the time as 2:30am using set method, when I query the date using
get, I get back 3:30am! So, if what I set in the object is not the
same as what I get back, it means that the time is not valid. Is this
a good way to meet the requirement?

Any insight would be much appreciated.

Thanks,
Pranav
 
P

P.Hill

Please don't cross post.

Pranav said:
[...]
If user enters time as, say, 2:30am April 4, I need to figure out that
this is not a valid time. What is the best way to do this in Java?
The solution needs to be locale-independent.

You need to pick SOME locale which uses DLS, otherwise the
question has no meaning.
Any insight would be much appreciated.

Use SimpleDateFormat which uses its own Calendar object within itself.
Also use setLenient( false ) and see if that takes care of
its ability to take 2:30 AM PST on April 4th.

HTH,
-Paul
 
K

Karl von Laudermann

P.Hill said:
Please don't cross post.

Crossposting is acceptable if the post is appropriate to all the
newsgroups included. It is preferable to multiposting because if
you're using a proper newsreader, you'll only see the post once, even
if you read both groups.

Sorry, but crossposting *is* acceptable netiquette, and it's a pet
peeve of mine when someone says "don't cross post" in situations where
it is acceptable.
 
P

P.Hill

Karl said:
Sorry, but crossposting *is* acceptable netiquette, and it's a pet
peeve of mine when someone says "don't cross post" in situations where
it is acceptable.

Using your logic and assuming the OP post belongs in both, than
all posts appropriate for .help would also be appropriate for
..programmer. If that was the case we wouldn't have .help,
somehow you've left something out in your logic.

If I understand the idea of .help, I believe .help is supposed to
be a separate group, not an overlapping group. It hinges more
on the intent of the two groups than the idea of crossposting.

Two wasn't a bad amount of crossposting. All I said was please
don't.

cheers,
-Paul
 
K

Karl von Laudermann

P.Hill said:
Using your logic and assuming the OP post belongs in both, than
all posts appropriate for .help would also be appropriate for
.programmer. If that was the case we wouldn't have .help,
somehow you've left something out in your logic.

What I left out of my logic was the same thing you left out of yours:
an explanation as to why this particular case of crossposting was
inappropriate. You merely said "don't cross post" as though
crossposting is never acceptable, i.e. considered bad netiquette. If
you had specifically stated that the OP's message was inappropriate
for .programmer in your initial post, I wouldn't have responded.

However, admittedly I did imply that I thought his crosspost was
acceptable; I'm not sure whether Java programming questions should be
verboten in .programmer, just because .help exists. If I have a
question as to how to implement something, and I'm not a Java beginner
asking some basic question, what's wrong with asking in .programmer?
Especially if it could lead to design discussion, rather than a simple
"here's how you do it" answer.
 
P

P.Hill

Karl said:
I'm not sure whether Java programming questions should be
verboten in .programmer, just because .help exists.

I am sure. Pick one or the other, just not both.
what's wrong with asking in .programmer?

Nothing, I wasn't trying to imply it was to dumb a question, after all
I answered it, I'm just asking that people try to not even get into the
two group habit, before you know it they'll be shooting up heroin!
Ah, I mean they'll be trying maybe a third then ...

Sorry, I believe a better way to behave is to try a group, if that
doesn't work try another. Crossposting causess cancer, don't do it.

cheers,
-Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top