|
| 1 | +package org.ocpsoft.prettytime; |
| 2 | + |
| 3 | +import org.junit.After; |
| 4 | +import org.junit.Before; |
| 5 | +import org.junit.Test; |
| 6 | + |
| 7 | +import java.text.SimpleDateFormat; |
| 8 | +import java.util.Date; |
| 9 | +import java.util.Locale; |
| 10 | + |
| 11 | +import static org.junit.Assert.assertEquals; |
| 12 | + |
| 13 | +/** |
| 14 | + * Created by Azimkhan Yerzhan on 5/8/2017 |
| 15 | + */ |
| 16 | +public class PrettyTimeI18n_kk_Test { |
| 17 | + private final SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); |
| 18 | + private Locale locale; |
| 19 | + |
| 20 | + @Before |
| 21 | + public void setUp() throws Exception |
| 22 | + { |
| 23 | + locale = new Locale("kk"); |
| 24 | + Locale.setDefault(locale); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testPrettyTime() |
| 29 | + { |
| 30 | + PrettyTime p = new PrettyTime(locale); |
| 31 | + assertEquals("дәл қазір", p.format(new Date())); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testPrettyTimeCenturies() |
| 36 | + { |
| 37 | + PrettyTime p = new PrettyTime(new Date(3155692597470L * 3L), locale); |
| 38 | + assertEquals("3 ғасыр бұрын", p.format(new Date(0))); |
| 39 | + |
| 40 | + p = new PrettyTime(new Date(0), locale); |
| 41 | + assertEquals("3 ғасырдан кейін", p.format(new Date(3155692597470L * 3L))); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testCeilingInterval() throws Exception |
| 46 | + { |
| 47 | + Date then = format.parse("20/5/2009"); |
| 48 | + Date ref = format.parse("17/6/2009"); |
| 49 | + PrettyTime t = new PrettyTime(ref, locale); |
| 50 | + assertEquals("1 ай бұрын", t.format(then)); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void testNullDate() throws Exception |
| 55 | + { |
| 56 | + PrettyTime t = new PrettyTime(locale); |
| 57 | + Date date = null; |
| 58 | + assertEquals("дәл қазір", t.format(date)); |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void testRightNow() throws Exception |
| 63 | + { |
| 64 | + PrettyTime t = new PrettyTime(locale); |
| 65 | + assertEquals("дәл қазір", t.format(new Date())); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testRightNowVariance() throws Exception |
| 70 | + { |
| 71 | + PrettyTime t = new PrettyTime(new Date(0), locale); |
| 72 | + assertEquals("дәл қазір", t.format(new Date(600))); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testMinutesFromNow() throws Exception |
| 77 | + { |
| 78 | + PrettyTime t = new PrettyTime(new Date(0), locale); |
| 79 | + assertEquals("12 минуттан кейін", t.format(new Date(1000 * 60 * 12))); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void testHoursFromNow() throws Exception |
| 84 | + { |
| 85 | + PrettyTime t = new PrettyTime(new Date(0), locale); |
| 86 | + assertEquals("3 сағаттан кейін", t.format(new Date(1000 * 60 * 60 * 3))); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testDaysFromNow() throws Exception |
| 91 | + { |
| 92 | + PrettyTime t = new PrettyTime(new Date(0), locale); |
| 93 | + assertEquals("3 күннен кейін", t.format(new Date(1000 * 60 * 60 * 24 * 3))); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void testWeeksFromNow() throws Exception |
| 98 | + { |
| 99 | + PrettyTime t = new PrettyTime(new Date(0), locale); |
| 100 | + assertEquals("3 аптадан кейін", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3))); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void testMonthsFromNow() throws Exception |
| 105 | + { |
| 106 | + PrettyTime t = new PrettyTime(new Date(0), locale); |
| 107 | + assertEquals("3 айдан кейін", t.format(new Date(2629743830L * 3L))); |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void testYearsFromNow() throws Exception |
| 112 | + { |
| 113 | + PrettyTime t = new PrettyTime(new Date(0), locale); |
| 114 | + assertEquals("3 жылдан кейін", t.format(new Date(2629743830L * 12L * 3L))); |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + public void testDecadesFromNow() throws Exception |
| 119 | + { |
| 120 | + PrettyTime t = new PrettyTime(new Date(0), locale); |
| 121 | + assertEquals("3 онжылдықтан кейін", t.format(new Date(315569259747L * 3L))); |
| 122 | + } |
| 123 | + |
| 124 | + @Test |
| 125 | + public void testCenturiesFromNow() throws Exception |
| 126 | + { |
| 127 | + PrettyTime t = new PrettyTime(new Date(0), locale); |
| 128 | + assertEquals("3 ғасырдан кейін", t.format(new Date(3155692597470L * 3L))); |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + public void testMillenniaFromNow() throws Exception |
| 133 | + { |
| 134 | + PrettyTime t = new PrettyTime(new Date(0), locale); |
| 135 | + assertEquals("3 мыңжылдықтан кейін", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 1000 * 3))); |
| 136 | + } |
| 137 | + |
| 138 | + /* |
| 139 | + * Past |
| 140 | + */ |
| 141 | + @Test |
| 142 | + public void testMomentsAgo() throws Exception |
| 143 | + { |
| 144 | + PrettyTime t = new PrettyTime(new Date(6000), locale); |
| 145 | + assertEquals("жана ғана", t.format(new Date(0))); |
| 146 | + } |
| 147 | + |
| 148 | + @Test |
| 149 | + public void testMinutesAgo() throws Exception |
| 150 | + { |
| 151 | + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 12), locale); |
| 152 | + assertEquals("12 минут бұрын", t.format(new Date(0))); |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + public void testHoursAgo() throws Exception |
| 157 | + { |
| 158 | + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale); |
| 159 | + assertEquals("3 сағат бұрын", t.format(new Date(0))); |
| 160 | + } |
| 161 | + |
| 162 | + @Test |
| 163 | + public void testDaysAgo() throws Exception |
| 164 | + { |
| 165 | + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale); |
| 166 | + assertEquals("3 күн бұрын", t.format(new Date(0))); |
| 167 | + } |
| 168 | + |
| 169 | + @Test |
| 170 | + public void testWeeksAgo() throws Exception |
| 171 | + { |
| 172 | + PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale); |
| 173 | + assertEquals("3 апта бұрын", t.format(new Date(0))); |
| 174 | + } |
| 175 | + |
| 176 | + @Test |
| 177 | + public void testMonthsAgo() throws Exception |
| 178 | + { |
| 179 | + PrettyTime t = new PrettyTime(new Date(2629743830L * 3L), locale); |
| 180 | + assertEquals("3 ай бұрын", t.format(new Date(0))); |
| 181 | + } |
| 182 | + |
| 183 | + @Test |
| 184 | + public void testYearsAgo() throws Exception |
| 185 | + { |
| 186 | + PrettyTime t = new PrettyTime(new Date(2629743830L * 12L * 3L), locale); |
| 187 | + assertEquals("3 жыл бұрын", t.format(new Date(0))); |
| 188 | + } |
| 189 | + |
| 190 | + @Test |
| 191 | + public void testDecadesAgo() throws Exception |
| 192 | + { |
| 193 | + PrettyTime t = new PrettyTime(new Date(315569259747L * 3L), locale); |
| 194 | + assertEquals("3 онжылдық бұрын", t.format(new Date(0))); |
| 195 | + } |
| 196 | + |
| 197 | + @Test |
| 198 | + public void testCenturiesAgo() throws Exception |
| 199 | + { |
| 200 | + PrettyTime t = new PrettyTime(new Date(3155692597470L * 3L), locale); |
| 201 | + assertEquals("3 ғасыр бұрын", t.format(new Date(0))); |
| 202 | + } |
| 203 | + |
| 204 | + @Test |
| 205 | + public void testMillenniaAgo() throws Exception |
| 206 | + { |
| 207 | + PrettyTime t = new PrettyTime(new Date(3155692597470L * 10 * 3L), locale); |
| 208 | + // 3 millennia ago |
| 209 | + assertEquals("3 мыңжылдық бұрын", t.format(new Date(0))); |
| 210 | + } |
| 211 | + |
| 212 | + @After |
| 213 | + public void tearDown() throws Exception |
| 214 | + { |
| 215 | + Locale.setDefault(locale); |
| 216 | + } |
| 217 | +} |
0 commit comments