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

Season script code

Talk about anything that doesn't fit elsewhere - PLEASE don't put Cumulus queries in here!
Post Reply
Michael_Wright
Posts: 140
Joined: Thu 30 May 2013 9:15 am
Weather Station: fine offset
Operating System: windows 7
Location: Townsville/Queensland/Australia
Contact:

Season script code

Post by Michael_Wright »

Hi guys how can I get this script to work with html cumulus template ???

Code: Select all

// $date - A date in any English textual format. If blank 
// defaults to the current date
// $hemisphere - "northern", "southern" or "australia"
function get_season($date="", $hemisphere="northern") {
	
	// Set $date to today if no date specified
	if ($date=="") { $date = date("Y-m-d"); }
	
	// Specify the season names
	$season_names = array('Winter', 'Spring', 'Summer', 'Fall');

	// Get year of date specified
	$date_year = date("Y", strtotime($date));

	// Declare season date ranges
	switch (strtolower($hemisphere)) {
		case "northern": {
			if (
				strtotime($date)<strtotime($date_year.'-03-21') || 
				strtotime($date)>=strtotime($date_year.'-12-21')
			) { 
				return $season_names[0]; // Must be in Winter
			}elseif (strtotime($date)>=strtotime($date_year.'-09-23')) {
				return $season_names[3]; // Must be in Fall
			}elseif (strtotime($date)>=strtotime($date_year.'-06-21')) {
				return $season_names[2]; // Must be in Summer
			}elseif (strtotime($date)>=strtotime($date_year.'-03-21')) {
				return $season_names[1]; // Must be in Spring
			}
			break;
		}
		case "southern": {
			if (
				strtotime($date)<strtotime($date_year.'-03-21') || 
				strtotime($date)>=strtotime($date_year.'-12-21')
			) { 
				return $season_names[2]; // Must be in Summer
			}elseif (strtotime($date)>=strtotime($date_year.'-09-23')) {
				return $season_names[1]; // Must be in Spring
			}elseif (strtotime($date)>=strtotime($date_year.'-06-21')) {
				return $season_names[0]; // Must be in Winter
			}elseif (strtotime($date)>=strtotime($date_year.'-03-21')) {
				return $season_names[3]; // Must be in Fall	
			}
			break;
		}
		case "australia": {
			if (
				strtotime($date)<strtotime($date_year.'-03-01') || 
				strtotime($date)>=strtotime($date_year.'-12-01')
			) { 
				return $season_names[2]; // Must be in Summer
			}elseif (strtotime($date)>=strtotime($date_year.'-09-01')) {
				return $season_names[1]; // Must be in Spring
			}elseif (strtotime($date)>=strtotime($date_year.'-06-01')) {
				return $season_names[0]; // Must be in Winter
			}elseif (strtotime($date)>=strtotime($date_year.'-03-01')) {
				return $season_names[3]; // Must be in Fall	
			}
			break;
		}
		default: { echo "Invalid hemisphere set"; }
	}

}
Image
The Future you have Not seen but the presants shall all ways be.
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Season script code

Post by beteljuice »

That is a .php script, which needs to be within OR 'included' in a .php file.

Then wherever you wanted the season name you would code:

Code: Select all

It's <?php echo get_season(null, "austrailia"); ?>

// OR change
function get_season($date="", $hemisphere="austrailia"){

//and use
It's <?php echo get_season(); ?>
In other words you would have to process your xxxxT.htm file and rename to xxxx.php
The code would be put between <?php ..... ?> tags somewhere BEFORE the 'echo' call.

Of course you would need to change any links in your other page menus for the .php extension.
Image
......................Imagine, what you will KNOW tomorrow !
Post Reply