Handling of DST in java

N

nag

Hi,
Does java handle DST automatically ?
I'm using java Gregorian calendar to get the time/date. Does this
automatically give the local time/date iirrespective of DST or special
handling should be done ?
 
T

Thomas Weidenfeller

nag said:
Does java handle DST automatically ?
I'm using java Gregorian calendar to get the time/date. Does this
automatically give the local time/date iirrespective of DST or special
handling should be done ?

What do you really want to do? If you need to represent a point in time
internally in your application, then a calendar is a bad choice. Use a
Date() object, or the time (as a long, in milliseconds). Java keeps its
date/time in milliseconds since Jan .1st, 1970 00:00 GMT. Only when you
you do some I/O you should consider if you want to have GMT/UTC
date/time, or local time (with DST)

E.g. if you just need to print out some time, [Simple]DateFormat is
often a much better choice than a calendar. It takes the local time-zone
into account, and you an specify another zone. Time-zone information
contains DST information.

A calendar is useful for presenting(!) some point in time in, guess
what, calender format, and doing some calculations based on this
representation, but not more. The representations produced by
GregorianCalender are somewhat imprecise. E.g. GregorianCalendar doesn't
know about leap seconds.

GregorianCalender does take time-zone information (and thus DST, if
defined for a time-zone) into account. But if I remember correctly, does
so inconsistently. If I remember correctly, then it sometimes assumes a
change from/to DST happens at midnight local time, which is wrong for
several time-zones. GregorianCalender also has a problem with the times
which appear twice when the clock is turned back at the end of DST. You
can't specify if you want to have the A (DST) or B (standard) time when
you e.g. set the HOUR value, or when you move into that period with and
add().

Doing timekeeping with a calender is usually a bad idea in Java.

/Thomas
 
R

Roedy Green

Does java handle DST automatically ?
I'm using java Gregorian calendar to get the time/date. Does this
automatically give the local time/date iirrespective of DST or special
handling should be done ?

Yes. However, because the tables are so voluminous, and because
people think it fun to change the rules, as if they were ordering the
sun to change it rising time, Sun's tables will always be a little
off.

I think it is a nutty idea. It creates two goofy anomalies each year
-- a missing hour and an hour lived twice. Leave the time alone and
just declare different summer and winter business hours.
Non-compliance would help spread rush hour.
 
S

Stefan Ram

Roedy Green said:
I think it is a nutty idea. It creates two goofy anomalies each year
-- a missing hour and an hour lived twice. Leave the time alone and
just declare different summer and winter business hours.

I agree. It just seems to be an attempt to show to power of
the government, "look, we can change the run of the time!" or
"Look, we can make completely idiotic rules, still you have to
live by them."

In 2005, US-president Bush signed a paper to extend DST by
four weeks in the USA (starting in 2007), and to make life
even more complicated by adding another rule modification ...

There is an "international movement" against it, the German
website is

http://www.initiative-sonnenzeit.de/
 
E

Eric Sosman

Roedy Green wrote On 01/10/06 13:27,:
Yes. However, because the tables are so voluminous, and because
people think it fun to change the rules, as if they were ordering the
sun to change it rising time, Sun's tables will always be a little
off.

I think it is a nutty idea. It creates two goofy anomalies each year
-- a missing hour and an hour lived twice. Leave the time alone and
just declare different summer and winter business hours.
Non-compliance would help spread rush hour.

Why stop there? Get rid of this silly business of
time zones and just run the entire world on UTC. (That
way I'll have a good excuse for lying in bed until noon
and not returning there until tomorrow morning.)

While we're at it, let's reform the calendar: Who
needs this arbitrary assortment of irregularly-sized
months, anyhow? "Thirty days hath September / The Ides
come on the fifteenth day ..." Bosh! And look at all
the confusion it's caused, what with the Merkins and
Yoorops unable to tell whether 6/6 is June 6 or 6 June.
A simple day-of-year count of 1..365 (0..365 in Leap
Year) would do just fine. Knowing that today is the
10th and Christmas is the 359th would make it much
easier to count those shopping days ...

Come to think of it, who really needs a count of
years any more? We'll just get all of civil society to
switch to counting milliseconds since, since, well I
guess we'll just call it Millisecond Zero. "You are
charged with serving alcohol to a person under the age
of 568036800000, for which you could be sent to prison
for as long as 126230400000. How do you plead?" See
how much simpler things are when you don't need to
specify which of a multitude of confusing units is
meant?

Roedy, I think you've got something -- and if you'll
let me smoke some, too, I won't rat to the narcs.
 
R

Roedy Green

