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

MinutesSinceLastRainTip

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

Moderator: daj

Alan
Posts: 51
Joined: Sun 14 Mar 2010 9:41 am
Weather Station: WH1091
Operating System: Win 7
Location: Sydney

MinutesSinceLastRainTip

Post by Alan »

Hi to all,
I am hoping that somebody with javascript experience can help me out with this one as my knowledge is next to zero.
In the latest Cumulus version (1.9.4) Steve made available a tag to return the number of minutes since the last rain tip (<#MinutesSinceLastRainTip>). This for me is really useful but not in its current format. I would really like to convert the returned number of minutes into xxDays : xxHrs : xxMins
I have tried various samples that were retrieved from the net but all to no avail.... I am now at my wits end. Any help with this would be greatly appreciated.
The applicable code that I am trying to modify is as follows.....

<table class="data" width="1900px" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="100%"align="center"valign="center"style="font-size:600%"style="color:blue"><#MinutesSinceLastRainTip></td>
</tr>
</table>
</body>
</html>

Thanking any helpers in advance
Cheers!
Alan
milos.jirik
Posts: 18
Joined: Wed 19 May 2010 5:02 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 10
Location: Nova Paka, Czech Republic, Central Europe
Contact:

Re: MinutesSinceLastRainTip

Post by milos.jirik »

Hi Alan,

this can be replaced by the script as written below.

Code: Select all

<?php
       # script for converting time since last precipitation
        $minutes = $MinutesSinceLastRainTip;                 // variable definition
        // determine the variables calculated from $minutes    
        $d = floor ($minutes / 1440);
        $h = floor (($minutes - $d * 1440) / 60);
        $m = $minutes - ($d * 1440) - ($h * 60);
        // output values
        if($d == 0){
        echo "{$h}&nbsp;h.&nbsp;{$m}&nbsp;min.";
          }
          else {
          if($d == 1){
           echo "{$d}&nbsp;Day&nbsp;{$h}&nbsp;Hrs&nbsp;{$m}&nbsp;Mins";
              } 
          else {
          if($d >= 2){
          echo "{$d}&nbsp;Days&nbsp;{$h}&nbsp;Hrs&nbsp;{$m}&nbsp;Mins";
          }
         }
        }    
     #  end of script
?>
Cheers!

Milos
User avatar
steve
Cumulus Author
Posts: 26672
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: MinutesSinceLastRainTip

Post by steve »

With JavaScript, you could do it as follows. There may be more elegant ways!

Code: Select all

<td width="100%"align="center"valign="center"style="font-size:600%"style="color:blue"><script type="text/javascript">document.write(Math.floor(<#MinutesSinceLastRainTip>/24/60) + 'Days : ' + Math.floor(<#MinutesSinceLastRainTip>/60%24) + 'Hrs : ' + Math.floor(<#MinutesSinceLastRainTip>%60) + 'Mins');</script></td>
Steve
milos.jirik
Posts: 18
Joined: Wed 19 May 2010 5:02 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 10
Location: Nova Paka, Czech Republic, Central Europe
Contact:

Re: MinutesSinceLastRainTip

Post by milos.jirik »

Hi Steve,

thanks for converting my PHP script to Javascript. I'm not that familiar with Javascript.

Best regards

Milos
Alan
Posts: 51
Joined: Sun 14 Mar 2010 9:41 am
Weather Station: WH1091
Operating System: Win 7
Location: Sydney

Re: MinutesSinceLastRainTip

Post by Alan »

Hi to Steve and Milos,
Thanks to both of you for your efforts, the javascript supplied works beautifully.
Cheers and best regards,
Alan
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: MinutesSinceLastRainTip

Post by ace2 »

very nice......YONK


sorry, I've stolen that code and used it in my page.

hope that's ok??? :)



http://www.users.on.net/~ace2/index.htm
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
captzero
Posts: 363
Joined: Wed 03 Mar 2010 10:20 am
Weather Station: Vantage Pro2 w/ daytime FARS
Operating System: Windows 10
Location: Brisbane, Australia
Contact:

Re: MinutesSinceLastRainTip

Post by captzero »

If any value is equal to '1' this php code will write 'days', 'hours' or 'minutes' as the singular, i.e...day...hr...min.

Code: Select all

$minutes = '<#MinutesSinceLastRainTip>';       
	   
$d = floor ($minutes / 1440);
$h = floor (($minutes - $d * 1440) / 60);
$m = $minutes - ($d * 1440) - ($h * 60);

$day ='day';
$days ='days';
$hour ='hr';
$hours ='hrs';
$min = 'min';
$mins = 'mins';

if ($d == '1') echo "{$d}&nbsp;{$day}&nbsp;"; else echo "{$d}&nbsp;{$days}&nbsp;";
if ($h == '1') echo "{$h}&nbsp;{$hour}&nbsp;"; else echo "{$h}&nbsp;{$hours}&nbsp;";
if ($m == '1') echo "{$m}&nbsp;{$min}&nbsp;"; else echo "{$m}&nbsp;{$mins}";
Dan

http://www.brisbaneliveweather.com




A man with a thermometer always knows the temperature. A man with two thermometers, not so sure.
Alan
Posts: 51
Joined: Sun 14 Mar 2010 9:41 am
Weather Station: WH1091
Operating System: Win 7
Location: Sydney

Re: MinutesSinceLastRainTip

Post by Alan »

Dan, thank you very much for your suggestion. However, as I mentioned in my original post, I know next to nothing about jvascript and must add that I know absolutely nothing about PHP, I have never used it. So would you be so kind so as to show me exactly where your supplied code would be embedded into the code that I supplied. I was aware of the use of plural nomenclature only but was prepared to put up with. This solution of yours though seems to be the bees knees.

Cheers! and thanks,
Alan
BCJKiwi
Posts: 1259
Joined: Mon 09 Jul 2012 8:40 pm
Weather Station: Davis VP2 Cabled
Operating System: Windows 10 Pro
Location: Auckland, New Zealand
Contact:

Re: MinutesSinceLastRainTip

Post by BCJKiwi »

Or this;
To insert this into the standard html wherever you want it displayed. e.g into a new table row in say index.htm. You will need to add into the ....T.htm file in C:\cumulus\web as Cumulus needs to fill the <#MinutesSinceLastRainTip> tag.

Code: Select all

  <tr>
    <td colspan="7">
      <b>Age of Last rain Tip: </b>
      <?php
         $minutes = '<#MinutesSinceLastRainTip>';

         $d = floor ($minutes / 1440);
         $h = floor (($minutes - $d * 1440) / 60);
         $m = $minutes - ($d * 1440) - ($h * 60);

         $dy = ($d === 1)? $d . " Day:" : $d . " Days:";
         $hr = ($h === 1)? $h . " Hr:" :  $h . " Hrs:";
         $mi = ($m === 1)? $d . " Min:" : $m . " Mins";
         echo "$dy $hr $mi";
      ?>
    </td>
  </tr>
The <?php ?> are the php tags as this is a bit of php code.
The ( )? is the if part of an "if else" statement.
The : in front of the $d is the else part.
Last edited by BCJKiwi on Sun 23 Feb 2014 6:39 am, edited 1 time in total.
captzero
Posts: 363
Joined: Wed 03 Mar 2010 10:20 am
Weather Station: Vantage Pro2 w/ daytime FARS
Operating System: Windows 10
Location: Brisbane, Australia
Contact:

Re: MinutesSinceLastRainTip

Post by captzero »

Hi Alan,

I should have read your initial post more carefully.
You did ask for a javascript solution and I posted a PHP solution and it wont work on your webpage as it stands. I'm afraid I have bugger all knowledge of javascript so I'll have to leave that and hope that someone else on the forum can provide something for you.
Dan

http://www.brisbaneliveweather.com




A man with a thermometer always knows the temperature. A man with two thermometers, not so sure.
User avatar
ace2
Posts: 679
Joined: Tue 14 Jan 2014 12:38 pm
Weather Station: maxkon ws-1081pc
Operating System: windows 7 & 8
Location: Adelaide, south Australia, Australia
Contact:

Re: MinutesSinceLastRainTip

Post by ace2 »

<table class="data" width="1900px" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td width="100%"align="center"valign="center"style="font-
size:600%"style="color:blue"><script type="text/
javascript">document.write(Math.floor
(<#MinutesSinceLastRainTip>/24/60) + 'Days : ' + Math.floor
(<#MinutesSinceLastRainTip>/60%24) + 'Hrs : ' + Math.floor
(<#MinutesSinceLastRainTip>%60) + 'Mins');</script></td>
</tr>
</table>
</body>
</html>

or anywhere you want!
just remember it must be in a template file to be processed to work.
i added mine into indexT.htm below the forecast


http://www.users.on.net/~ace2/index.htm
the output file, I edited the code a little to suit my needs.
CHRIS
Image
web site
http://www.ace2weather.com
Follow me on Twitter
http://tinyurl.com/kwlr9re
YouTube channel
http://tinyurl.com/lehwpgp
Facebook page
http://tinyurl.com/k3sap4s
Tiny URL links used
User avatar
steve
Cumulus Author
Posts: 26672
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: MinutesSinceLastRainTip

Post by steve »

You can amend that JavaScript I provided to do the same kind of thing (i.e. do the plural check). You would probably want to create a separate function rather than putting it 'inline', as it's going to get messy. I'll see if I can come up with something later, if none of the real JavaScript experts have chipped in by then.
Steve
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: MinutesSinceLastRainTip

Post by mcrossley »

Code: Select all

<script type="text/javascript">
var days = Math.floor(<#MinutesSinceLastRainTip>/24/60);
var hrs = Math.floor(<#MinutesSinceLastRainTip>/60%24);
var mins = Math.floor(<#MinutesSinceLastRainTip>%60);
function plur(x){return x > 1 ? 's' : ''};
document.write(days + 'Day' + plur(days) + ' : ' + hrs + 'Hr' + plur(hrs) + ' : ' + mins + 'Min' + plur(mins));
</script>
[/s]

Nowt wrong with your js Steve.

Do you have any idea how hard it is to peck out code on a tablet!
Last edited by mcrossley on Sun 23 Feb 2014 2:41 pm, edited 1 time in total.
User avatar
steve
Cumulus Author
Posts: 26672
Joined: Mon 02 Jun 2008 6:49 pm
Weather Station: None
Operating System: None
Location: Vienne, France
Contact:

Re: MinutesSinceLastRainTip

Post by steve »

Thanks, Mark, that's much more elegant than my effort would have been!
Steve
Alan
Posts: 51
Joined: Sun 14 Mar 2010 9:41 am
Weather Station: WH1091
Operating System: Win 7
Location: Sydney

Re: MinutesSinceLastRainTip

Post by Alan »

Steve, even with my limited knowledge I can understand what you mean by it getting messy (because I have given this point consideration). What I find thoroughly encouraging is the involvement of various members on this topic.
Alan
Post Reply