@@ -21,106 +21,182 @@ class Timezone
21
21
*/
22
22
protected CarbonTimeZone $ storage ;
23
23
24
+ /**
25
+ * Create a new singleton instance.
26
+ *
27
+ * @param string $default
28
+ * @return void
29
+ */
24
30
public function __construct (string $ default )
25
31
{
26
32
$ this ->setStorage ($ default );
27
33
$ this ->setCurrent ($ default );
28
34
}
29
35
30
- public static function instance (): static
36
+ /**
37
+ * @alias setCurrent
38
+ *
39
+ * Set the current application timezone.
40
+ *
41
+ * @param mixed $timezone
42
+ * @return void
43
+ */
44
+ public function set ($ timezone = null )
31
45
{
32
- return app ()-> make ( self ::class );
46
+ $ this -> setCurrent ( $ timezone );
33
47
}
34
48
35
- public static function set ($ timezone = null )
49
+ /**
50
+ * Set the current application timezone.
51
+ *
52
+ * @param mixed $timezone
53
+ * @return void
54
+ */
55
+ public function setCurrent ($ timezone )
36
56
{
37
- static :: instance ()-> setCurrent ($ timezone );
57
+ $ this -> current = $ this -> makeTimezone ($ timezone );
38
58
}
39
59
40
- public static function current (): CarbonTimeZone
60
+ /**
61
+ * Return the current application timezone.
62
+ *
63
+ * @return \Carbon\CarbonTimeZone
64
+ */
65
+ public function current (): CarbonTimeZone
41
66
{
42
- return static :: instance ()-> getCurrent () ;
67
+ return $ this -> current ;
43
68
}
44
69
45
- public static function storage (): CarbonTimeZone
70
+ /**
71
+ * Set the current database timezone.
72
+ *
73
+ * @param mixed $timezone
74
+ * @return void
75
+ */
76
+ public function setStorage ($ timezone )
46
77
{
47
- return static :: instance ()-> getStorage ( );
78
+ $ this -> storage = $ this -> makeTimezone ( $ timezone );
48
79
}
49
80
50
- public static function now (): CarbonInterface
81
+ /**
82
+ * Return the current application timezone.
83
+ *
84
+ * @return \Carbon\CarbonTimeZone
85
+ */
86
+ public function storage (): CarbonTimeZone
51
87
{
52
- return static :: instance ()-> convertToCurrent ( now ()) ;
88
+ return $ this -> storage ;
53
89
}
54
90
55
- public static function date ($ value , callable $ maker = null ): CarbonInterface
91
+ /**
92
+ * Get the current timezoned date.
93
+ *
94
+ * @return \Carbon\CarbonInterface
95
+ */
96
+ public function now (): CarbonInterface
56
97
{
57
- $ instance = static ::instance ();
58
-
59
- return $ instance ->convertToCurrent (
60
- $ instance ->makeDateWithStorage ($ value , $ maker )
61
- );
98
+ return $ this ->convertToCurrent (Date::now ());
62
99
}
63
100
64
- public static function store ($ value , callable $ maker = null ): CarbonInterface
101
+ /**
102
+ * Configure given date for the application's current timezone.
103
+ *
104
+ * @param mixed $value
105
+ * @param null|callable $maker
106
+ * @return \Carbon\CarbonInterface
107
+ */
108
+ public function date ($ value , callable $ maker = null ): CarbonInterface
65
109
{
66
- $ instance = static ::instance ();
67
-
68
- return $ instance ->convertToStorage (
69
- $ instance ->makeDateWithCurrent ($ value , $ maker )
110
+ return $ this ->convertToCurrent (
111
+ $ this ->makeDateWithStorage ($ value , $ maker )
70
112
);
71
113
}
72
114
73
- public function setCurrent ($ timezone )
74
- {
75
- $ this ->current = $ this ->makeTimezone ($ timezone );
76
- }
77
-
78
- public function getCurrent (): CarbonTimeZone
79
- {
80
- return $ this ->current ;
81
- }
82
-
83
- public function setStorage ($ timezone )
84
- {
85
- $ this ->storage = $ this ->makeTimezone ($ timezone );
86
- }
87
-
88
- public function getStorage (): CarbonTimeZone
115
+ /**
116
+ * Configure given date for the database storage timezone.
117
+ *
118
+ * @param mixed $value
119
+ * @param null|callable $maker
120
+ * @return \Carbon\CarbonInterface
121
+ */
122
+ public function store ($ value , callable $ maker = null ): CarbonInterface
89
123
{
90
- return $ this ->storage ;
124
+ return $ this ->convertToStorage (
125
+ $ this ->makeDateWithCurrent ($ value , $ maker )
126
+ );
91
127
}
92
128
93
- public function convertToCurrent (CarbonInterface $ date ): CarbonInterface
129
+ /**
130
+ * Duplicate the given date and shift its timezone to the application's current timezone.
131
+ *
132
+ * @param \Carbon\CarbonInterface
133
+ * @return \Carbon\CarbonInterface
134
+ */
135
+ protected function convertToCurrent (CarbonInterface $ date ): CarbonInterface
94
136
{
95
- return $ date ->copy ()->setTimezone ($ this ->getCurrent ());
137
+ return $ date ->copy ()->setTimezone ($ this ->current ());
96
138
}
97
139
98
- public function convertToStorage (CarbonInterface $ date ): CarbonInterface
140
+ /**
141
+ * Duplicate the given date and shift its timezone to the database's storage timezone.
142
+ *
143
+ * @param \Carbon\CarbonInterface
144
+ * @return \Carbon\CarbonInterface
145
+ */
146
+ protected function convertToStorage (CarbonInterface $ date ): CarbonInterface
99
147
{
100
- return $ date ->copy ()->setTimezone ($ this ->getStorage ());
148
+ return $ date ->copy ()->setTimezone ($ this ->storage ());
101
149
}
102
150
103
- public function makeDateWithCurrent ($ value , callable $ maker = null ): CarbonInterface
151
+ /**
152
+ * Create or configure date using the application's current timezone.
153
+ *
154
+ * @param mixed $value
155
+ * @param null|callable $maker
156
+ * @return \Carbon\CarbonInterface
157
+ */
158
+ protected function makeDateWithCurrent ($ value , callable $ maker = null ): CarbonInterface
104
159
{
105
160
return is_a ($ value , CarbonInterface::class)
106
161
? $ this ->convertToCurrent ($ value )
107
- : $ this ->makeDate ($ value , $ this ->getCurrent (), $ maker );
162
+ : $ this ->makeDate ($ value , $ this ->current (), $ maker );
108
163
}
109
164
110
- public function makeDateWithStorage ($ value , callable $ maker = null ): CarbonInterface
165
+ /**
166
+ * Create or configure date using the database's storage timezone.
167
+ *
168
+ * @param mixed $value
169
+ * @param null|callable $maker
170
+ * @return \Carbon\CarbonInterface
171
+ */
172
+ protected function makeDateWithStorage ($ value , callable $ maker = null ): CarbonInterface
111
173
{
112
174
return is_a ($ value , CarbonInterface::class)
113
175
? $ this ->convertToStorage ($ value )
114
- : $ this ->makeDate ($ value , $ this ->getStorage (), $ maker );
176
+ : $ this ->makeDate ($ value , $ this ->storage (), $ maker );
115
177
}
116
178
179
+ /**
180
+ * Create a date using the provided timezone.
181
+ *
182
+ * @param mixed $value
183
+ * @param \Carbon\CarbonTimeZone $timezone
184
+ * @param null|callable $maker
185
+ * @return \Carbon\CarbonInterface
186
+ */
117
187
protected function makeDate ($ value , CarbonTimeZone $ timezone , callable $ maker = null ): CarbonInterface
118
188
{
119
189
return ($ maker )
120
190
? call_user_func ($ maker , $ value , $ timezone )
121
191
: Date::create ($ value , $ timezone );
122
192
}
123
193
194
+ /**
195
+ * Create a Carbon timezone from given value.
196
+ *
197
+ * @param mixed $value
198
+ * @return \Carbon\CarbonTimeZone
199
+ */
124
200
protected function makeTimezone ($ value ): CarbonTimeZone
125
201
{
126
202
if (! is_a ($ value , CarbonTimeZone::class)) {
0 commit comments