-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpers.php
More file actions
executable file
·83 lines (71 loc) · 2.46 KB
/
Helpers.php
File metadata and controls
executable file
·83 lines (71 loc) · 2.46 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
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Common helpers.
*
* @author David Grudl
* @package Nette\Extras
*/
class Helpers
{
/**
* Static class - cannot be instantiated.
*/
final public function __construct()
{
throw new LogicException("Cannot instantiate static class " . get_class($this));
}
public static function timeAgoInWords($time)
{
if (!$time) {
return FALSE;
} elseif (is_numeric($time)) {
$time = (int) $time;
} elseif ($time instanceof DateTime) {
$time = $time->format('U');
} else {
$time = strtotime($time);
}
$delta = time() - $time;
if ($delta < 0) {
$delta = round(abs($delta) / 60);
if ($delta == 0) return 'za okamžik';
if ($delta == 1) return 'za minutu';
if ($delta < 45) return 'za ' . $delta . ' ' . self::plural($delta, 'minuta', 'minuty', 'minut');
if ($delta < 90) return 'za hodinu';
if ($delta < 1440) return 'za ' . round($delta / 60) . ' ' . self::plural(round($delta / 60), 'hodina', 'hodiny', 'hodin');
if ($delta < 2880) return 'zítra';
if ($delta < 43200) return 'za ' . round($delta / 1440) . ' ' . self::plural(round($delta / 1440), 'den', 'dny', 'dní');
if ($delta < 86400) return 'za měsíc';
if ($delta < 525960) return 'za ' . round($delta / 43200) . ' ' . self::plural(round($delta / 43200), 'měsíc', 'měsíce', 'měsíců');
if ($delta < 1051920) return 'za rok';
return 'za ' . round($delta / 525960) . ' ' . self::plural(round($delta / 525960), 'rok', 'roky', 'let');
}
$delta = round($delta / 60);
if ($delta == 0) return 'před okamžikem';
if ($delta == 1) return 'před minutou';
if ($delta < 45) return "před $delta minutami";
if ($delta < 90) return 'před hodinou';
if ($delta < 1440) return 'před ' . round($delta / 60) . ' hodinami';
if ($delta < 2880) return 'včera';
if ($delta < 43200) return 'před ' . round($delta / 1440) . ' dny';
if ($delta < 86400) return 'před měsícem';
if ($delta < 525960) return 'před ' . round($delta / 43200) . ' měsíci';
if ($delta < 1051920) return 'před rokem';
return 'před ' . round($delta / 525960) . ' lety';
}
/**
* Plural: three forms, special cases for 1 and 2, 3, 4.
* (Slavic family: Slovak, Czech)
* @param int
* @return mixed
*/
private static function plural($n)
{
$args = func_get_args();
return $args[($n == 1) ? 1 : ($n >= 2 && $n <= 4) ? 2 : 3];
}
public static function currency($value)
{
return str_replace(" ", "\xc2\xa0", number_format($value, 0, "", " ")) . "\xc2\xa0Kč";
}
}