/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FI_Test.java

http://github.com/ocpsoft/prettytime · Java · 403 lines · 332 code · 56 blank · 15 comment · 4 complexity · fb149df597e7b41b04605a724e46bd2d MD5 · raw file

  1. /*
  2. * Copyright 2012 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.ocpsoft.prettytime;
  17. import static org.junit.Assert.assertEquals;
  18. import java.util.ArrayList;
  19. import java.util.Date;
  20. import java.util.List;
  21. import java.util.Locale;
  22. import org.junit.Before;
  23. import org.junit.Test;
  24. import org.ocpsoft.prettytime.Duration;
  25. import org.ocpsoft.prettytime.PrettyTime;
  26. import org.ocpsoft.prettytime.TimeFormat;
  27. import org.ocpsoft.prettytime.TimeUnit;
  28. import org.ocpsoft.prettytime.units.JustNow;
  29. public class PrettyTimeI18n_FI_Test {
  30. private Locale locale;
  31. @Before
  32. public void setUp() throws Exception
  33. {
  34. locale = new Locale("fi");
  35. }
  36. private PrettyTime newPrettyTimeWOJustNow(Date ref, Locale locale)
  37. {
  38. PrettyTime t = new PrettyTime(ref, locale);
  39. List<TimeUnit> units = t.getUnits();
  40. List<TimeFormat> formats = new ArrayList<TimeFormat>();
  41. for (TimeUnit timeUnit : units) {
  42. if(!(timeUnit instanceof JustNow)) {
  43. formats.add(t.getFormat(timeUnit));
  44. }
  45. }
  46. int index = 0;
  47. t.clearUnits();
  48. for (TimeUnit timeUnit : units) {
  49. if(!(timeUnit instanceof JustNow)) {
  50. t.registerUnit(timeUnit, formats.get(index));
  51. index++;
  52. }
  53. }
  54. return t;
  55. }
  56. @Test
  57. public void testRightNow() throws Exception
  58. {
  59. PrettyTime t = new PrettyTime(new Date(0), locale);
  60. assertEquals("hetken pההstה", t.format(new Date(6000)));
  61. }
  62. @Test
  63. public void testMomentsAgo() throws Exception
  64. {
  65. PrettyTime t = new PrettyTime(new Date(6000), locale);
  66. assertEquals("hetki sitten", t.format(new Date(0)));
  67. }
  68. @Test
  69. public void testMilliSecondsFromNow() throws Exception
  70. {
  71. PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale);
  72. assertEquals("13 millisekunnin pההstה", t.format(new Date(13)));
  73. }
  74. @Test
  75. public void testMilliSecondsAgo() throws Exception
  76. {
  77. PrettyTime t = newPrettyTimeWOJustNow(new Date(13), locale);
  78. assertEquals("13 millisekuntia sitten", t.format(new Date(0)));
  79. }
  80. @Test
  81. public void testMilliSecondFromNow() throws Exception
  82. {
  83. PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale);
  84. assertEquals("millisekunnin pההstה", t.format(new Date(1)));
  85. }
  86. @Test
  87. public void testMilliSecondAgo() throws Exception
  88. {
  89. PrettyTime t = newPrettyTimeWOJustNow(new Date(1), locale);
  90. assertEquals("millisekunti sitten", t.format(new Date(0)));
  91. }
  92. @Test
  93. public void testSecondsFromNow() throws Exception
  94. {
  95. PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale);
  96. assertEquals("13 sekunnin pההstה", t.format(new Date(1000 * 13)));
  97. }
  98. @Test
  99. public void testSecondsAgo() throws Exception
  100. {
  101. PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 13), locale);
  102. assertEquals("13 sekuntia sitten", t.format(new Date(0)));
  103. }
  104. @Test
  105. public void testSecondFromNow() throws Exception
  106. {
  107. PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale);
  108. assertEquals("sekunnin pההstה", t.format(new Date(1000 * 1)));
  109. }
  110. @Test
  111. public void testSecondAgo() throws Exception
  112. {
  113. PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 1), locale);
  114. assertEquals("sekunti sitten", t.format(new Date(0)));
  115. }
  116. @Test
  117. public void testMinutesFromNow() throws Exception
  118. {
  119. PrettyTime t = new PrettyTime(new Date(0), locale);
  120. assertEquals("13 minuutin pההstה", t.format(new Date(1000 * 60 * 13)));
  121. }
  122. @Test
  123. public void testMinutesAgo() throws Exception
  124. {
  125. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 13), locale);
  126. assertEquals("13 minuuttia sitten", t.format(new Date(0)));
  127. }
  128. @Test
  129. public void testMinuteFromNow() throws Exception
  130. {
  131. PrettyTime t = newPrettyTimeWOJustNow(new Date(0), locale);
  132. assertEquals("minuutin pההstה", t.format(new Date(1000 * 60 * 1)));
  133. }
  134. @Test
  135. public void testMinuteAgo() throws Exception
  136. {
  137. PrettyTime t = newPrettyTimeWOJustNow(new Date(1000 * 60 * 1), locale);
  138. assertEquals("minuutti sitten", t.format(new Date(0)));
  139. }
  140. @Test
  141. public void testHoursFromNow() throws Exception
  142. {
  143. PrettyTime t = new PrettyTime(new Date(0), locale);
  144. assertEquals("3 tunnin pההstה", t.format(new Date(1000 * 60 * 60 * 3)));
  145. }
  146. @Test
  147. public void testHoursAgo() throws Exception
  148. {
  149. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 3), locale);
  150. assertEquals("3 tuntia sitten", t.format(new Date(0)));
  151. }
  152. @Test
  153. public void testHoursFromNowSingle() throws Exception
  154. {
  155. PrettyTime t = new PrettyTime(new Date(0), locale);
  156. assertEquals("tunnin pההstה", t.format(new Date(1000 * 60 * 60 * 1)));
  157. }
  158. @Test
  159. public void testHoursAgoSingle() throws Exception
  160. {
  161. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 1), locale);
  162. assertEquals("tunti sitten", t.format(new Date(0)));
  163. }
  164. @Test
  165. public void testDaysFromNow() throws Exception
  166. {
  167. PrettyTime t = new PrettyTime(new Date(0), locale);
  168. assertEquals("3 pהivהn pההstה", t.format(new Date(1000 * 60 * 60 * 24 * 3)));
  169. }
  170. @Test
  171. public void testDaysAgo() throws Exception
  172. {
  173. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3), locale);
  174. assertEquals("3 pהivהה sitten", t.format(new Date(0)));
  175. }
  176. @Test
  177. public void testDaysFromNowSingle() throws Exception
  178. {
  179. PrettyTime t = new PrettyTime(new Date(0), locale);
  180. assertEquals("huomenna", t.format(new Date(1000 * 60 * 60 * 24 * 1)));
  181. }
  182. @Test
  183. public void testDaysAgoSingle() throws Exception
  184. {
  185. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 1), locale);
  186. assertEquals("eilen", t.format(new Date(0)));
  187. }
  188. @Test
  189. public void testWeeksFromNow() throws Exception
  190. {
  191. PrettyTime t = new PrettyTime(new Date(0), locale);
  192. assertEquals("3 viikon pההstה", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 3)));
  193. }
  194. @Test
  195. public void testWeeksAgo() throws Exception
  196. {
  197. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 3), locale);
  198. assertEquals("3 viikkoa sitten", t.format(new Date(0)));
  199. }
  200. @Test
  201. public void testWeeksFromNowSingle() throws Exception
  202. {
  203. PrettyTime t = new PrettyTime(new Date(0), locale);
  204. assertEquals("viikon pההstה", t.format(new Date(1000 * 60 * 60 * 24 * 7 * 1)));
  205. }
  206. @Test
  207. public void testWeeksAgoSingle() throws Exception
  208. {
  209. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 7 * 1), locale);
  210. assertEquals("viikko sitten", t.format(new Date(0)));
  211. }
  212. @Test
  213. public void testMonthsFromNow() throws Exception
  214. {
  215. PrettyTime t = new PrettyTime(new Date(0), locale);
  216. assertEquals("3 kuukauden pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 30 * 3)));
  217. }
  218. @Test
  219. public void testMonthsAgo() throws Exception
  220. {
  221. PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 30 * 3), locale);
  222. assertEquals("3 kuukautta sitten", t.format(new Date(0)));
  223. }
  224. @Test
  225. public void testMonthFromNow() throws Exception
  226. {
  227. PrettyTime t = new PrettyTime(new Date(0), locale);
  228. assertEquals("kuukauden pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 30 * 1)));
  229. }
  230. @Test
  231. public void testMonthAgo() throws Exception
  232. {
  233. PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 30 * 1), locale);
  234. assertEquals("kuukausi sitten", t.format(new Date(0)));
  235. }
  236. @Test
  237. public void testYearsFromNow() throws Exception
  238. {
  239. PrettyTime t = new PrettyTime(new Date(0), locale);
  240. assertEquals("3 vuoden pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 3)));
  241. }
  242. @Test
  243. public void testYearsAgo() throws Exception
  244. {
  245. PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 3), locale);
  246. assertEquals("3 vuotta sitten", t.format(new Date(0)));
  247. }
  248. @Test
  249. public void testYearFromNow() throws Exception
  250. {
  251. PrettyTime t = new PrettyTime(new Date(0), locale);
  252. assertEquals("vuoden pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 366 * 1)));
  253. }
  254. @Test
  255. public void testYearAgo() throws Exception
  256. {
  257. PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 366 * 1), locale);
  258. assertEquals("vuosi sitten", t.format(new Date(0)));
  259. }
  260. @Test
  261. public void testDecadesFromNow() throws Exception
  262. {
  263. PrettyTime t = new PrettyTime(new Date(0), locale);
  264. assertEquals("3 vuosikymmenen pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 10 * 3)));
  265. }
  266. @Test
  267. public void testDecadesAgo() throws Exception
  268. {
  269. PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 10 * 3), locale);
  270. assertEquals("3 vuosikymmentה sitten", t.format(new Date(0)));
  271. }
  272. @Test
  273. public void testDecadeFromNow() throws Exception
  274. {
  275. PrettyTime t = new PrettyTime(new Date(0), locale);
  276. assertEquals("vuosikymmenen pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 11 * 1)));
  277. }
  278. @Test
  279. public void testDecadeAgo() throws Exception
  280. {
  281. PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 11), locale);
  282. assertEquals("vuosikymmen sitten", t.format(new Date(0)));
  283. }
  284. @Test
  285. public void testCenturiesFromNow() throws Exception
  286. {
  287. PrettyTime t = new PrettyTime(new Date(0), locale);
  288. assertEquals("3 vuosisadan pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 100 * 3)));
  289. }
  290. @Test
  291. public void testCenturiesAgo() throws Exception
  292. {
  293. PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 100 * 3), locale);
  294. assertEquals("3 vuosisataa sitten", t.format(new Date(0)));
  295. }
  296. @Test
  297. public void testCenturyFromNow() throws Exception
  298. {
  299. PrettyTime t = new PrettyTime(new Date(0), locale);
  300. assertEquals("vuosisadan pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 101)));
  301. }
  302. @Test
  303. public void testCenturyAgo() throws Exception
  304. {
  305. PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 101), locale);
  306. assertEquals("vuosisata sitten", t.format(new Date(0)));
  307. }
  308. @Test
  309. public void testMillenniaFromNow() throws Exception
  310. {
  311. PrettyTime t = new PrettyTime(new Date(0), locale);
  312. assertEquals("3 vuosituhannen pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 1000 * 3)));
  313. }
  314. @Test
  315. public void testMillenniaAgo() throws Exception
  316. {
  317. PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 1000 * 3), locale);
  318. assertEquals("3 vuosituhatta sitten", t.format(new Date(0)));
  319. }
  320. @Test
  321. public void testMillenniumFromNow() throws Exception
  322. {
  323. PrettyTime t = new PrettyTime(new Date(0), locale);
  324. assertEquals("vuosituhannen pההstה", t.format(new Date(1000L * 60 * 60 * 24 * 365 * 1001)));
  325. }
  326. @Test
  327. public void testMillenniumAgo() throws Exception
  328. {
  329. PrettyTime t = new PrettyTime(new Date(1000L * 60 * 60 * 24 * 365 * 1001), locale);
  330. assertEquals("vuosituhat sitten", t.format(new Date(0)));
  331. }
  332. @Test
  333. public void testFormattingDurationListInThePast() throws Exception
  334. {
  335. PrettyTime t = new PrettyTime(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15 + 1000 * 60 * 38), locale);
  336. List<Duration> durations = t.calculatePreciseDuration(new Date(0));
  337. assertEquals("3 pהivהה 15 tuntia 38 minuuttia sitten", t.format(durations));
  338. }
  339. @Test
  340. public void testFormattingDurationListInTheFuture() throws Exception
  341. {
  342. PrettyTime t = new PrettyTime(new Date(0), locale);
  343. List<Duration> durations = t.calculatePreciseDuration(new Date(1000 * 60 * 60 * 24 * 3 + 1000 * 60 * 60 * 15
  344. + 1000 * 60 * 38));
  345. assertEquals("3 pהivהn 15 tunnin 38 minuutin pההstה", t.format(durations));
  346. }
  347. }