|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Propaganistas\LaravelIntl\Proxies; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Traits\Macroable; |
|
6
|
|
|
use Jenssegers\Date\Date as Carbon; |
|
7
|
|
|
use JsonSerializable; |
|
8
|
|
|
use Punic\Calendar; |
|
9
|
|
|
|
|
10
|
|
|
class Date extends Carbon implements JsonSerializable |
|
11
|
|
|
{ |
|
12
|
|
|
use Macroable; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* The custom Carbon JSON serializer. |
|
16
|
|
|
* |
|
17
|
|
|
* @var callable|null |
|
18
|
|
|
*/ |
|
19
|
|
|
protected static $serializer; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Formats the date to a short date string. |
|
23
|
|
|
* |
|
24
|
|
|
* @return string |
|
25
|
|
|
* @throws \Punic\Exception |
|
26
|
|
|
*/ |
|
27
|
3 |
|
public function toShortDateString() |
|
28
|
|
|
{ |
|
29
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
30
|
|
|
return $this->__call(__FUNCTION__, []); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
3 |
|
return Calendar::formatDate($this, 'short'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Formats the date to a medium date string. |
|
38
|
|
|
* |
|
39
|
|
|
* @return string |
|
40
|
|
|
* @throws \Punic\Exception |
|
41
|
|
|
*/ |
|
42
|
3 |
|
public function toMediumDateString() |
|
43
|
|
|
{ |
|
44
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
45
|
|
|
return $this->__call(__FUNCTION__, []); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
3 |
|
return Calendar::formatDate($this, 'medium'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Formats the date to a long date string. |
|
53
|
|
|
* |
|
54
|
|
|
* @return string |
|
55
|
|
|
* @throws \Punic\Exception |
|
56
|
|
|
*/ |
|
57
|
3 |
|
public function toLongDateString() |
|
58
|
|
|
{ |
|
59
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
60
|
|
|
return $this->__call(__FUNCTION__, []); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
3 |
|
return Calendar::formatDate($this, 'long'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Formats the date to a full date string. |
|
68
|
|
|
* |
|
69
|
|
|
* @return string |
|
70
|
|
|
* @throws \Punic\Exception |
|
71
|
|
|
*/ |
|
72
|
3 |
|
public function toFullDateString() |
|
73
|
|
|
{ |
|
74
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
75
|
|
|
return $this->__call(__FUNCTION__, []); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
3 |
|
return Calendar::formatDate($this, 'full'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Formats the date to a short time string. |
|
83
|
|
|
* |
|
84
|
|
|
* @return string |
|
85
|
|
|
* @throws \Punic\Exception |
|
86
|
|
|
*/ |
|
87
|
3 |
|
public function toShortTimeString() |
|
88
|
|
|
{ |
|
89
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
90
|
|
|
return $this->__call(__FUNCTION__, []); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
3 |
|
return Calendar::formatTime($this, 'short'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Formats the date to a medium time string. |
|
98
|
|
|
* |
|
99
|
|
|
* @return string |
|
100
|
|
|
* @throws \Punic\Exception |
|
101
|
|
|
*/ |
|
102
|
3 |
|
public function toMediumTimeString() |
|
103
|
|
|
{ |
|
104
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
105
|
|
|
return $this->__call(__FUNCTION__, []); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
3 |
|
return Calendar::formatTime($this, 'medium'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Formats the date to a long time string. |
|
113
|
|
|
* |
|
114
|
|
|
* @return string |
|
115
|
|
|
* @throws \Punic\Exception |
|
116
|
|
|
*/ |
|
117
|
3 |
|
public function toLongTimeString() |
|
118
|
|
|
{ |
|
119
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
120
|
|
|
return $this->__call(__FUNCTION__, []); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
3 |
|
return Calendar::formatTime($this, 'long'); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Formats the date to a full time string. |
|
128
|
|
|
* |
|
129
|
|
|
* @return string |
|
130
|
|
|
* @throws \Punic\Exception |
|
131
|
|
|
*/ |
|
132
|
3 |
|
public function toFullTimeString() |
|
133
|
|
|
{ |
|
134
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
135
|
|
|
return $this->__call(__FUNCTION__, []); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
3 |
|
return Calendar::formatTime($this, 'full'); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Formats the date to a short datetime string. |
|
143
|
|
|
* |
|
144
|
|
|
* @return string |
|
145
|
|
|
* @throws \Punic\Exception |
|
146
|
|
|
*/ |
|
147
|
3 |
|
public function toShortDatetimeString() |
|
148
|
|
|
{ |
|
149
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
150
|
|
|
return $this->__call(__FUNCTION__, []); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
3 |
|
return Calendar::formatDatetime($this, 'short'); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Formats the date to a medium datetime string. |
|
158
|
|
|
* |
|
159
|
|
|
* @return string |
|
160
|
|
|
* @throws \Punic\Exception |
|
161
|
|
|
*/ |
|
162
|
3 |
|
public function toMediumDatetimeString() |
|
163
|
|
|
{ |
|
164
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
165
|
|
|
return $this->__call(__FUNCTION__, []); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
3 |
|
return Calendar::formatDatetime($this, 'medium'); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Formats the date to a long datetime string. |
|
173
|
|
|
* |
|
174
|
|
|
* @return string |
|
175
|
|
|
* @throws \Punic\Exception |
|
176
|
|
|
*/ |
|
177
|
3 |
|
public function toLongDatetimeString() |
|
178
|
|
|
{ |
|
179
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
180
|
|
|
return $this->__call(__FUNCTION__, []); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
3 |
|
return Calendar::formatDatetime($this, 'long'); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Formats the date to a full datetime string. |
|
188
|
|
|
* |
|
189
|
|
|
* @return string |
|
190
|
|
|
* @throws \Punic\Exception |
|
191
|
|
|
*/ |
|
192
|
3 |
|
public function toFullDatetimeString() |
|
193
|
|
|
{ |
|
194
|
3 |
|
if (static::hasMacro(__FUNCTION__)) { |
|
195
|
|
|
return $this->__call(__FUNCTION__, []); |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
3 |
|
return Calendar::formatDatetime($this, 'full'); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* Get the short date format. |
|
203
|
|
|
* |
|
204
|
|
|
* @return string |
|
205
|
|
|
* @throws \Punic\Exception |
|
206
|
|
|
*/ |
|
207
|
3 |
|
public function getShortDateFormat() |
|
208
|
|
|
{ |
|
209
|
3 |
|
return Calendar::getDateFormat('short'); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Get the medium date format. |
|
214
|
|
|
* |
|
215
|
|
|
* @return string |
|
216
|
|
|
* @throws \Punic\Exception |
|
217
|
|
|
*/ |
|
218
|
3 |
|
public function getMediumDateFormat() |
|
219
|
|
|
{ |
|
220
|
3 |
|
return Calendar::getDateFormat('medium'); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Get the long date format. |
|
225
|
|
|
* |
|
226
|
|
|
* @return string |
|
227
|
|
|
* @throws \Punic\Exception |
|
228
|
|
|
*/ |
|
229
|
3 |
|
public function getLongDateFormat() |
|
230
|
|
|
{ |
|
231
|
3 |
|
return Calendar::getDateFormat('long'); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Get the full date format. |
|
236
|
|
|
* |
|
237
|
|
|
* @return string |
|
238
|
|
|
* @throws \Punic\Exception |
|
239
|
|
|
*/ |
|
240
|
3 |
|
public function getFullDateFormat() |
|
241
|
|
|
{ |
|
242
|
3 |
|
return Calendar::getDateFormat('full'); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* Get the short time format. |
|
247
|
|
|
* |
|
248
|
|
|
* @return string |
|
249
|
|
|
* @throws \Punic\Exception |
|
250
|
|
|
*/ |
|
251
|
3 |
|
public function getShortTimeFormat() |
|
252
|
|
|
{ |
|
253
|
3 |
|
return Calendar::getTimeFormat('short'); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
/** |
|
257
|
|
|
* Get the medium time format. |
|
258
|
|
|
* |
|
259
|
|
|
* @return string |
|
260
|
|
|
* @throws \Punic\Exception |
|
261
|
|
|
*/ |
|
262
|
3 |
|
public function getMediumTimeFormat() |
|
263
|
|
|
{ |
|
264
|
3 |
|
return Calendar::getTimeFormat('medium'); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* Get the long time format. |
|
269
|
|
|
* |
|
270
|
|
|
* @return string |
|
271
|
|
|
* @throws \Punic\Exception |
|
272
|
|
|
*/ |
|
273
|
3 |
|
public function getLongTimeFormat() |
|
274
|
|
|
{ |
|
275
|
3 |
|
return Calendar::getTimeFormat('long'); |
|
276
|
|
|
} |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Get the full time format. |
|
280
|
|
|
* |
|
281
|
|
|
* @return string |
|
282
|
|
|
* @throws \Punic\Exception |
|
283
|
|
|
*/ |
|
284
|
3 |
|
public function getFullTimeFormat() |
|
285
|
|
|
{ |
|
286
|
3 |
|
return Calendar::getTimeFormat('full'); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* Get the short datetime format. |
|
291
|
|
|
* |
|
292
|
|
|
* @return string |
|
293
|
|
|
* @throws \Punic\Exception |
|
294
|
|
|
*/ |
|
295
|
3 |
|
public function getShortDatetimeFormat() |
|
296
|
|
|
{ |
|
297
|
3 |
|
return Calendar::getDatetimeFormat('short'); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* Get the medium datetime format. |
|
302
|
|
|
* |
|
303
|
|
|
* @return string |
|
304
|
|
|
* @throws \Punic\Exception |
|
305
|
|
|
*/ |
|
306
|
3 |
|
public function getMediumDatetimeFormat() |
|
307
|
|
|
{ |
|
308
|
3 |
|
return Calendar::getDatetimeFormat('medium'); |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* Get the long datetime format. |
|
313
|
|
|
* |
|
314
|
|
|
* @return string |
|
315
|
|
|
* @throws \Punic\Exception |
|
316
|
|
|
*/ |
|
317
|
3 |
|
public function getLongDatetimeFormat() |
|
318
|
|
|
{ |
|
319
|
3 |
|
return Calendar::getDatetimeFormat('long'); |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* Get the full datetime format. |
|
324
|
|
|
* |
|
325
|
|
|
* @return string |
|
326
|
|
|
* @throws \Punic\Exception |
|
327
|
|
|
*/ |
|
328
|
3 |
|
public function getFullDatetimeFormat() |
|
329
|
|
|
{ |
|
330
|
3 |
|
return Calendar::getDatetimeFormat('full'); |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* Prepare the object for JSON serialization. |
|
335
|
|
|
* |
|
336
|
|
|
* @return array|string |
|
337
|
|
|
*/ |
|
338
|
12 |
|
public function jsonSerialize() |
|
339
|
|
|
{ |
|
340
|
12 |
|
if (static::$serializer) { |
|
341
|
|
|
return call_user_func(static::$serializer, $this); |
|
342
|
|
|
} |
|
343
|
|
|
|
|
344
|
12 |
|
$carbon = $this; |
|
345
|
|
|
|
|
346
|
12 |
|
return call_user_func(function () use ($carbon) { |
|
347
|
12 |
|
return get_object_vars($carbon); |
|
348
|
12 |
|
}); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
/** |
|
352
|
|
|
* JSON serialize all Carbon instances using the given callback. |
|
353
|
|
|
* |
|
354
|
|
|
* @param callable $callback |
|
355
|
|
|
* @return void |
|
356
|
|
|
*/ |
|
357
|
|
|
public static function serializeUsing($callback) |
|
358
|
|
|
{ |
|
359
|
|
|
static::$serializer = $callback; |
|
360
|
|
|
} |
|
361
|
|
|
} |