1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Presenters\Traits; |
13
|
|
|
|
14
|
|
|
use Jenssegers\Date\Date; |
15
|
|
|
|
16
|
|
|
trait TimestampsTrait |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Present formatted date time. |
20
|
|
|
* |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
|
|
public function created_at() |
24
|
|
|
{ |
25
|
|
|
return (new Date($this->wrappedObject->created_at)) |
|
|
|
|
26
|
|
|
->setTimezone($this->setting->get('app_timezone'))->toDateTimeString(); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Present diff for humans date time. |
31
|
|
|
* |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
public function created_at_diff() |
35
|
|
|
{ |
36
|
|
|
return (new Date($this->wrappedObject->created_at)) |
37
|
|
|
->setTimezone($this->setting->get('app_timezone')) |
38
|
|
|
->diffForHumans(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Present formatted date time. |
43
|
|
|
* |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
public function created_at_formatted() |
47
|
|
|
{ |
48
|
|
|
return ucfirst((new Date($this->wrappedObject->created_at)) |
49
|
|
|
->setTimezone($this->setting->get('app_timezone')) |
50
|
|
|
->format($this->setting->get('issue_date_format', 'l jS F Y H:i:s'))); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Present formatted date time. |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function created_at_iso() |
59
|
|
|
{ |
60
|
|
|
return $this->wrappedObject->created_at->setTimezone($this->setting->get('app_timezone'))->toISO8601String(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Present formatted date time. |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
public function updated_at() |
69
|
|
|
{ |
70
|
|
|
return (new Date($this->wrappedObject->updated_at)) |
71
|
|
|
->setTimezone($this->setting->get('app_timezone'))->toDateTimeString(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Present formatted date time. |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
public function deleted_at() |
80
|
|
|
{ |
81
|
|
|
return (new Date($this->wrappedObject->deleted_at)) |
82
|
|
|
->setTimezone($this->setting->get('app_timezone'))->toDateTimeString(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Present formatted date time. |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
public function verified_at() |
91
|
|
|
{ |
92
|
|
|
return (new Date($this->wrappedObject->verified_at)) |
93
|
|
|
->setTimezone($this->setting->get('app_timezone'))->toDateTimeString(); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: