473,386 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DST

After December and before 2100, the following should determine the start
and finish dates of local US DST in the current year.
CHECK !!! TEST !!!

Y = new Date().getFullYear()
DSTON = /* March */ Y==2006 ? 33 : T = 14 - (((5*Y/4)|0) + 1) % 7
DSTOFF = /* November */ Y==2006 ? -2 : T - 7
X = [new Date(Y, 2, DSTON, 2), new Date(Y, 10, DSTOFF, 2)]

There may be an error within an hour of the critical moment.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
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.
Oct 6 '05 #1
6 3677
"Dr John Stockton" <jr*@merlyn.demon.co.uk> wrote in message
news:3M**************@merlyn.demon.co.uk...
After December and before 2100, the following should determine the start
and finish dates of local US DST in the current year.
CHECK !!! TEST !!!

Y = new Date().getFullYear()
DSTON = /* March */ Y==2006 ? 33 : T = 14 - (((5*Y/4)|0) + 1) % 7
DSTOFF = /* November */ Y==2006 ? -2 : T - 7
X = [new Date(Y, 2, DSTON, 2), new Date(Y, 10, DSTOFF, 2)]

There may be an error within an hour of the critical moment.

Before 2100 ... try 2007!

More Daylight Savings: Energy Boon or Scheduling Snafu?
http://news.nationalgeographic.com/n..._daylight.html

"clock changes would actually take effect in 2007."

"The bill calls for daylight savings to begin three weeks earlier,
on the second Sunday in March, and to end on the first Sunday
in November, one week later than daylight saving time currently does."
Oct 7 '05 #2
Dr John Stockton wrote:
After December and before 2100, the following should determine the start
and finish dates of local US DST in the current year.
CHECK !!! TEST !!!

Y = new Date().getFullYear()
DSTON = /* March */ Y==2006 ? 33 : T = 14 - (((5*Y/4)|0) + 1) % 7
DSTOFF = /* November */ Y==2006 ? -2 : T - 7
X = [new Date(Y, 2, DSTON, 2), new Date(Y, 10, DSTOFF, 2)]

There may be an error within an hour of the critical moment.


Seems to work OK (1987 and onward), but why make your code so difficult
to decipher?

Given the frequency of change and probable need for it to be modified
for a great variety dates, there is a strong need for code that is
portable and easily maintained. It should also handle date ranges that
span New Year.

The wikipedia daylight saving entry is:

<URL:http://en.wikipedia.org/wiki/Daylight_Saving_Time>

The examples below should help.
/* Changeover to and from US DST occurs at 0200 hrs (2:00 am)
* on the following days:
*
* 1987 to 2006 inclusive:
* 1st Sunday in April to last Sunday in October
*
* 2007 onward (until next change...):
* 2nd Sunday in March to first Sunday in November
*
* Note that there have been many changes to the start days for
* DST - see:
* http://aa.usno.navy.mil/faq/docs/daylight_time.html
* http://www.energy.ca.gov/daylightsaving.html
*/
function DSTdatesUS( yr )
{
if ( yr<1987 ) return; // Outside range

// Work out last possible on/off date
var don = (yr<2007)? 38 : 14;
var dof = (yr<2007)? 31 : 38;

// Create initial on/off date objects
var DSTon = new Date(yr, 2, don, 2);
var DSToff = new Date(yr, 9, dof, 2);

// Adjust to Sunday before last possible date (adjustment may be 0)
DSTon.setDate( DSTon.getDate() - DSTon.getDay() );
DSToff.setDate( DSToff.getDate() - DSToff.getDay() );

return [DSTon, DSToff];
}
/* Australian Eastern Daylight Saving Time (AEDST) [on, off]
*
* Since 2001, the changeover to AEDST occurs at 0200 hrs (2:00 am)
* on the last Sunday in October and finishes at 0200 hrs on the
* last Sunday in March the following year.
*
* Note: Of the states 4 states in the AEST time zone, there are 2
* different ranges for daylight saving and one state that doesn't
* observe it at all. Start and end dates vary frequently.
*
* Legislation is before the NSW govt to extend the end of DST in 2006
* by one week.
*
* yr is the start year.
*/
function DSTdatesAEDST( yr )
{
if ( yr<2001 ) return; // Outside range

// Initially set to last possible on/off dates
var don = 31;
var dof = 31;
// If legislation passes, NSW DST extends by 7 days in 05/06
if (2005 == yr ) dof += 7;

// Create initial on/off date objects
var DSTon = new Date(yr, 9, don, 2);
var DSToff = new Date(yr, 14, dof, 2);

// Adjust to Sunday before last possible date (adjustment may be 0)
DSTon.setDate( DSTon.getDate() - DSTon.getDay() );
DSToff.setDate( DSToff.getDate() - DSToff.getDay() );

return [DSTon, DSToff];
}
--
Rob
Oct 7 '05 #3
McKirahan wrote:
"Dr John Stockton" <jr*@merlyn.demon.co.uk> wrote in message
news:3M**************@merlyn.demon.co.uk...
After December and before 2100, the following should determine the start
and finish dates of local US DST in the current year.
CHECK !!! TEST !!!

Y = new Date().getFullYear()
DSTON = /* March */ Y==2006 ? 33 : T = 14 - (((5*Y/4)|0) + 1) % 7
DSTOFF = /* November */ Y==2006 ? -2 : T - 7
X = [new Date(Y, 2, DSTON, 2), new Date(Y, 10, DSTOFF, 2)]

There may be an error within an hour of the critical moment.


Before 2100 ... try 2007!


I think that is JRS humour.

