1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of gpupo/netshoes-sdk |
5
|
|
|
* Created by Gilmar Pupo <[email protected]> |
6
|
|
|
* For the information of copyright and license you should read the file |
7
|
|
|
* LICENSE which is distributed with this source code. |
8
|
|
|
* Para a informação dos direitos autorais e de licença você deve ler o arquivo |
9
|
|
|
* LICENSE que é distribuído com este código-fonte. |
10
|
|
|
* Para obtener la información de los derechos de autor y la licencia debe leer |
11
|
|
|
* el archivo LICENSE que se distribuye con el código fuente. |
12
|
|
|
* For more information, see <https://www.gpupo.com/>. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Gpupo\NetshoesSdk\Traits; |
16
|
|
|
|
17
|
|
|
use DateTime; |
18
|
|
|
use DateTimeZone; |
19
|
|
|
use DateInterval; |
20
|
|
|
|
21
|
|
|
trait DateTimeTrait |
22
|
|
|
{ |
23
|
22 |
|
protected function dateFormat($string) |
24
|
|
|
{ |
25
|
22 |
|
$zone = 'America/Sao_Paulo'; |
26
|
|
|
|
27
|
22 |
|
if (intval($string) === $string) { |
28
|
2 |
|
$df = date_default_timezone_get(); |
29
|
2 |
|
if ($df !== $zone) { |
30
|
2 |
|
date_default_timezone_set($zone); |
31
|
|
|
} |
32
|
2 |
|
$date = date('c', $string / 1000); |
33
|
|
|
|
34
|
2 |
|
if ($df !== $zone) { |
35
|
2 |
|
date_default_timezone_set($df); |
36
|
|
|
} |
37
|
|
|
|
38
|
2 |
|
return $date; |
39
|
|
|
} |
40
|
|
|
|
41
|
20 |
|
$timezone = new DateTimeZone($zone); |
42
|
20 |
|
$datetime = new DateTime($string, $timezone); |
43
|
|
|
|
44
|
20 |
|
return $datetime->format('c'); |
45
|
|
|
} |
46
|
|
|
|
47
|
9 |
|
protected function dateGet($key) |
48
|
|
|
{ |
49
|
9 |
|
$value = $this->get($key); |
|
|
|
|
50
|
|
|
|
51
|
9 |
|
if (!empty($value)) { |
52
|
9 |
|
$string = $this->dateFormat($value); |
53
|
|
|
|
54
|
9 |
|
return str_replace('-03:00', '.000-03:00', $string); |
55
|
|
|
} |
56
|
1 |
|
} |
57
|
|
|
|
58
|
1 |
|
protected function dateMove($move) |
59
|
|
|
{ |
60
|
1 |
|
$date = new DateTime(); |
61
|
1 |
|
$date->sub(new DateInterval($move)); |
62
|
|
|
|
63
|
1 |
|
return $date->format('c'); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.