|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HMLB\Date\Tests\Localization; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Date package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Hugues Maignol <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
use HMLB\Date\Date; |
|
15
|
|
|
use HMLB\Date\Tests\AbstractTestCase; |
|
16
|
|
|
|
|
17
|
|
View Code Duplication |
class EsTest extends AbstractTestCase |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
|
|
public function testDiffForHumansLocalizedInSpanish() |
|
20
|
|
|
{ |
|
21
|
|
|
Date::setLocale('es'); |
|
22
|
|
|
|
|
23
|
|
|
$scope = $this; |
|
24
|
|
|
$this->wrapWithTestNow( |
|
25
|
|
|
function () use ($scope) { |
|
26
|
|
|
$d = Date::now()->subSecond(); |
|
27
|
|
|
$scope->assertSame('hace 1 segundo', $d->diffForHumans()); |
|
28
|
|
|
|
|
29
|
|
|
$d = Date::now()->subSeconds(3); |
|
30
|
|
|
$scope->assertSame('hace 3 segundos', $d->diffForHumans()); |
|
31
|
|
|
|
|
32
|
|
|
$d = Date::now()->subMinute(); |
|
33
|
|
|
$scope->assertSame('hace 1 minuto', $d->diffForHumans()); |
|
34
|
|
|
|
|
35
|
|
|
$d = Date::now()->subMinutes(2); |
|
36
|
|
|
$scope->assertSame('hace 2 minutos', $d->diffForHumans()); |
|
37
|
|
|
|
|
38
|
|
|
$d = Date::now()->subHour(); |
|
39
|
|
|
$scope->assertSame('hace 1 hora', $d->diffForHumans()); |
|
40
|
|
|
|
|
41
|
|
|
$d = Date::now()->subHours(2); |
|
42
|
|
|
$scope->assertSame('hace 2 horas', $d->diffForHumans()); |
|
43
|
|
|
|
|
44
|
|
|
$d = Date::now()->subDay(); |
|
45
|
|
|
$scope->assertSame('hace 1 día', $d->diffForHumans()); |
|
46
|
|
|
|
|
47
|
|
|
$d = Date::now()->subDays(2); |
|
48
|
|
|
$scope->assertSame('hace 2 días', $d->diffForHumans()); |
|
49
|
|
|
|
|
50
|
|
|
$d = Date::now()->subWeek(); |
|
51
|
|
|
$scope->assertSame('hace 1 semana', $d->diffForHumans()); |
|
52
|
|
|
|
|
53
|
|
|
$d = Date::now()->subWeeks(2); |
|
54
|
|
|
$scope->assertSame('hace 2 semanas', $d->diffForHumans()); |
|
55
|
|
|
|
|
56
|
|
|
$d = Date::now()->subMonth(); |
|
57
|
|
|
$scope->assertSame('hace 1 mes', $d->diffForHumans()); |
|
58
|
|
|
|
|
59
|
|
|
$d = Date::now()->subMonths(2); |
|
60
|
|
|
$scope->assertSame('hace 2 meses', $d->diffForHumans()); |
|
61
|
|
|
|
|
62
|
|
|
$d = Date::now()->subYear(); |
|
63
|
|
|
$scope->assertSame('hace 1 año', $d->diffForHumans()); |
|
64
|
|
|
|
|
65
|
|
|
$d = Date::now()->subYears(2); |
|
66
|
|
|
$scope->assertSame('hace 2 años', $d->diffForHumans()); |
|
67
|
|
|
|
|
68
|
|
|
$d = Date::now()->addSecond(); |
|
69
|
|
|
$scope->assertSame('dentro de 1 segundo', $d->diffForHumans()); |
|
70
|
|
|
|
|
71
|
|
|
$d = Date::now()->addSecond(); |
|
72
|
|
|
$d2 = Date::now(); |
|
73
|
|
|
$scope->assertSame('1 segundo después', $d->diffForHumans($d2)); |
|
74
|
|
|
$scope->assertSame('1 segundo antes', $d2->diffForHumans($d)); |
|
75
|
|
|
|
|
76
|
|
|
$scope->assertSame('1 segundo', $d->diffForHumans($d2, true)); |
|
77
|
|
|
$scope->assertSame('2 segundos', $d2->diffForHumans($d->addSecond(), true)); |
|
78
|
|
|
} |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.