473,574 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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().getFullY ear()
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.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.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 3688
"Dr John Stockton" <jr*@merlyn.dem on.co.uk> wrote in message
news:3M******** ******@merlyn.d emon.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().getFullY ear()
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().getFullY ear()
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.or g/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.dem on.co.uk> wrote in message
news:3M******** ******@merlyn.d emon.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().getFullY ear()
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 shortsightednes s. ;-)

[...]
--
Rob
Oct 7 '05 #4
JRS: In article <Mv************ ********@comcas t.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.dem on.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().getFullY ear()
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.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.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.optu s.net.au>, dated Fri, 7
Oct 2005 06:32:56, seen in news:comp.lang. javascript, RobG
<rg***@iinet.ne t.au> posted :
McKirahan wrote:
"Dr John Stockton" <jr*@merlyn.dem on.co.uk> wrote in message
news:3M******** ******@merlyn.d emon.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().getFullY ear()
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 shortsightednes s. ;-)


Your shortsightednes s : 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.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Oct 7 '05 #6
JRS: In article <Dl************ *****@news.optu s.net.au>, dated Fri, 7
Oct 2005 06:12:51, seen in news:comp.lang. javascript, RobG
<rg***@iinet.ne t.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().getFullY ear()
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.or g/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.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.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
11192
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) on the server because of that. Our site will have an SSL certificate next week, so I would like to use AIM instead of SIM, however, I don't know how...
2
5788
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 to execute the code until the browser send his reply to the header instruction. So an exit(); after each redirection won't hurt at all
3
22982
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 field is completed.
0
8455
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. 354 roberto@ausone:Build/php-4.3.2> ldd /opt/php4/bin/php libsablot.so.0 => /usr/local/lib/libsablot.so.0 libstdc++.so.5 => ...
1
8558
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 column below. The viewer can select states from the drop down lists above the other two columns as well. If the viewer selects only one, only one...
4
18233
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 user comes back to a page where he had a submitted POST data the browser keeps telling that the data has expired and asks if repost. How to avoid...
1
6793
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 http://www.mis.gla.ac.uk/biquery/training/ but each of the courses held have maximum of 8 people that could be
2
31367
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 to :parameter I dont like the idea of making the SQL statement on the fly without binding parameters as I dont want a highly polluted SQL cache.
3
23551
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 results of the picture half the size. The PHP I have installed support 1.62 or higher. And all I would like to do is take and image and make it fit a...
0
7719
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8044
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7808
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6450
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5299
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3749
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.