summaryrefslogtreecommitdiff
blob: 8821f29e211674fba66c6850ec773a4d4c6bc83c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
 * Tests for TimeUnits
 * @author Santhosh Thottingal
 * @copyright Copyright © 2007-2013
 * @license GPL-2.0-or-later
 *
 * @covers TimeUnits
 */
class TimeUnitsTest extends MediaWikiTestCase {

	/**
	 * @dataProvider providerTimeUnit
	 * @param string $language
	 * @param string $tsTime The timestamp to format
	 * @param string $currentTime The time to consider "now"
	 * @param string $expectedOutput The expected output
	 * @param string $desc Description
	 */
	public function testTimeUnit( $language, $tsTime, $currentTime, $expectedOutput, $desc ) {
		$tsTime = new MWTimestamp( $tsTime );
		$currentTime = new MWTimestamp( $currentTime );
		$this->assertEquals(
			$expectedOutput,
			$tsTime->getHumanTimestamp( $currentTime, null, Language::factory( $language ) ),
			$desc
		);
	}

	public static function providerTimeUnit() {
		return [
			[
				'en',
				'20111231170000',
				'20120101000000',
				'7 hours ago',
				'"Yesterday" across years',
			],
			[
				'en',
				'20120717190900',
				'20120717190929',
				'29 seconds ago',
				'"Just now"',
			],
			[
				'en',
				'20120717190900',
				'20120717191530',
				'6 minutes ago',
				'X minutes ago',
			],
			[
				'en',
				'20121006173100',
				'20121006173200',
				'1 minute ago',
				'"1 minute ago"',
			],
			[
				'en',
				'20120617190900',
				'20120717190900',
				'1 month ago',
				'Month difference'
			],
			[
				'en',
				'19910130151500',
				'20120716193700',
				'21 years ago',
				'Different year',
			],
			[
				'en',
				'20120714184300',
				'20120715040000',
				'9 hours ago',
				'Today at another time',
			],
			[
				'en',
				'20120617190900',
				'20120717190900',
				'1 month ago',
				'Another month'
			],
			[
				'en',
				'19910130151500',
				'20120716193700',
				'21 years ago',
				'Different year',
			],
			[
				'ml',
				'20111231170000',
				'20120101000000',
				'7 മണിക്കൂർ മുമ്പ്',
				'"Yesterday" across years',
			],
			[
				'ml',
				'20120717190900',
				'20120717190929',
				'29 സെക്കൻഡ് മുമ്പ്',
				'"Just now"',
			],
			[
				'ml',
				'20120717190900',
				'20120717191530',
				'6 മിനിറ്റ് മുമ്പ്',
				'X minutes ago',
			],
			[
				'ml',
				'20121006173100',
				'20121006173200',
				'1 മിനിറ്റ് മുമ്പ്',
				'"1 minute ago"',
			],
			[
				'ml',
				'20120617190900',
				'20120717190900',
				'1 മാസം മുമ്പ്',
				'Month difference'
			],
			[
				'ml',
				'19910130151500',
				'20120716193700',
				'21 വർഷം മുമ്പ്',
				'Different year',
			],
			[
				'ml',
				'20120714184300',
				'20120715040000',
				'9 മണിക്കൂർ മുമ്പ്',
				'Today at another time',
			],
			[
				'ml',
				'20120617190900',
				'20120717190900',
				'1 മാസം മുമ്പ്',
				'Another month'
			],
			[
				'ml',
				'19910130151500',
				'20120716193700',
				'21 വർഷം മുമ്പ്',
				'Different year',
			],
		];
	}
}