I agree. It just seems to be an attempt to show to power of
the government, "look, we can change the run of the time!" or
"Look, we can make completely idiotic rules, still you have to
live by them."

Local time is a concept on its way out. With netmeetings across the
globe, you have to arrange your meeting in some common global base
time, be it UTC , EST or head office time.

Similarly for satellite broadcasts across time zones.

As travel speeds up, we may find even meetings between in and out of
towners arranged in some common base -- NOT local time.

When a politician meddles with the rules for time, it creates a
headache for anyone who has a payroll system, or anything that runs 24
hours.

I first became aware of the problem back in the 1970s. To my surprise,
"war time" as it was originally called was quite chaotically employed,
using an offset up to 5 hours, with every community separately making
up their own rules about when to kick in and out each year.

Railroads refused to play and published their schedules in standard
time. I suppose with computers they have now relented.

I like the idea of keeping correlation between time and position of
the Sun in the sky. Pretending the sun in irrelevant to man's
activity is just arrogance. It enforces the idea that man is not an
animal with the same environmental limitations that face all animals.

Java wisely stores all dates in UTC and considers timezone merely a
display quirk, not something inherent in the measurement.
 
R

Roedy Green

Come to think of it, who really needs a count of
years any more?

At some point that will have to happen. Years are a very earth-centric
measure, hardly suitable for a civilisation spanning many worlds.

If someone discovers time is quantised, perhaps we could use time
quanta since the big bang, with the high and low order bits deleted.

But now there appears to be some doubt there was a big bang after all.
We will have to pick an arbitrary starting point, perhaps the adoption
of the new calendar.
 
R

Roedy Green

Roedy, I think you've got something -- and if you'll
let me smoke some, too, I won't rat to the narcs.

I consider that sort of crack unacceptably rude, though I notice
people using them quite casually without obvious malice.
 
E

Eric Sosman

Roedy Green wrote On 01/10/06 15:16,:
At some point that will have to happen. Years are a very earth-centric
measure, hardly suitable for a civilisation spanning many worlds.

If someone discovers time is quantised, perhaps we could use time
quanta since the big bang, with the high and low order bits deleted.

But now there appears to be some doubt there was a big bang after all.
We will have to pick an arbitrary starting point, perhaps the adoption
of the new calendar.

Don't invent Yet Another Zero; stick with existing precedent:

http://www3.sympatico.ca/n.rieck/docs/calendar_time_y2k_etc.html#nov-17-1858
 
R

Raymond DeCampo

Roedy said:
Local time is a concept on its way out. With netmeetings across the
globe, you have to arrange your meeting in some common global base
time, be it UTC , EST or head office time.

Similarly for satellite broadcasts across time zones.

As travel speeds up, we may find even meetings between in and out of
towners arranged in some common base -- NOT local time.

When a politician meddles with the rules for time, it creates a
headache for anyone who has a payroll system, or anything that runs 24
hours.

I first became aware of the problem back in the 1970s. To my surprise,
"war time" as it was originally called was quite chaotically employed,
using an offset up to 5 hours, with every community separately making
up their own rules about when to kick in and out each year.

Railroads refused to play and published their schedules in standard
time. I suppose with computers they have now relented.

I like the idea of keeping correlation between time and position of
the Sun in the sky. Pretending the sun in irrelevant to man's
activity is just arrogance. It enforces the idea that man is not an
animal with the same environmental limitations that face all animals.

Java wisely stores all dates in UTC and considers timezone merely a
display quirk, not something inherent in the measurement.

The sun is in fact a prime motivator for daylight saving time.
Politicians are not simply meddling with time to display their power.
It has been shown that daylight saving time results in less energy
consumption. I'll leave it as an exercise to the reader why that is a
good thing. :)

Ray
 
L

Luc The Perverse

Stefan Ram said:
I agree. It just seems to be an attempt to show to power of
the government, "look, we can change the run of the time!" or
"Look, we can make completely idiotic rules, still you have to
live by them."

In 2005, US-president Bush signed a paper to extend DST by
four weeks in the USA (starting in 2007), and to make life
even more complicated by adding another rule modification ...

There is an "international movement" against it, the German
website is

http://www.initiative-sonnenzeit.de/

I really don't think Bush gives a shit what his people think let alone
Germans.
 
O

Oliver Wong

Eric Sosman said:
Come to think of it, who really needs a count of
years any more? We'll just get all of civil society to
switch to counting milliseconds since, since, well I
guess we'll just call it Millisecond Zero. "You are
charged with serving alcohol to a person under the age
of 568036800000, for which you could be sent to prison
for as long as 126230400000. How do you plead?" See
how much simpler things are when you don't need to
specify which of a multitude of confusing units is
meant?

