Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    New Coder
    Join Date
    May 2012
    Location
    Australia
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Next batch of code.

    If I have done it correctly, it should show the current time in Victoria, while taking daylight savings into consideration.

    Have I done the nested if conditions correctly?

    Code:
    if
        {
            if
                {
                    blah1
                }
            else
               {
                   blah2
               }
        }
    And is that a good way of doing nested if's? (Or even an acceptable way?

    Code below in its entirety.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function startVic() {
    
    
    
    var nowvica = new Date();  
    var yrvica = nowvica.getYear();
    var DSTusedvica = false;
    
    var janvica = new Date(yrvica,0,1);  // 1st January in current year
    var janoffvica = janvica.getTimezoneOffset();
    var julvica = new Date(yrvica,6,1);  // 1st July in current year
    var juloffvica = julvica.getTimezoneOffset();
    // alert ("January " + janoff +  "          July " + juloff); // for testing
    if (janoffvica != juloffvica) {
    DSTusedvica = true;
    }
    
    if (DSTusedvica) {
    var ntzovica = nowvica.getTimezoneOffset();
    if (ntzovica == juloffvica) {
     // DST is in operation
    }
    else {
     // DST is not in operation
    }
    }
    
    
    
    
    
    
    var nowvic = new Date();
    var hvic=nowvic.getUTCHours();
    var minvic=nowvic.getUTCMinutes();
    var svic=nowvic.getUTCSeconds();
    if (hvic>12) {hvic-=12}
    if (hvic==0) {hvic=12};
    
    if (ntzovica == juloffvica)
    	{
    		if (hvic<=2)
    			{
    					hvic=hvic+10
    			}
    		else
    			{
    					hvic=hvic-2
    			}
    	}
    else
    	{
    		if (hvic<=1)
    			{
    				hvic=hvic+11
    			}
    		else
    			{
    				hvic=hvic-1
    			}
    	}
    
    
    
    if (minvic<10) {minvic="0"+minvic}
    if (svic<10) {svic="0"+svic}
    document.getElementById("timevic").innerHTML=hvic+":"+minvic+":"+svic;
    var timvic = setTimeout("startVic()",1000);
    }
    </script>
    </head>
    <body onload="startVic()">
    <span id="timevic"></span>
    </body>
    </html>
    Last edited by daleala; 05-11-2012 at 04:15 AM.

  2. #17
    New Coder
    Join Date
    May 2012
    Location
    Australia
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Is there any way I can add "setTimezone("AEST");" or setTimezone("Australia/Melbourne");" into the coding somewhere or something similar to the DST check (see above) so it checks if it is daylight savings or not in Victoria, regardless of the timezone it is running from?

  3. #18
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by daleala View Post
    Is there any way I can add "setTimezone("AEST");" or setTimezone("Australia/Melbourne");" into the coding somewhere or something similar to the DST check (see above) so it checks if it is daylight savings or not in Victoria, regardless of the timezone it is running from?
    No. As I said before, it is possible to detect whether DST is used and is currently in operation in the user's own country, but AFAIK it is not possible for a user in one country to detect whether DST is currently in operation in some other country, e.g. Japan or Argentina.

    In any case, why does it matter to a user in (say) New Zealand whether or not DST is currently in operation in Victoria Australia?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  4. #19
    New Coder
    Join Date
    May 2012
    Location
    Australia
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Unless I am mistaken, because we are telling the clock to go to UTC time then add 10 hours, during daylight savings time (+11 hours instead of +10) the clock would be 1 hour off. It's not hugely important for this implementation as it may only get used in Victoria, but something I'll try to look into as the next upgrade so it can actually get used cross-state (and then post the code here for an open/closed taking DST into consideration script)

    I'll post the entire working code in the next day or so - as best as I can tell it is all working, I just want to bug hunt and double-check myself.

    Cheers.

  5. #20
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Do the states of Australia have different dates of implementation of DST?

    I now see that those states that do use DST use the same dates, but not all Australian states use DST.
    And there are three different time zones in Australia.
    Last edited by Philip M; 05-14-2012 at 08:17 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  6. #21
    New Coder
    Join Date
    May 2012
    Location
    Australia
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Do the states of Australia have different dates of implementation of DST?

    I now see that those states that do use DST use the same dates, but not all Australian states use DST.
    And there are three different time zones in Australia.
    Yeah, if they all used DST at the same time it would not be an issue at all!
    There's been a few times where the use of DST has been questioned by us Aussies, but nothing has happened of it. Go figure!

    I was busy looking for a way of working out how to find out the DST in a specific timezone clientside - I found a few ways server-side using Ruby on Rails or PHP but nothing in Javascript.
    I'll keep looking and see what I can find, then update this thread.

  7. #22
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,919
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by daleala View Post
    I was busy looking for a way of working out how to find out the DST in a specific timezone clientside - I found a few ways server-side using Ruby on Rails or PHP but nothing in Javascript.
    As I have already tried to explain, it is not possible using client-side code.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •