Composr: Tempcode Symbol SEASON of the year
Posted: Fri Jul 26, 2019 1:50 pm
Tempcode symbol SEASON to show the season of the year.
sources/hooks/systems/symbols/SEASON.php
code from: https://stackoverflow.com/questions/408 ... ccordingly
usage:
sources/hooks/systems/symbols/SEASON.php
Code: Select all
<?php
class Hook_symbol_SEASON
{
public function run($param)
{
//start
// get today's date
$today = new DateTime();
// get the season dates
$spring = new DateTime('March 20');
$summer = new DateTime('June 20');
$fall = new DateTime('September 22');
$winter = new DateTime('December 21');
switch(true) {
case $today >= $spring && $today < $summer:
$value= 'Spring';
break;
case $today >= $summer && $today < $fall:
$value= 'Summer';
break;
case $today >= $fall && $today < $winter:
$value= 'Fall';
break;
default:
$value= 'Winter';
}
return $value;
}
}
usage:
Code: Select all
{$SEASON}