Skip to content

Instantly share code, notes, and snippets.

@nasrulhazim
Created June 20, 2021 03:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasrulhazim/039ff696b5d56abcad326ea7affb9015 to your computer and use it in GitHub Desktop.
Save nasrulhazim/039ff696b5d56abcad326ea7affb9015 to your computer and use it in GitHub Desktop.
Simple Time Period Helper
<?php
if (! function_exists('time_period')) {
function time_period()
{
// Morning: 6 a.m.-noon
// Afternoon: noon-6 p.m.
// Evening: 6-9 p.m.
$value = (int) date('H');
if (in_array($value, range(0, 12))) {
return __('Morning');
}
if (in_array($value, range(13, 15))) {
return __('Afternoon');
}
if (in_array($value, range(16, 23))) {
return __('Evening');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment