1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alkoumi\CarbonDateTranslator; |
4
|
|
|
use Carbon\Carbon; |
5
|
|
|
use Illuminate\Support\Str; |
|
|
|
|
6
|
|
|
|
7
|
|
|
/* |
8
|
|
|
* this class translates carbon date difference to arabic |
9
|
|
|
*/ |
10
|
|
|
class TransDate |
11
|
|
|
{ |
12
|
|
|
public static function inArabic($theDate) |
13
|
|
|
{ |
14
|
|
|
// Define The Zaman after or before |
15
|
|
|
$theDate < Carbon::now() ? $zaman = "قبل " : $zaman = "بعد "; |
16
|
|
|
$theDate = $theDate->diffForHumans(); |
17
|
|
|
$dateArray = explode(" ", $theDate); //return $dateArray; // ["1","day","ago"] |
18
|
|
|
//$dateArray[0] is number, $dateArray[1] is the time period , $dateArray[2] is the word ago |
19
|
|
|
$time = $dateArray[1]; |
20
|
|
|
// handl seconds |
21
|
|
|
if((new self)->isSecond($time)) |
22
|
|
|
{ |
23
|
|
|
if($dateArray[0] == 1) |
24
|
|
|
{ |
25
|
|
|
return $zaman."ثانية واحدة"; |
26
|
|
|
} |
27
|
|
|
elseif($dateArray[0] == 2) |
28
|
|
|
{ |
29
|
|
|
return $zaman. "ثانيتين"; |
30
|
|
|
} |
31
|
|
|
elseif($dateArray[0] >= 3 && $dateArray[0] <= 10 ) |
32
|
|
|
{ |
33
|
|
|
return $zaman. $dateArray[0] . " ثواني"; |
34
|
|
|
} |
35
|
|
|
else |
36
|
|
|
{ |
37
|
|
|
return $zaman. $dateArray[0] . " ثانية"; |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
// handl minutes |
41
|
|
|
if((new self)->isMinute($time)) |
42
|
|
|
{ |
43
|
|
|
if($dateArray[0] == 1) |
44
|
|
|
{ |
45
|
|
|
return $zaman."دقيقة واحدة"; |
46
|
|
|
} |
47
|
|
|
elseif($dateArray[0] == 2) |
48
|
|
|
{ |
49
|
|
|
return $zaman. "دقيقتين"; |
50
|
|
|
} |
51
|
|
|
elseif($dateArray[0] >= 3 && $dateArray[0] <= 10 ) |
52
|
|
|
{ |
53
|
|
|
return $zaman. $dateArray[0] . " دقائق"; |
54
|
|
|
} |
55
|
|
|
else |
56
|
|
|
{ |
57
|
|
|
return $zaman. $dateArray[0] . " دقيقة"; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
// handl hours |
61
|
|
|
if((new self)->isHour($time)) |
62
|
|
|
{ |
63
|
|
|
if($dateArray[0] == 1) |
64
|
|
|
{ |
65
|
|
|
return $zaman."ساعة"; |
66
|
|
|
} |
67
|
|
|
elseif($dateArray[0] == 2) |
68
|
|
|
{ |
69
|
|
|
return $zaman. "ساعتين"; |
70
|
|
|
} |
71
|
|
|
elseif($dateArray[0] >= 3 && $dateArray[0] <= 10 ) |
72
|
|
|
{ |
73
|
|
|
return $zaman. $dateArray[0] . " ساعات"; |
74
|
|
|
} |
75
|
|
|
else |
76
|
|
|
{ |
77
|
|
|
return $zaman. $dateArray[0] . " ساعة"; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
// handl days |
81
|
|
|
if((new self)->isDay($time)) |
82
|
|
|
{ |
83
|
|
|
if($dateArray[0] == 1) |
84
|
|
|
{ |
85
|
|
|
return $zaman." يوم"; |
86
|
|
|
} |
87
|
|
|
elseif($dateArray[0] == 2) |
88
|
|
|
{ |
89
|
|
|
return $zaman. "يومين"; |
90
|
|
|
} |
91
|
|
|
elseif($dateArray[0] >= 3 && $dateArray[0] <= 10 ) |
92
|
|
|
{ |
93
|
|
|
return $zaman. $dateArray[0] . " أيام"; |
94
|
|
|
} |
95
|
|
|
else |
96
|
|
|
{ |
97
|
|
|
return $zaman. $dateArray[0] . " يوم"; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
// handl weeks |
101
|
|
|
if((new self)->isWeek($time)) |
102
|
|
|
{ |
103
|
|
|
if($dateArray[0] == 1) |
104
|
|
|
{ |
105
|
|
|
return $zaman." أسبوع"; |
106
|
|
|
} |
107
|
|
|
elseif($dateArray[0] == 2) |
108
|
|
|
{ |
109
|
|
|
return $zaman. " أسبوعين"; |
110
|
|
|
} |
111
|
|
|
elseif($dateArray[0] >= 3 && $dateArray[0] <= 10 ) |
112
|
|
|
{ |
113
|
|
|
return $zaman. $dateArray[0] . " أسابيع"; |
114
|
|
|
} |
115
|
|
|
else |
116
|
|
|
{ |
117
|
|
|
return $zaman. $dateArray[0] . " أسبوع"; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
// handl months |
121
|
|
|
if((new self)->isMonth($time)) |
122
|
|
|
{ |
123
|
|
|
if($dateArray[0] == 1) |
124
|
|
|
{ |
125
|
|
|
return $zaman."شهر"; |
126
|
|
|
} |
127
|
|
|
elseif($dateArray[0] == 2) |
128
|
|
|
{ |
129
|
|
|
return $zaman. " شهرين"; |
130
|
|
|
} |
131
|
|
|
elseif($dateArray[0] >= 3 && $dateArray[0] <= 10 ) |
132
|
|
|
{ |
133
|
|
|
return $zaman. $dateArray[0] . " شهور"; |
134
|
|
|
} |
135
|
|
|
else |
136
|
|
|
{ |
137
|
|
|
return $zaman. $dateArray[0] . " شهر"; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
// handl years |
141
|
|
|
if((new self)->isYear($time)) |
142
|
|
|
{ |
143
|
|
|
if($dateArray[0] == 1) |
144
|
|
|
{ |
145
|
|
|
return $zaman."سنة"; |
146
|
|
|
} |
147
|
|
|
elseif($dateArray[0] == 2) |
148
|
|
|
{ |
149
|
|
|
return $zaman. " سنتين"; |
150
|
|
|
} |
151
|
|
|
elseif($dateArray[0] >= 3 && $dateArray[0] <= 10 ) |
152
|
|
|
{ |
153
|
|
|
return $zaman. $dateArray[0] . " سنوات"; |
154
|
|
|
} |
155
|
|
|
else |
156
|
|
|
{ |
157
|
|
|
return $zaman. $dateArray[0] . " سنة"; |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function isSecond($time) |
163
|
|
|
{ |
164
|
|
|
Str::startsWith($time,'second') ? $isSecond = true : $isSecond = false ; |
165
|
|
|
return $isSecond; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function isMinute($time) |
169
|
|
|
{ |
170
|
|
|
Str::startsWith($time,'minute') ? $isMinute = true : $isMinute = false ; |
171
|
|
|
return $isMinute; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function isHour($time) |
175
|
|
|
{ |
176
|
|
|
Str::startsWith($time,'hour') ? $isHour = true : $isHour = false ; |
177
|
|
|
return $isHour; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
public function isDay($time) |
181
|
|
|
{ |
182
|
|
|
Str::startsWith($time,'day') ? $isDay = true : $isDay = false ; |
183
|
|
|
return $isDay; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function isWeek($time) |
187
|
|
|
{ |
188
|
|
|
Str::startsWith($time,'week') ? $isWeek = true : $isWeek = false ; |
189
|
|
|
return $isWeek; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
public function isMonth($time) |
193
|
|
|
{ |
194
|
|
|
Str::startsWith($time,'month') ? $isMonth = true : $isMonth = false ; |
195
|
|
|
return $isMonth; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function isYear($time) |
199
|
|
|
{ |
200
|
|
|
Str::startsWith($time,'year') ? $isYear = true : $isYear = false ; |
201
|
|
|
return $isYear; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
} |
205
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths