Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

Help with Javascript

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
MickinMoulden
Posts: 499
Joined: Mon 20 Dec 2010 12:12 pm
Weather Station: WS-1081 with rain gauge mod
Operating System: Windows 7 & 1.9.3 b1059
Location: Palmerston, NT, Australia
Contact:

Help with Javascript

Post by MickinMoulden »

Can anyone see anything wrong with this?

Code: Select all

<script type="text/javascript">

             var date = new Date();
	var y=date.getFullYear();
	var m=date.getMonth();
	var d=date.getDay();
	var h=date.getHours();
	var min=date.getMinutes();
	if (h<9)
	{var d=d-1;
	var rollover= new Date(y, m, d, 9,0,0,0);
	}else (rollover= new Date(y, m, d, 9,0,0,0));
	var now=new Date();
	var timeelapsed=now-rollover;
             
....more code follows.

Just finding the time difference (in milliseconds) between actual time and the rollover time (for me is 0900hrs).
If nothing is wrong here, then I'll have to check the rest of the code.
Michael, Palmerston, NT Australia www.Palmerston-WeatherImageNo image? I'm offline!
ImageImage
User avatar
MickinMoulden
Posts: 499
Joined: Mon 20 Dec 2010 12:12 pm
Weather Station: WS-1081 with rain gauge mod
Operating System: Windows 7 & 1.9.3 b1059
Location: Palmerston, NT, Australia
Contact:

Re: Help with Javascript

Post by MickinMoulden »

It's all done and fixed.
Michael, Palmerston, NT Australia www.Palmerston-WeatherImageNo image? I'm offline!
ImageImage
User avatar
mcrossley
Posts: 14388
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Help with Javascript

Post by mcrossley »

No curly brackets around your else is bad practice, you don't need 'now' as you already have now in 'date', and have you tested when d=1-1? It should work with the Date() object rolling back the month/year automatically, but worth a test of 8am on the first of January.

But don't keep us in suspense, what was the problem?
User avatar
MickinMoulden
Posts: 499
Joined: Mon 20 Dec 2010 12:12 pm
Weather Station: WS-1081 with rain gauge mod
Operating System: Windows 7 & 1.9.3 b1059
Location: Palmerston, NT, Australia
Contact:

Re: Help with Javascript

Post by MickinMoulden »

MickinMoulden wrote:Can anyone see anything wrong with this?

Code: Select all

<script type="text/javascript">

             var date = new Date();
	var y=date.getFullYear();
	var m=date.getMonth();
	var d=date.getDay();    **getDate**is what was needed, it gives 0-31, **detDay** is 0-6!
	var h=date.getHours();
	var min=date.getMinutes();
	if (h<9)
	{var d=d-1;
	var rollover= new Date(y, m, d, 9,0,0,0);
	}else (rollover= new Date(y, m, d, 9,0,0,0));
	var now=new Date();
	var timeelapsed=now-rollover;
             
....more code follows.

Just finding the time difference (in milliseconds) between actual time and the rollover time (for me is 0900hrs).
If nothing is wrong here, then I'll have to check the rest of the code.
Michael, Palmerston, NT Australia www.Palmerston-WeatherImageNo image? I'm offline!
ImageImage
User avatar
mcrossley
Posts: 14388
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Help with Javascript

Post by mcrossley »

Doh! Didn't spot that one!
Post Reply