John's code handles the 2007 change but assumes that every year evenly
divisible by 4 is a leap year. Since 2100 isn't a leap year even though
2100%4 = 0, from 2100 onward the code reports changes as occurring on
Saturdays, not Sundays.

Likely John thought that DST changeover rules will be modified before
then, so his code will need to be changed anyway - or his heirs may be
imposed upon to account for his shortsightedness. ;-)

[...]
--
Rob
Oct 7 '05 #4
JRS: In article <Mv********************@comcast.com>, dated Fri, 7 Oct
2005 00:24:01, seen in news:comp.lang.javascript, McKirahan
<Ne**@McKirahan.com> posted :
"Dr John Stockton" <jr*@merlyn.demon.co.uk> wrote in message
news:3M**************@merlyn.demon.co.uk...
After December and before 2100, the following should determine the start
and finish dates of local US DST in the current year.
CHECK !!! TEST !!!

Y = new Date().getFullYear()
DSTON = /* March */ Y==2006 ? 33 : T = 14 - (((5*Y/4)|0) + 1) % 7
DSTOFF = /* November */ Y==2006 ? -2 : T - 7
X = [new Date(Y, 2, DSTON, 2), new Date(Y, 10, DSTOFF, 2)]

There may be an error within an hour of the critical moment.

Before 2100 ... try 2007!

More Daylight Savings: Energy Boon or Scheduling Snafu?
http://news.nationalgeographic.com/n..._daylight.html

"clock changes would actually take effect in 2007."

"The bill calls for daylight savings to begin three weeks earlier,
on the second Sunday in March, and to end on the first Sunday
in November, one week later than daylight saving time currently does."


My code gives results suitable for determining the current state of DST
from after the first Sunday in November 2005 until some time in March
2100, assuming no new legislation. The algorithm is derived from one at
webexhibits, verified and adapted.

You need to learn to think, and to test, before you write; the time that
you waste is mostly that of others.

So does National Geographic, since the second Sunday in March is only
three weeks earlier than the first Sunday in April; about half the time.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
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.
Oct 7 '05 #5
JRS: In article <sE*****************@news.optus.net.au>, dated Fri, 7
Oct 2005 06:32:56, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.au> posted :
McKirahan wrote:
"Dr John Stockton" <jr*@merlyn.demon.co.uk> wrote in message
news:3M**************@merlyn.demon.co.uk...
After December and before 2100, the following should determine the start
and finish dates of local US DST in the current year.
CHECK !!! TEST !!!

Y = new Date().getFullYear()
DSTON = /* March */ Y==2006 ? 33 : T = 14 - (((5*Y/4)|0) + 1) % 7
DSTOFF = /* November */ Y==2006 ? -2 : T - 7
X = [new Date(Y, 2, DSTON, 2), new Date(Y, 10, DSTOFF, 2)]

There may be an error within an hour of the critical moment.

Before 2100 ... try 2007!


I think that is JRS humour.

John's code handles the 2007 change but assumes that every year evenly
divisible by 4 is a leap year. Since 2100 isn't a leap year even though
2100%4 = 0, from 2100 onward the code reports changes as occurring on
Saturdays, not Sundays.

Likely John thought that DST changeover rules will be modified before
then, so his code will need to be changed anyway - or his heirs may be
imposed upon to account for his shortsightedness. ;-)


Your shortsightedness : I wrote, as you quoted, "and before 2100".

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 7 '05 #6
JRS: In article <Dl*****************@news.optus.net.au>, dated Fri, 7
Oct 2005 06:12:51, seen in news:comp.lang.javascript, RobG
<rg***@iinet.net.au> posted :
Dr John Stockton wrote:
After December and before 2100, the following should determine the start
and finish dates of local US DST in the current year.
CHECK !!! TEST !!!

Y = new Date().getFullYear()
DSTON = /* March */ Y==2006 ? 33 : T = 14 - (((5*Y/4)|0) + 1) % 7
DSTOFF = /* November */ Y==2006 ? -2 : T - 7
X = [new Date(Y, 2, DSTON, 2), new Date(Y, 10, DSTOFF, 2)]

There may be an error within an hour of the critical moment.

Seems to work OK (1987 and onward), but why make your code so difficult
to decipher?


No, it does not work, and does not claim to work, for years before 2006.
For 1987-2006 :-
Begin April (07 - (5*y div 4 + 4) mod 7) at 02:00 local
End October (31 - (5*y div 4 + 1) mod 7) at 02:00 local

The point is that the day-of-month of the change, given constant rules
in 1900-2099, can easily be calculated by simple arithmetic (for
everywhere with the usual sort of rules); and that for US 2007+ DST, the
relationship between ON & OFF is particularly simple.

In 1900-2099, the javascript day-of-week of Christmas Day is just
Math.floor(5*y/4) % 7

Given the frequency of change and probable need for it to be modified
for a great variety dates, there is a strong need for code that is
portable and easily maintained. It should also handle date ranges that
span New Year.
Mine handles years correctly too; in AU/NZ, the rules for the dates in
the first and second halves of the year are given by similar rules, and
a simple XOR hemisphere will get the direction of the change right.

The wikipedia daylight saving entry is:

<URL:http://en.wikipedia.org/wiki/Daylight_Saving_Time>
Wiki is quite often right, or mostly right.

The examples below should help.
They rely on the javascript date object to determine the date; the
method I gave does not, and could be readily translated into other
languages, at least for after 2006, and could even be learned for doing
in one's head.

// If legislation passes, NSW DST extends by 7 days in 05/06
if (2005 == yr ) dof += 7;


That appears odd - extension only in 2005/06, or permanently from then?
The OFF date for 2005/06 is surely when 2006==yr ?
Has Canada or Mexico legislated to follow the USA?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
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.
Oct 7 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.