Java Time/Calendar Bug?

H

Hal Vaughan

I have the following in my code:

GregorianCalendar cal = new GregorianCalendar();
....
tString = "00" + String.valueOf(cal.get(Calendar.HOUR_OF_DAY));

When I run it, now, the time is one hour behind my system's time. I've been
searching, but it seems the closest bug I could find was effecting Palm
Pilots. I'm using a program composed on Java 1.4.2 and running on Java 5.
If the time zone matters, I'm on Eastern Time, during Daylight Savings.
This is happening now, but could have been an issue previously and I may
not have noticed it.

I've also replaced HOUR_OF_DAY with HOUR and had the same problem.

I know the US has decided to muck things up and start DST earlier and end it
later and I see how that would effect this issue during the "exception"
days effected by that change, but I wouldn't expect it to effect the time
during September, when we're normally in DST>\.

Does anyone have more info about this?

Hal
 
K

Knute Johnson

Hal said:
I have the following in my code:

GregorianCalendar cal = new GregorianCalendar();
...
tString = "00" + String.valueOf(cal.get(Calendar.HOUR_OF_DAY));

When I run it, now, the time is one hour behind my system's time. I've been
searching, but it seems the closest bug I could find was effecting Palm
Pilots. I'm using a program composed on Java 1.4.2 and running on Java 5.
If the time zone matters, I'm on Eastern Time, during Daylight Savings.
This is happening now, but could have been an issue previously and I may
not have noticed it.

I've also replaced HOUR_OF_DAY with HOUR and had the same problem.

I know the US has decided to muck things up and start DST earlier and end it
later and I see how that would effect this issue during the "exception"
days effected by that change, but I wouldn't expect it to effect the time
during September, when we're normally in DST>\.

Does anyone have more info about this?

Hal

Hal:

You running Linux? Maybe Fedora?
 
K

Knute Johnson

Hal said:
Yes, Linux. Ubuntu Feisty on this system.

Hal

There is a bug, I can't find my notes right now to tell you what the
number is but the fix is to remove any spaces from your timezone in
/etc/sysconfig/clock. Mine was:

ZONE=America/Los Angeles and I changed it to

ZONE=America/Los_Angeles

That solved my one hour problem with Java. Now I'm not sure that Ubuntu
uses /etc/sysconfig/clock. I don't have any Ubuntu running here but I
will load the live CD after I post this and see what I can find.
 
H

Hal Vaughan

Knute said:
There is a bug, I can't find my notes right now to tell you what the
number is but the fix is to remove any spaces from your timezone in
/etc/sysconfig/clock. Mine was:

ZONE=America/Los Angeles and I changed it to

ZONE=America/Los_Angeles

That solved my one hour problem with Java. Now I'm not sure that Ubuntu
uses /etc/sysconfig/clock. I don't have any Ubuntu running here but I
will load the live CD after I post this and see what I can find.

Do you know if there's any side effects with other Linux programs, or do
they recognize the underscore and space as the same in time zones?

If it's just on my system, that's no problem. I'm testing it on my
computer. Most people running this will be on Windows. A few will be on
Linux, but they're smart enough they can work with me on this.

Thanks for the info -- I was wondering if I was doing something wrong!

Hal
 
K

Knute Johnson

Hal said:
Do you know if there's any side effects with other Linux programs, or do
they recognize the underscore and space as the same in time zones?

As far as I know it does not affect any other programs (he says).
If it's just on my system, that's no problem. I'm testing it on my
computer. Most people running this will be on Windows. A few will be on
Linux, but they're smart enough they can work with me on this.

Windows shouldn't be a problem.
Thanks for the info -- I was wondering if I was doing something wrong!

Hal

I just loaded up my Ubuntu CD and ran it live and I don't find a
/etc/sysconfig/clock. In fact there is no sysconfig directory. I'm not
sure where Ubuntu keeps the timezone. You might look around for that.
On Fedora it is in the clock file. I would be curious to know if you
find out where it is kept.

The bug number is 6456628. Somebody posted the note here a couple of
months ago about the space versus under_score. You might vote for this
bug if you have any to spare.

What time zone are you in Hal?
 
I

Ingo Menger

Do you know if there's any side effects with other Linux programs, or do
they recognize the underscore and space as the same in time zones?

You can most easily test this by running
date
perl -e '$x= localtime(time); print "$x";'
etc.
On some *Xs, there is a environment variable TZ, that works like this
(all commands typed within a few minutes):

$ echo $TZ
MET
$ date
Wed Aug 8 15:32:35 MEST 2007
$ TZ=XXX date
Wed Aug 8 13:32:46 GMT 2007
$ TZ=UTC+5 date
Wed Aug 8 08:33:05 UTC 2007
$ TZ=UTC-5 date
Wed Aug 8 18:33:13 UTC 2007
$ TZ=EST date
Wed Aug 8 08:33:28 EST 2007
$ TZ=EST+1 date
Wed Aug 8 12:34:00 EST 2007
$ TZ=XXX+1 date
Wed Aug 8 12:34:34 XXX 2007

On that system, TZ is honored and there is a set of known timezones
(i.e. MET where it also knows the associated daylight savings timezone
name or EST (that is the same as 5 hours west UTC) and you can also
enter a custom timezone where the time zone name is not honored, thus
EST+1 is the same as XXX+1 and is interpreted as UTC+1)
If it's just on my system, that's no problem. I'm testing it on my
computer. Most people running this will be on Windows. A few will be on
Linux, but they're smart enough they can work with me on this.

As long as the programs I listed above print the same time as your
program does, then it is okay. Otherwise, it's a problem with java or
your program.
 

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,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top