<?php
// general helper functions
function getUrlParameter($name, $isInt = FALSE)
{
$default = $isInt ? ((int)0) : '';
return isset($_GET[$name]) ? trim($_GET[$name]) : $default;
}
function getLocalTime()
{
$gmtOffset = -7; // adjust for your timezone, or 0 for GMT time
$myTimezone = ($gmtOffset) * (3600);
$format = 'Y-m-d H:i:s';
$t = date($format, time() + $myTimezone);
return $t;
}
function debugDump($var, $title)
{
echo '<span style="color: #A20000;">' . getLocalTime() . ' <strong>' . $title . '</strong>:</span><pre>';
var_dump($var);
echo '</pre>';
}
// $date - A date in any English textual format. If blank, defaults to the current date
// $hemisphere - "northern", "southern" or "australia"
// does not accommodate annual solstice changes
// source: http://biostall.com/get-the-current-season-using-php/
function getSeason($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') OR
strtotime($date) >= strtotime($date_year . '-12-21')
)
{
return $season_names[0]; // Winter
}
elseif ( strtotime($date) >= strtotime($date_year . '-09-23') )
{
return $season_names[3]; // Fall
}
elseif ( strtotime($date) >= strtotime($date_year . '-06-21') )
{
return $season_names[2]; // Summer
}
elseif ( strtotime($date) >= strtotime($date_year . '-03-21') )
{
return $season_names[1]; // Spring
}
break;
}
case 'southern':
{
if (
strtotime($date) < strtotime($date_year . '-03-21') OR
strtotime($date) >= strtotime($date_year . '-12-21')
)
{
return $season_names[2]; // Summer
}
elseif ( strtotime($date) >= strtotime($date_year . '-09-23') )
{
return $season_names[1]; // Spring
}
elseif ( strtotime($date) >= strtotime($date_year . '-06-21') )
{
return $season_names[0]; // Winter
}
elseif ( strtotime($date) >= strtotime($date_year . '-03-21') )
{
return $season_names[3]; // Fall
}
break;
}
case 'australia':
{
if (
strtotime($date) < strtotime($date_year . '-03-01') OR
strtotime($date) >= strtotime($date_year . '-12-01')
)
{
return $season_names[2]; // Summer
}
elseif ( strtotime($date) >= strtotime($date_year . '-09-01') )
{
return $season_names[1]; // Spring
}
elseif ( strtotime($date) >= strtotime($date_year . '-06-01') )
{
return $season_names[0]; // Winter
}
elseif ( strtotime($date) >= strtotime($date_year . '-03-01') )
{
return $season_names[3]; // Fall
}
break;
}
default:
{
//echo 'Invalid hemisphere given';
return 'invalid hemisphere';
}
}
return 'huh?';
}
|