-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBerlinClock.php
More file actions
73 lines (54 loc) · 1.91 KB
/
BerlinClock.php
File metadata and controls
73 lines (54 loc) · 1.91 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
<?php
class BerlinClock{
public function countSimpleMinutes(int $int): string{
$int = $int%5;
if($int === 1) return "1Y";
if($int === 2) return "2Y";
if($int === 3) return "3Y";
if($int === 4) return "4Y";
return "0Y";
}
public function countBlockOfFiveMinutes(int $int): string{
if($int >= 55) return "8Y3R";
if($int >= 50) return "7Y3R";
if($int >= 45) return "6Y3R";
if($int >= 40) return "6Y2R";
if($int >= 35) return "5Y2R";
if($int >= 30) return "4Y2R";
if($int >= 25) return "4Y1R";
if($int >= 20) return "3Y1R";
if($int >= 15) return "2Y1R";
if($int >= 10) return "2Y0R";
if($int >= 5) return "1Y0R";
return "0Y0R";
}
public function countSimpleHours(int $int): string{
$int = $int%5;
if($int === 1) return "1R";
if($int === 2) return "2R";
if($int === 3) return "3R";
if($int === 4) return "4R";
return "0R";
}
public function countBlockOfFiveHours(int $int): string{
if($int >= 20) return "4R";
if($int >= 15) return "3R";
if($int >= 10) return "2R";
if($int >= 5) return "1R";
return "0R";
}
public function countSeconds(int $int): string{
$int = $int%2;
if($int === 1) return "0R";
return "1R";
}
public function countEntireClock(string $heure): string{
$hours = intval(substr($heure, 0, 2));
$minutes = intval(substr($heure, 3, 2));
$seconds = intval(substr($heure, 6,2));
$stringMinutes = $this->countSimpleMinutes($minutes) . $this->countBlockOfFiveMinutes($minutes);
$stringHours = $this->countSimpleHours($hours) . $this->countBlockOfFiveHours($hours);
$stringSeconds = $this->countSeconds($seconds);
return $stringMinutes . $stringHours . $stringSeconds;
}
}