By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,744 Members | 1,830 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,744 IT Pros & Developers. It's quick & easy.

Checking for daylight saving

P: n/a
I was investigating a function to determine whether daylight saving
was being observed on a particular date (given the platform's regional
settings) and came across a suggestion at merlyn.com to test the time
zone offset on a variety of dates to see if it changes. Based on
that, I developed the following checkDST() function which, as far as I
can tell, should be sufficient.

It checks either the date passed to it or the current date with 3
other dates, each 3 months further into the future. If any of their
time zones differs from the epoch then either:

true - daylight saving is being observed on the date, or

false - daylight saving is observed but not on the date

are returned. If no difference is found, undefined is returned. I
explicitly return undefined as a matter of style rather than let the
loop peter out and return undefined by default.

Can anyone suggest whether the algorithm is appropriate and if my
implementation is OK? It will fail if there are changes to time zone
offsets that are not related to daylight saving, and if changes occur
for a period of less than 3 months and fall within the dates tested.

As far as I know, there isn't anywhere that does that, but they might
be accommodated by an "acceptable range" test (say allow changes of up
to 5 minutes) and checking for symmetry - if the time zone is
different in x months time, check if it was also different (12 - x)
months ago, and check if it differed by the same amount taking into
consideration the acceptable range.
function checkDST(d) {

d = d || new Date();

var x = new Date(d);
var dt = d.getTimezoneOffset();
var xt;

for (var i=0; i<3; i++) {
x.setMonth(x.getMonth() + 3)
xt = x.getTimezoneOffset();

if (dt != xt) {
return dt < xt;
}
}
return undefined;
}

function showDST(){

var x = isDST(new Date());
var msg;

if (x === true) {
msg = 'Daylight saving is observed here ' +
'and is in force.';
} else if (x === false) {
msg = 'Daylight saving is observed here, ' +
'but not at the moment.';
} else {
msg = 'Daylight saving is not observed here at all.'
}
alert(x + ': ' + msg);
}

showDST();

--
Rob
Dec 20 '07 #1
Share this Question
Share on Google+
27 Replies


P: n/a
RobG said the following on 12/20/2007 1:27 AM:

