-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtime.php
61 lines (52 loc) · 1.4 KB
/
time.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
class Time {
private $zone;
private $stamp;
/**
* Constructor
* @param string $zone Timezone
* @param string $stamp Return format
*/
public function __construct($zone = "Europe/Copenhagen", $stamp = "d-m-Y H:i"){
$this->zone = $zone;
$this->stamp = $stamp;
date_default_timezone_set($this->zone);
}
/**
* Create a timestamp
* @return string date according to $stamp
*/
public function timestamp($val = null){
$date = date($this->stamp);
if($val == "day")
return substr($date, 0, 2);
if($val == "month")
return substr($date, 3, 2);
if($val == "year")
return substr($date, 6, 4);
if($val == "time")
return substr($date, -5);
return $date;
}
/**
* Return a greeting message, depending on the time of day.
* @return string Good [morning/day/afternoon/evening/night]
*/
public function greeting(){
$stamp = self::timestamp();
$pos = strpos($stamp, ':')-2;
$tod = substr($stamp, $pos, 2);
if($tod >= "05" && $tod <= "09")
$mess = "Good morning";
elseif($tod >= "10" && $tod <= "13")
$mess = "Good day";
elseif($tod >= "14" && $tod <= "18")
$mess = "Good afternoon";
elseif($tod >= "19" && $tod <= "22")
$mess = "Good evening";
else
$mess = "Goodnight";
return $mess;
}
}
?>