Skip to content

Commit

Permalink
Create config file
Browse files Browse the repository at this point in the history
- set hour greeting
- show date time greeting
- format date time.
  • Loading branch information
uekichinos committed Oct 11, 2021
1 parent d1fccd4 commit 92d1a48
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 10 deletions.
23 changes: 22 additions & 1 deletion config/greet.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
<?php

return [

'hour' => [
'morning' => [
'end' => 12,
'text' => 'Good morning'
],
'afternoon' => [
'start' => 12,
'end' => 17,
'text' => 'Good afternoon'
],
'evening' => [
'start' => 17,
'end' => 19,
'text' => 'Good evening'
],
'night' => [
'start' => 19,
'text' => 'Good night'
],
],
'show_datetime' => true,
'format_datetime' => 'd M Y, H:i:sa'
];
43 changes: 34 additions & 9 deletions src/Greet.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,43 @@ public static function hello($name = null)
{
$time = date('H');

if ($time < '12') {
echo 'Good morning';
} elseif ($time >= '12' && $time < '17') {
echo 'Good afternoon';
} elseif ($time >= '17' && $time < '19') {
echo 'Good evening';
} elseif ($time >= '19') {
echo 'Good night';
$greets = config('greet.hour');
if (is_array($greets)) {
foreach ($greets as $key => $value) {
if (!isset($value['start'])) {
if ($time < $value['end']) {
echo $value['text'];
}
} else if (!isset($value['end'])) {
if ($time >= $value['start']) {
echo $value['text'];
}
} else {
if ($time >= $value['start'] && $time < $value['end']) {
echo $value['text'];
}
}
}
}

// if ($time < '12') {
// echo 'Good morning';
// } elseif ($time >= '12' && $time < '17') {
// echo 'Good afternoon';
// } elseif ($time >= '17' && $time < '19') {
// echo 'Good evening';
// } elseif ($time >= '19') {
// echo 'Good night';
// }

if ($name != null) {
echo ', '.$name;
echo ' ' . $name . '.';
}

$show = config('greet.show_datetime');
if ($show === true) {
$format = config('greet.format_datetime');
echo ' Today is ' . date($format);
}
}
}

0 comments on commit 92d1a48

Please sign in to comment.