I think it would make more sense to make the "second" the basic unit of
time, just like the "meter" is the basic unit of length, or the "litre" is
the basic unit of volume. And so the judge would probably not say "under the
age of 568036800 seconds", but rather "under the age of 568 megaseconds".

But then again, 568 megaseconds seems rather arbitrary, and would only
exist for historical reasons related to the drinking age previously being
based on the unit of year. So with these new units, probably for
convenience, the drinking age would be amended to 500 megaseconds, or 600
megaseconds or some other round number (500 Ms is approximately 15 years and
10 months, 600 Ms is approximately 19 years).

For a sense of scale with respect to life expectancy, 80 years is about
2.5 gigaseconds.

- Oliver
 
S

Stefan Ram

Raymond DeCampo said:
It has been shown that daylight saving time results in less
energy consumption.

"less" in relation to what?

Leaving the time zone unmodified, but shifting the start and
end time of work might have the same effect.
 
R

Roedy Green

Don't invent Yet Another Zero; stick with existing precedent:

the old Julian astronomer's calendar epoch is a good one. It does not
have religious connotations.

Another than might just evolve out of Java is millis since 1970 since
programmers learn it as a side effect of debugging date code.
These probably is a defacto one that all the satellite and
astronomical folk use for high precision work.
 
C

Chris Uppal

Eric said:
Why stop there? Get rid of this silly business of
time zones and just run the entire world on UTC.

The reason for stopping there is that DST is an outdated hack that could easily
/be/ dropped, whereas any the other options you mention would require that real
people adapt to it (which ain't going to happen -- obviously).

OTOH, if you are genuinely want to see peoples' local intuitions about
times-of-day reflected in the clock, why don't we go back to the idea that the
length of an hour/minute/second is dependent on the length of the local
day/night (as used to be the case) ? That, very people-centric, idea was
dropped several hundred years ago, but only because they didn't have the
technology. Nor had they (I think) the sophistication to recognise that they
could use two clocks, one for scientific/global purposes (such as astronomy and
international trade) and another for local purposes. We do now (for both).
So the hour from midnight to 1 AM in Aberdeen should be longer than the
corresponding hour in London (at this time of year -- the reverse in summer). I
admit that that would introduce some small problems (for instance the local
speed limit would change with the time of day ;-), but nothing that couldn't
easily be dealt with.

-- chris
 
E

Eric Sosman

Roedy Green wrote On 01/10/06 15:20,:
I consider that sort of crack unacceptably rude, though I notice
people using them quite casually without obvious malice.

My tongue was quite firmly in my cheek, as I thought
would be clear from the rest of my message. If the
resulting grimace offended you, I apologize.

It's been observed more than once that although Usenet
is a good channel for words, it's a poor communicator of
"attitude."
 
A

Alex Buell

I consider that sort of crack unacceptably rude, though I notice
people using them quite casually without obvious malice.

What's the matter, someone take away your sense of humour?
 
R

Raymond DeCampo

Stefan said:
"less" in relation to what?

I think that it is clear that the statement above compares daylight
saving time to the lack of daylight saving time.
Leaving the time zone unmodified, but shifting the start and
end time of work might have the same effect.

Perhaps, but that is not something the government can easily legislate
nor enforce. (Do you really want the time police checking to see if you
are working an hour later?) Changing the wall clock time is the easiest
way to get people to actually observe the change.

There is nothing sacred about the time zone. It has always been under
the purview of government. In China, there should be about five time
zones by geographical standards, but there is only one. In the U.S.,
the Eastern time zone is about twice as big as it should be.

Ray
 
S

Stefan Ram

Raymond DeCampo said:
Perhaps, but that is not something the government can easily
legislate nor enforce. (Do you really want the time police
checking to see if you are working an hour later?)

Something like this is done here for the closing-time of
stores. So, since the government already enforces
opening-times and closing-times of stores, they could change
these and they could change to times for schools, universities
and their own agencies. Some other institutions then might
follow.
There is nothing sacred about the time zone.

It is only that, given two time stamps of the legal time for
a location in Germany, like

2005-07-10T21:38:10 and
1960-07-10T21:38:13

it would be a typical programming task to write a routine
that can calculate the difference between them in seconds.
And this would be much more easy, without the need to have
to find out all details of regulations for DST in Germany.

After WWII, in Germany, there were several different zones
controlled by different countries and some details for the DST
differed between these zones. In one zone, there was a special
DST with two hours added for the mid of summer. Then there are
reports that there were years with DST even in winter. And so
on.

All these special regulations make it very difficult to
write such a routine.
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top