Skip to content

Instantly share code, notes, and snippets.

@eddieespinal
Created March 11, 2015 17:35
Show Gist options
  • Select an option

  • Save eddieespinal/7d54174297cc92867bcd to your computer and use it in GitHub Desktop.

Select an option

Save eddieespinal/7d54174297cc92867bcd to your computer and use it in GitHub Desktop.
renderTimeOfDay
private function renderTimeOfDay($user){
$now = DateTime::now();
$now->timezone($user['timezone']); // convert to user's timezone
$hour = $now->time()->hour();
$result = 'night';
if($hour > 3 && $hour < 12){
$result = 'morning';
}elseif($hour < 17){
$result = 'afternoon';
}elseif($hour < 22){
$result = 'evening';
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment