Tempcode Symbol SEASON

Post

Posted
Rating:
Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 (Liked by Chris Graham)
#5461 (In Topic #1113)
Tempcode symbol SEASON to show the season of the year.

sources/hooks/systems/symbols/SEASON.php

Code

<?php

class Hook_symbol_SEASON
{

    public function run($param)
    {
 // 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;
    }
}

code from https://stackoverflow.com/questions/40893960/php-how-to-check-the-season-of-the-year-and-set-a-class-accordingly

usage:

Code

{$SEASON}

Post

Posted
Rating:
#5462
I also made  sunrise & sunset tempcode symbols,

example:

Code

date_default_timezone_set("Asia/Tokyo");
$value = date("g:i a",(date_sunrise(time(),SUNFUNCS_RET_TIMESTAMP,43.4,141.21,90,9)));

info: https://www.w3schools.com/php/func_date_sunrise.asp

Post

Posted
Rating:
#5463
for greeting of the day:

Code

<?php

class Hook_symbol_GREETING
{

    public function run($param)
    {
    //start
   
   date_default_timezone_set("Asia/Tokyo");
    $time = date("H");  
   
   //  $timezone = date("e");
   
    if ($time < "12") {
return "morning";
    } else
   
    if ($time >= "12" && $time < "17") {
        return "afternoon";
    } else
   
    if ($time >= "17" && $time < "19") {
        return "evening";
    } else
   
    if ($time >= "19") {
        return "night";
    }

 
       
    }
}


code from https://stackoverflow.com/questions/8652502/run-code-depending-on-the-time-of-day
 

0 guests and 0 members have recently viewed this.