School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,503 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,885 people online right now. Registration is fast and FREE... Join Now!




Detecting DST or Daylight Saving Time in Flash ActionScript

 

Detecting DST or Daylight Saving Time in Flash ActionScript, simplify the obvious when it comes to detecting DST

simkiss

20 Apr, 2007 - 12:28 PM
Post #1

New D.I.C Head
*

Joined: 20 Apr, 2007
Posts: 6


My Contributions
I have been trying to figure out how to determine what time zone the user is in. However, when I use the code below, the hour offset and UTC changes with DST or Daylight Saving Time. I tried to make a forumla to calculate it, but when DST is in effect, my formula does not work. How can I detect if DST is in effect? ...or is there a time that does not change with DST that I can check against in ActionScript?

CODE


// FIGURE OUT TIME ZONE
hoursFromGMT = myTime.getTimezoneOffset()/60;
trace(hoursFromGMT);
hoursFromUTC = myTime.getUTCHours();
trace(hoursFromUTC);


trace results: 4, 20 (at 16:00 EDT), or
trace results: 5, 21 (at 16:00 EST)

The above is very simple. It's not my clock. It's just an illustration of how I'm trying to trace my time zone.
For example, I am in the Eastern Time Zone. So, during EST or Eastern Standard Time, hoursFromGMT = 5, but during EDT or Eastern Daylight Time, hoursFromGMT = 4. Therefore, I cannot say that if hoursFromGMT == 5 then I am in Eastern Time Zone, because during Eastern Daylight Time the value of hourFromGMT would be 4, thus the forumla would say that I'm in the Atlantic Time Zone.

Now, I could create a function to determine which day of the year it is, knowing ahead of time when DST goes into effect, check against that date, then shift the time zone accordingly, but that's a lot of code just to figure out if DST is in effect or not. There must be a simpler way such as...

CODE


zoneShifter = myTime.getDSTinEffectOrNot();
if zoneShifter = 0; {
    it's standard time;
    } else {
       it's daylight time;
    }
myNewTimeZone = hoursFromGMT + zoneShifter;



Any sort of trick would be helpful! also, if no shortcut is available, even with FLPro8, I would appreciate it someone could paste the code for a function to check to see if the current day is in the DST range. That is of course if you already have it. I'm not asking you to write it up just for me.

User is offlineProfile CardPM
+Quote Post


pioSko

RE: Detecting DST Or Daylight Saving Time In Flash ActionScript

21 Apr, 2007 - 02:19 AM
Post #2

still.dreaming
Group Icon

Joined: 6 Jun, 2003
Posts: 1,888



Thanked: 14 times
Dream Kudos: 225
My Contributions
QUOTE
Now, I could create a function to determine which day of the year it is, knowing ahead of time when DST goes into effect, check against that date, then shift the time zone accordingly, but that's a lot of code just to figure out if DST is in effect or not. There must be a simpler way such as...


Flash doesn't have any means of detecting if DST is in effect or not. Unfortunately, what you suggested may be the solution.

We've had a few questions recently about DST in Flash. Is there something we don't know?? lol

I've had this in my head since the first post came up and apart from using external scripts and writing a script to "brute force" it, I haven't found/thought of a different solution at the moment.
User is offlineProfile CardPM
+Quote Post

simkiss

RE: Detecting DST Or Daylight Saving Time In Flash ActionScript

23 Apr, 2007 - 06:04 AM
Post #3

New D.I.C Head
*

Joined: 20 Apr, 2007
Posts: 6


My Contributions
What I'm trying to accomplish is to have a countdown clock that shows how much time a visitor to our website has to call us based upon our business hours. I need to be able to calculate their time zone and if they are in DST so I can display the correct number of minutes left that we are open or even the number of minutes until we open again. I guess it's another day with me and ScriptAssist--my pal. cool.gif

Thanks for the post.
User is offlineProfile CardPM
+Quote Post

Khuffie

RE: Detecting DST Or Daylight Saving Time In Flash ActionScript

29 May, 2007 - 09:32 AM
Post #4

New D.I.C Head
*

Joined: 29 May, 2007
Posts: 1



Thanked: 1 times
My Contributions
While trying to google for a solution, I came across this post, and since I think I figured it out, I thought I'd come back and post here. Hopefully you have notifications set so you can see it!

Basically, the two assumptions I made are as follows:
- assume that during the summer period is when clocks are advanced by an hour (if they are)
- assume that July lies within this daylight savings period
- assume that January does NOT lie within this daylight savings period

I think the above assumptions are safe to make. So basically, all I did is compare the offset to a date in january, the offset to a date in july, and the offset now to determine whether daylight savings are in effect.

So if the offset now is the same as the summer offset, AND it's different from the winter offset, then daylight savigns are in effect, otherwise, ti isn't.

CODE

function getDSTOffset(){
    var winter = new Date(2007,01,01);
    var summer = new Date(2007,07,01);
    var now = new Date();
    
    var winterOffset = winter.getTimezoneOffset();
    var summerOffset = summer.getTimezoneOffset();
    var nowOffset = now.getTimezoneOffset();
        
    if((nowOffset == summerOffset) && (nowOffset != winterOffset)) {
        //daylight savings in effect, add one hour
    } else {
        //no dst, use nothing
    }    
}

User is offlineProfile CardPM
+Quote Post

skyhawk133

RE: Detecting DST Or Daylight Saving Time In Flash ActionScript

29 May, 2007 - 09:43 AM
Post #5

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 16,844



Thanked: 152 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
Thanks Khuffie! Great info and thanks for coming back to share.


Welcome to dream.in.code!
User is offlineProfile CardPM
+Quote Post

grimpirate

RE: Detecting DST Or Daylight Saving Time In Flash ActionScript

29 May, 2007 - 10:33 AM
Post #6

D.I.C Regular
Group Icon

Joined: 3 Aug, 2006
Posts: 383



Thanked: 16 times
Dream Kudos: 375
My Contributions
This seemed to me like it might relate to what you're doing
http://livedocs.adobe.com/flash/9.0/main/00000073.html
User is offlineProfile CardPM
+Quote Post

BronL

RE: Detecting DST Or Daylight Saving Time In Flash ActionScript

1 Jun, 2009 - 09:25 PM
Post #7

New D.I.C Head
*

Joined: 1 Jun, 2009
Posts: 1

QUOTE(Khuffie @ 29 May, 2007 - 09:32 AM) *



Basically, the two assumptions I made are as follows:
- assume that during the summer period is when clocks are advanced by an hour (if they are)
- assume that July lies within this daylight savings period
- assume that January does NOT lie within this daylight savings period

I think the above assumptions are safe to make. So basically, all I did is compare the offset to a date in january, the offset to a date in july, and the offset now to determine whether daylight savings are in effect.

So if the offset now is the same as the summer offset, AND it's different from the winter offset, then daylight savigns are in effect, otherwise, ti isn't.



I hate to burst any bubbles (and it may not matter to you) but this does not work for the southern hemisphere...
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 05:03AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month