<snip>
function checkDST(d) {
<snip>
function showDST(){

var x = isDST(new Date());
isDST is not defined. FF2.0
Object Expected. IE7.

Long day today?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 20 '07 #2

P: n/a
On Dec 20, 4:45 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
RobG said the following on 12/20/2007 1:27 AM:

<snip>
function checkDST(d) {

<snip>
function showDST(){
var x = isDST(new Date());
That should of course be:

var x = checkDST(new Date());
>
isDST is not defined. FF2.0
Object Expected. IE7.

Long day today?
:-x bugger...
I changed the name of the function just before posting - does it work
for you? I can't mess with my regional settings for a little while
yet, I'll test it more when I can.
--
Rob

Dec 20 '07 #3

P: n/a
RobG said the following on 12/20/2007 2:01 AM:
On Dec 20, 4:45 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
>RobG said the following on 12/20/2007 1:27 AM:

<snip>
>>function checkDST(d) {
<snip>
>>function showDST(){
var x = isDST(new Date());

That should of course be:

var x = checkDST(new Date());
I changed the name of the function.
>isDST is not defined. FF2.0
Object Expected. IE7.

Long day today?

:-x bugger...
I changed the name of the function just before posting - does it work
for you? I can't mess with my regional settings for a little while
yet, I'll test it more when I can.
I tested it for about 5 minutes fooling with the date on my computer. I
never did change any time zone settings. I can only tell you that it got
it right for my location.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 20 '07 #4

P: n/a
Response to Randy Webb <Hi************@aol.com>:
I tested it for about 5 minutes fooling with the date on my
computer. I never did change any time zone settings. I can only
tell you that it got it right for my location.
I don't suppose something like this would help?

<URL: http://www.nirsoft.net/utils/run_as_date.html>

....most likely not, but it came to mind.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Dec 20 '07 #5

P: n/a
-Lost said the following on 12/20/2007 3:41 AM:
Response to Randy Webb <Hi************@aol.com>:
>I tested it for about 5 minutes fooling with the date on my
computer. I never did change any time zone settings. I can only
tell you that it got it right for my location.

I don't suppose something like this would help?

<URL: http://www.nirsoft.net/utils/run_as_date.html>

...most likely not, but it came to mind.
Not for what Rob is wanting to test. The only way to know if it is
getting it correct in different time zones is to change the time zone
settings. It is just as trivial to do that for testing as changing the
time/date. I just didn't do it when I was testing. Right click the clock
on the taskbar in Windows>Adjust Date and Time>Time Zone tab. Change it,
apply it, test it, repeat. There is also a setting there for
automatically changing the time for DST. With it unchecked, the test
gives incorrect results for me when testing my own time zone.

"undefined: Daylight saving is not observed here at all. "

And that is in Eastern Standard Time Zone in the US.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 20 '07 #6

P: n/a
Randy Webb wrote on 20 dec 2007 in comp.lang.javascript:
Not for what Rob is wanting to test. The only way to know if it is
getting it correct in different time zones is to change the time zone
settings. It is just as trivial to do that for testing as changing the
time/date. I just didn't do it when I was testing. Right click the
clock on the taskbar in Windows>Adjust Date and Time>Time Zone tab.
Change it, apply it, test it, repeat. There is also a setting there
for automatically changing the time for DST. With it unchecked, the
test gives incorrect results for me when testing my own time zone.

"undefined: Daylight saving is not observed here at all. "

And that is in Eastern Standard Time Zone in the US.
This should work, IMHO:

<script type='text/javascript'>

var d1 = new Date(2007,0,1).getTimezoneOffset()
var d2 = new Date(2007,6,1).getTimezoneOffset()

var t = 'This computer is set for a zone with'

if (d1==d2)
alert(t + 'out summertime offset');
else if (d1>d2)
alert(t + ' summertime offset in Northern hemisphere');
else
alert(t + ' summertime offset in Southern hemisphere');

</script>

IE7 and Central European Time Zone tested.

That such offset saves daylight is absolute nonsense,
though it may save energy consumption.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 20 '07 #7

P: n/a
Evertjan. said the following on 12/20/2007 4:59 PM:
Randy Webb wrote on 20 dec 2007 in comp.lang.javascript:
>Not for what Rob is wanting to test. The only way to know if it is
getting it correct in different time zones is to change the time zone
settings. It is just as trivial to do that for testing as changing the
time/date. I just didn't do it when I was testing. Right click the
clock on the taskbar in Windows>Adjust Date and Time>Time Zone tab.
Change it, apply it, test it, repeat. There is also a setting there
for automatically changing the time for DST. With it unchecked, the
test gives incorrect results for me when testing my own time zone.

"undefined: Daylight saving is not observed here at all. "

And that is in Eastern Standard Time Zone in the US.

This should work, IMHO:

<script type='text/javascript'>

var d1 = new Date(2007,0,1).getTimezoneOffset()
var d2 = new Date(2007,6,1).getTimezoneOffset()

var t = 'This computer is set for a zone with'

if (d1==d2)
alert(t + 'out summertime offset');
else if (d1>d2)
alert(t + ' summertime offset in Northern hemisphere');
else
alert(t + ' summertime offset in Southern hemisphere');

</script>

IE7 and Central European Time Zone tested.
It tells me I have a summertime offset in Northern hemisphere, but, it
doesn't tell me whether I use Daylight Savings Time or not. No setting
on the PC can either. Arizona, USA, is split on DST. Parts of the state
use it and parts don't. Indiana was another state that just recently
started using it.
That such offset saves daylight is absolute nonsense,
though it may save energy consumption.
It doesn't "save daylight", it just changes the hours in the day when it
is there. Personally, I wish they would just do away with the entire
concept as it is a broken phenomenon now.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '07 #8

P: n/a
Response to Randy Webb <Hi************@aol.com>:
>That such offset saves daylight is absolute nonsense,
though it may save energy consumption.

It doesn't "save daylight", it just changes the hours in the day
when it is there. Personally, I wish they would just do away with
the entire concept as it is a broken phenomenon now.
Same here. Halfway through the week (this past DST change) we kept
wondering why no one updated their clocks and come to find out we were
the dummies.

Why in the world did Congress or whoever change that at the last moment
anyway?

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Dec 21 '07 #9

P: n/a
Response to Randy Webb <Hi************@aol.com>:
You can get to it without going into the Control Panel but it
changes it in the same place. Right click the clock on the Windows
Taskbar>Adjust Date/Time.
Or double-click.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Dec 21 '07 #10

P: n/a
-Lost said the following on 12/20/2007 9:24 PM:
Response to Randy Webb <Hi************@aol.com>:
>>That such offset saves daylight is absolute nonsense,
though it may save energy consumption.
It doesn't "save daylight", it just changes the hours in the day
when it is there. Personally, I wish they would just do away with
the entire concept as it is a broken phenomenon now.

Same here. Halfway through the week (this past DST change) we kept
wondering why no one updated their clocks and come to find out we were
the dummies.

Why in the world did Congress or whoever change that at the last moment
anyway?
<shrugWhy do politicians do any of the things they do?

One reason I read (and don't know if it is true or not) is:

A new law to extend DST to the first Sunday in November will take effect
in 2007, with the purpose of providing trick-or-treaters more light and
therefore more safety from traffic accidents.

Go figure.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '07 #11

P: n/a
Response to Randy Webb <Hi************@aol.com>:
>Why in the world did Congress or whoever change that at the last
moment anyway?

<shrugWhy do politicians do any of the things they do?
Heh, fair point.
One reason I read (and don't know if it is true or not) is:

A new law to extend DST to the first Sunday in November will take
effect in 2007, with the purpose of providing trick-or-treaters
more light and therefore more safety from traffic accidents.

Go figure.
Well, anything to make us think they care I suppose.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Dec 21 '07 #12

P: n/a
Randy Webb wrote on 21 dec 2007 in comp.lang.javascript:
-Lost said the following on 12/20/2007 9:24 PM:
>Why in the world did Congress or whoever change that at the last moment
anyway?
What congress?

Do you mean 'congress' in the sense of the Kamasutra
and changing a stand of such congress at the last moment?

Wouldn't that put you off, Lost?
<shrugWhy do politicians do any of the things they do?

One reason I read (and don't know if it is true or not) is:

A new law to extend DST to the first Sunday in November will take effect
in 2007, with the purpose of providing trick-or-treaters more light and
therefore more safety from traffic accidents.
What law?

Is that what politicians do, Randy, changing a stand at the last moment?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 21 '07 #13

P: n/a
Evertjan. said the following on 12/21/2007 3:43 AM:
Randy Webb wrote on 21 dec 2007 in comp.lang.javascript:
>-Lost said the following on 12/20/2007 9:24 PM:
>>Why in the world did Congress or whoever change that at the last moment
anyway?

What congress?
You have been reading too much JRS.
Do you mean 'congress' in the sense of the Kamasutra
and changing a stand of such congress at the last moment?

Wouldn't that put you off, Lost?
No, not Kamasutra, it was the World Congress of Politicians.
><shrugWhy do politicians do any of the things they do?

One reason I read (and don't know if it is true or not) is:

A new law to extend DST to the first Sunday in November will take effect
in 2007, with the purpose of providing trick-or-treaters more light and
therefore more safety from traffic accidents.

What law?
The one that extended DST to the first Sunday in November in the USA.
Is that what politicians do, Randy, changing a stand at the last moment?
I am not even sure that politicians know what politicians do. I do know
they can screw up something that should be trivially simple.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '07 #14

P: n/a
Randy Webb wrote on 21 dec 2007 in comp.lang.javascript:
It should. It has a setting to let Windows change the time for you. By
law, in the USA, it always starts and ends on the same days every
year, no matter what zone you are in in the USA, if you use it.
That gives two nights that this offset is rippling though your continent,
and must be terrible for large organisations like radio/tv.

The European law switching at the same time across all timezones is
slightly better.
>Does the London local setting know about the "double summertime" of
WWII?

No idea.
In general, MS-windows zones surely cannot fill in the historical patchwork
of summertime regions.

<http://en.wikipedia.org/wiki/Daylight_saving_time>
points to an European viewpoint:

Guess whose!

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 21 '07 #15

P: n/a
In comp.lang.javascript message <xJ*********************@giganews.com>,
Thu, 20 Dec 2007 14:15:01, Randy Webb <Hi************@aol.composted:
>
Not for what Rob is wanting to test. The only way to know if it is
getting it correct in different time zones is to change the time zone
settings.
But can one be certain, in Windows, that such a temporary change cannot
possibly have a lasting adverse effect, such as but not limited to
entries in calendar/diary software and limited-duration software that
looks for time reversal or performing scheduled activity?
It is just as trivial to do that for testing as changing the
time/date. I just didn't do it when I was testing. Right click the
clock on the taskbar in Windows>Adjust Date and Time>Time Zone tab.
Change it, apply it, test it, repeat. There is also a setting there for
automatically changing the time for DST. With it unchecked, the test
gives incorrect results for me when testing my own time zone.

"undefined: Daylight saving is not observed here at all. "

And that is in Eastern Standard Time Zone in the US.
Well, if DST is turned off one must expect it not to be found.
Obviously great care must be taken with the wording of such messages.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Dec 21 '07 #16

P: n/a
Dr J R Stockton said the following on 12/21/2007 7:58 AM:
In comp.lang.javascript message <xJ*********************@giganews.com>,
Thu, 20 Dec 2007 14:15:01, Randy Webb <Hi************@aol.composted:
>Not for what Rob is wanting to test. The only way to know if it is
getting it correct in different time zones is to change the time zone
settings.

But can one be certain, in Windows, that such a temporary change cannot
possibly have a lasting adverse effect, such as but not limited to
entries in calendar/diary software and limited-duration software that
looks for time reversal or performing scheduled activity?
Guess it would depend on how the software was doing the checks. I have
never run into a problem temporarily changing my clock/TZ settings and
then setting them back. But, I don't do anything but quick tests while
they are changed.
>It is just as trivial to do that for testing as changing the
time/date. I just didn't do it when I was testing. Right click the
clock on the taskbar in Windows>Adjust Date and Time>Time Zone tab.
Change it, apply it, test it, repeat. There is also a setting there for
automatically changing the time for DST. With it unchecked, the test
gives incorrect results for me when testing my own time zone.

"undefined: Daylight saving is not observed here at all. "

And that is in Eastern Standard Time Zone in the US.

Well, if DST is turned off one must expect it not to be found.
I didn't turn of DST, all I did was tell Windows not to automatically
set my clock back.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 21 '07 #17

P: n/a
Evertjan. wrote:
Randy Webb wrote on 20 dec 2007 in comp.lang.javascript:
>Not for what Rob is wanting to test. The only way to know if it is
getting it correct in different time zones is to change the time zone
settings.[snip]
Ok - so you *do* all know this is a waste of time don't you? There is
one and only one way to do it. You get the user to state explicitly
what time zone they are in, then you check the *actual* date and time
in that time zone (not the one on the PC - so you will need a remote
time-server somewhere) and then you apply the rules in force in that
specific time zone.

And anyone who wants to do that in Javascript is completely insane!

You have one - count them - *one* choice only. Find a way to ask the
operating system and presume the operating system has the time zone
details *and* rules set as the user wants them. Then check a remote
time-server. Even then, it may not be correct because, of course, the
user may choose to set his or her PC to - let's say - GMT because he
likes to do amateur astronomy and it makes it easier.
Dec 21 '07 #18

P: n/a
In comp.lang.javascript message <MJ*********************@giganews.com>,
Thu, 20 Dec 2007 22:49:47, Randy Webb <Hi************@aol.composted:
>-Lost said the following on 12/20/2007 9:24 PM:
>Response to Randy Webb <Hi************@aol.com>:
>>>That such offset saves daylight is absolute nonsense,
though it may save energy consumption.
It doesn't "save daylight", it just changes the hours in the day
when it is there. Personally, I wish they would just do away with
the entire concept as it is a broken phenomenon now.
Same here. Halfway through the week (this past DST change) we kept
wondering why no one updated their clocks and come to find out we were
the dummies.
Why in the world did Congress or whoever change that at the last
moment anyway?

<shrugWhy do politicians do any of the things they do?

One reason I read (and don't know if it is true or not) is:

A new law to extend DST to the first Sunday in November will take
effect in 2007, with the purpose of providing trick-or-treaters more
light and therefore more safety from traffic accidents.

You can find the exact wording on the Web at a USG-type site.
You can find the URL of it in my <uksumtim.htm>, where you can also find
the exact words in a format similar to that of USG.

Try putting congress daylight saving H.R.6 in an IE address bar and
then using Go .

Did you know that the next day on which a Congressional, but not a
Presidential, election will be held in the USA will be (except maybe in
Arizona and Hawaii) in Summer Time?

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Dec 21 '07 #19

P: n/a
In comp.lang.javascript message <Fo*********************@giganews.com>,
Fri, 21 Dec 2007 05:22:22, Randy Webb <Hi************@aol.composted:
>Evertjan. said the following on 12/21/2007 3:33 AM:
>Randy Webb wrote on 21 dec 2007 in comp.lang.javascript:
>>>IE7 and Central European Time Zone tested.
It tells me I have a summertime offset in Northern hemisphere, but, it
doesn't tell me whether I use Daylight Savings Time or not. No setting
on the PC can either. Arizona, USA, is split on DST. Parts of the
state use it and parts don't. Indiana was another state that just
recently started using it.
Do you mean if you are using summertime offset at present?

No, whether the location I am in observes Daylight Savings Time. If you
look in Windows XP (not sure what other Win OS'es have it), in the Date
and Time Properties>Time Zone tab, there is an explicit setting for
Indiana(East). That is because Indiana, USA did not use DST for a long
time. You won't find a setting for Arizona, USA, in that list. Yet,
there are parts of Arizona that do, and parts that do not, use Daylight
Savings Time. Yet, the Time Zone is the same whether they use it or
not. The OS has no way of knowing that.
There is no way of telling the exact location, so in Arizona it cannot
as supplied know whether the location has DST or not. That is why
there's a checkbox in XP for turning it on & off.

Windows, if MS does its job right (Win98 got it wrong) knows current UK
Summer Time rules, and has checked the box in installation If I uncheck
it, the machine will show UT (GMT) permanently, as it would if I set
Reykjavik.

>How would it be "even more terrible" if there were no such thing as
Daylight Savings Time?
>Does it know when this summertime concept started in each zone?

It should.
It does not; except that Vista can know of the most recent change, which
*could* be when it was first used in a location (not a zone). Labrador
and Chile are in the same time zone; but would use opposite Summer Time
changes.
It has a setting to let Windows change the time for you. By law, in
the USA, it always starts and ends on the same days every year, no
matter what zone you are in in the USA, if you use it.
The same days? The dates vary, being 0-6 days before -03-14 &-11-07.
They're (very probably) not even always the same ISO 8601 yyyy-Www-d
(there will be 2 possible values for ww).
>Does the London local setting know about the "double summertime" of WWII?
It will not; and if it did Javascript would not be allowed to use that
unless the system date was set back to WWII.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Dec 21 '07 #20

P: n/a
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Fri, 21 Dec 2007 17:17:00, Evertjan. <ex**************@interxnl.net>
posted:
>Randy Webb wrote on 21 dec 2007 in comp.lang.javascript:
>It should. It has a setting to let Windows change the time for you. By
law, in the USA, it always starts and ends on the same days every
year, no matter what zone you are in in the USA, if you use it.
Canada is more liberal there; the provinces decide. AFAIK they've
"always" used the US dates, but with some variation in time.

>That gives two nights that this offset is rippling though your continent,
and must be terrible for large organisations like radio/tv.
AIUI, they have comparatively little of that sort of thing. However,
the Russians, with 11(?) zones, know what to do; and likewise the
Australians, if they ripple-change.

There'll be problems when all of Russia joins the EU; either there'll be
a break-in-system, or in Kamchatka they'll change clocks after Monday
breakfast.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "" (SonOfRFC1036)
Dec 21 '07 #21

P: n/a
In comp.lang.javascript message <lv*********************@giganews.com>,
Thu, 20 Dec 2007 20:59:05, Randy Webb <Hi************@aol.composted:
>Dr J R Stockton said the following on 12/20/2007 5:40 PM:
>In comp.lang.javascript message <ecae4e75-9e61-4aa0-90ab-6c10978d781e@d4
g2000prg.googlegroups.com>, Wed, 19 Dec 2007 22:27:46, RobG
<rg***@iinet.net.auposted:
>>It checks either the date passed to it or the current date with 3
other dates, each 3 months further into the future.
Checking the date in question, and January 1st, and July 1st, should
suffice - unless someone does something silly with Summer Time.

It doesn't take anything that naive to fool it. Simply telling my PC
not to change the time for me is enough to cause Rob's function to give
incorrect results.
If you lie to your machine, you must be ready to receive lies back. Rob
may need more subtle wording.
>>Can anyone suggest whether the algorithm is appropriate and if my
implementation is OK? It will fail if there are changes to time zone
offsets that are not related to daylight saving, and if changes occur
for a period of less than 3 months and fall within the dates tested.
ISO/IEC 16262 requires that the CURRENT Summer Time rules are
applied
for ALL years. Most OSs only know one set of rules per location, but
AIUI Vista knows up to 2 sets, and changes.
US legislation, IIRC, changed the rules with effect from 2007-03-01
(presumably local time; possibly DC time). Therefore, Randy et al
should have stopped running Javascript on pre-Vista PCs before
2007-02-28 24:00 LCT, should have updated their systems, and not
restarted Javascript before 2007-03-01 00:00 LCT.

What US legislation also does is make it a local decision as to whether
it is used or not. Witness Arizona in the USA.
Yes, and that power did not change.

I know of no US legislation on the date at which a location can change
from one rule set to another, as (much of?) Indiana did. H.R.6
stipulated 2007-03-01, maybe without fullest consideration.
>I don't know whether Vista does it right.
Some systems, IIRC, using UNIX, get the OS to do date work that
Javascript ought to do; in that case, the wrong (by 16262) rules or zone
may be applied to non-current dates.
I recall no provision for changing time zone at a location, other
than
by the Control Panel settings.

You can get to it without going into the Control Panel but it changes
it in the same place. Right click the clock on the Windows
Taskbar>Adjust Date/Time.

Yes, but that's merely another route to the same settings.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/- FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Dec 21 '07 #22

P: n/a
Dr J R Stockton said the following on 12/21/2007 5:24 PM:
In comp.lang.javascript message <lv*********************@giganews.com>,
Thu, 20 Dec 2007 20:59:05, Randy Webb <Hi************@aol.composted:
>Dr J R Stockton said the following on 12/20/2007 5:40 PM:
>>In comp.lang.javascript message <ecae4e75-9e61-4aa0-90ab-6c10978d781e@d4
g2000prg.googlegroups.com>, Wed, 19 Dec 2007 22:27:46, RobG
<rg***@iinet.net.auposted:
>>>It checks either the date passed to it or the current date with 3
other dates, each 3 months further into the future.
Checking the date in question, and January 1st, and July 1st, should
suffice - unless someone does something silly with Summer Time.
It doesn't take anything that naive to fool it. Simply telling my PC
not to change the time for me is enough to cause Rob's function to give
incorrect results.

If you lie to your machine, you must be ready to receive lies back. Rob
may need more subtle wording.
I didn't lie to my machine. I simply told it not to automatically change
the time. I didn't tell it to ignore Daylight Savings Time. If the
checkbox were labeled "Use Daylight Savings Time" then it would be more
indicative of what the user wanted. I still wouldn't be lying to the
machine though.

<snip>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 22 '07 #23

P: n/a
Dr J R Stockton wrote on 21 dec 2007 in comp.lang.javascript:
>>That gives two nights that this offset is rippling though your continent,
and must be terrible for large organisations like radio/tv.

AIUI, they have comparatively little of that sort of thing. However,
the Russians, with 11(?) zones, know what to do; and likewise the
Australians, if they ripple-change.

There'll be problems when all of Russia joins the EU; either there'll be
a break-in-system, or in Kamchatka they'll change clocks after Monday
breakfast.
Not having to get out of bed is such cold places could be a bonus,
someyears I did the same.

What about Vladiwostok?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 22 '07 #24

P: n/a
In comp.lang.javascript message <iu*********************@giganews.com>,
Fri, 21 Dec 2007 13:51:12, Randy Webb <Hi************@aol.composted:
>I didn't turn of DST, all I did was tell Windows not to automatically
set my clock back.

That is what the label said. It is not necessarily what it ought to
have said.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

Dec 22 '07 #25

P: n/a
Dr J R Stockton said the following on 12/22/2007 12:27 PM:
In comp.lang.javascript message <iu*********************@giganews.com>,
Fri, 21 Dec 2007 13:51:12, Randy Webb <Hi************@aol.composted:
>I didn't turn of DST, all I did was tell Windows not to automatically
set my clock back.


That is what the label said. It is not necessarily what it ought to
have said.
And I agree with that. But, changing it is not lying to the machine.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 22 '07 #26

P: n/a
Dr J R Stockton wrote on 22 dec 2007 in comp.lang.javascript:
I occasionally, as you may have noticed, change pieces of my date code
from local to UTC.
I think, as you may have guessed, that JS Date()'s UTC support is a mess.

It would have been better to have all methods have a attribute
having them interact directly with the internal UTC date/time value of
any Date() object.

dateObj.getDate('UTC')
in stead of
dateObj.getUTCDate()
etc.

That way we could define functions,
that would work both for local time as for UTC:

function manipulateTimeDate(myDate,UTCorNot) {
.....;
.....;
return myDate.getUTCDate(UTCorNot);
};

var nrDate = manipulateTimeDate(thatDate);

var UTCnrDate = manipulateTimeDate(thatDate,'UTC');

====================================

btw, ever replied upon this in MS scripting 5.6?

===========
dateObj.getVarDate()

Remarks
The required dateObj reference is a Date object.

The getVarDate method is used when interacting with COM objects, ActiveX®
objects or other objects that accept and return date values in VT_DATE
format, such as Visual Basic and VBScript.

The actual format is dependent on regional settings and should not be
replied upon within JScript.
============

"replied upon" ??

MS-JS being unreplyable, MS seems to have a lot to answer for.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Dec 23 '07 #27

P: n/a
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Sun, 23 Dec 2007 08:51:54, Evertjan. <ex**************@interxnl.net>
posted:
>Dr J R Stockton wrote on 22 dec 2007 in comp.lang.javascript:
>I occasionally, as you may have noticed, change pieces of my date code
from local to UTC.

I think, as you may have guessed, that JS Date()'s UTC support is a mess.

It would have been better to have all methods have a attribute
having them interact directly with the internal UTC date/time value of
any Date() object.
Or maybe for every Date Object to have a property that made it work
either in UTC or in LCT?
>That way we could define functions,
that would work both for local time as for UTC:
Note that an algorithm correct for all LCT is correct for UTC (because
sometimes LTC is UTC), but an algorithm correct for UTC is not
necessarily correct for all LTC.

>dateObj.getVarDate()
I know it exists in IE6 & IE7, but I've never investigated what it is
for. <js-date0.htmrefers.
>"replied upon" ??
Indeed - relied upon?
Opera is 9.25.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Dec 23 '07 #28

This discussion thread is closed

Replies have been disabled for this discussion.