1/* 2 * Copyright (C) 2015 The Android Open Source Project 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 17package libcore.libcore.icu; 18 19import java.util.Calendar; 20import java.util.Locale; 21import java.util.TimeZone; 22 23import libcore.icu.RelativeDateTimeFormatter; 24 25import static libcore.icu.DateUtilsBridge.FORMAT_ABBREV_ALL; 26import static libcore.icu.DateUtilsBridge.FORMAT_ABBREV_RELATIVE; 27import static libcore.icu.DateUtilsBridge.FORMAT_NO_YEAR; 28import static libcore.icu.DateUtilsBridge.FORMAT_NUMERIC_DATE; 29import static libcore.icu.DateUtilsBridge.FORMAT_SHOW_YEAR; 30import static libcore.icu.RelativeDateTimeFormatter.DAY_IN_MILLIS; 31import static libcore.icu.RelativeDateTimeFormatter.HOUR_IN_MILLIS; 32import static libcore.icu.RelativeDateTimeFormatter.MINUTE_IN_MILLIS; 33import static libcore.icu.RelativeDateTimeFormatter.SECOND_IN_MILLIS; 34import static libcore.icu.RelativeDateTimeFormatter.WEEK_IN_MILLIS; 35import static libcore.icu.RelativeDateTimeFormatter.YEAR_IN_MILLIS; 36import static libcore.icu.RelativeDateTimeFormatter.getRelativeDateTimeString; 37import static libcore.icu.RelativeDateTimeFormatter.getRelativeTimeSpanString; 38 39public class RelativeDateTimeFormatterTest extends junit.framework.TestCase { 40 41 // Tests adopted from CTS tests for DateUtils.getRelativeTimeSpanString. 42 public void test_getRelativeTimeSpanStringCTS() throws Exception { 43 Locale en_US = new Locale("en", "US"); 44 TimeZone tz = TimeZone.getTimeZone("GMT"); 45 Calendar cal = Calendar.getInstance(tz, en_US); 46 // Feb 5, 2015 at 10:50 GMT 47 cal.set(2015, Calendar.FEBRUARY, 5, 10, 50, 0); 48 final long baseTime = cal.getTimeInMillis(); 49 50 assertEquals("0 minutes ago", 51 getRelativeTimeSpanString(en_US, tz, baseTime - SECOND_IN_MILLIS, baseTime, 52 MINUTE_IN_MILLIS, 0)); 53 assertEquals("In 0 minutes", 54 getRelativeTimeSpanString(en_US, tz, baseTime + SECOND_IN_MILLIS, baseTime, 55 MINUTE_IN_MILLIS, 0)); 56 57 assertEquals("1 minute ago", 58 getRelativeTimeSpanString(en_US, tz, 0, MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, 0)); 59 assertEquals("In 1 minute", 60 getRelativeTimeSpanString(en_US, tz, MINUTE_IN_MILLIS, 0, MINUTE_IN_MILLIS, 0)); 61 62 assertEquals("42 minutes ago", 63 getRelativeTimeSpanString(en_US, tz, baseTime - 42 * MINUTE_IN_MILLIS, baseTime, 64 MINUTE_IN_MILLIS, 0)); 65 assertEquals("In 42 minutes", 66 getRelativeTimeSpanString(en_US, tz, baseTime + 42 * MINUTE_IN_MILLIS, baseTime, 67 MINUTE_IN_MILLIS, 0)); 68 69 final long TWO_HOURS_IN_MS = 2 * HOUR_IN_MILLIS; 70 assertEquals("2 hours ago", 71 getRelativeTimeSpanString(en_US, tz, baseTime - TWO_HOURS_IN_MS, baseTime, 72 MINUTE_IN_MILLIS, FORMAT_NUMERIC_DATE)); 73 assertEquals("In 2 hours", 74 getRelativeTimeSpanString(en_US, tz, baseTime + TWO_HOURS_IN_MS, baseTime, 75 MINUTE_IN_MILLIS, FORMAT_NUMERIC_DATE)); 76 77 assertEquals("In 42 min.", 78 getRelativeTimeSpanString(en_US, tz, baseTime + (42 * MINUTE_IN_MILLIS), baseTime, 79 MINUTE_IN_MILLIS, FORMAT_ABBREV_RELATIVE)); 80 81 assertEquals("Tomorrow", 82 getRelativeTimeSpanString(en_US, tz, DAY_IN_MILLIS, 0, DAY_IN_MILLIS, 0)); 83 assertEquals("In 2 days", 84 getRelativeTimeSpanString(en_US, tz, 2 * DAY_IN_MILLIS, 0, DAY_IN_MILLIS, 0)); 85 assertEquals("Yesterday", 86 getRelativeTimeSpanString(en_US, tz, 0, DAY_IN_MILLIS, DAY_IN_MILLIS, 0)); 87 assertEquals("2 days ago", 88 getRelativeTimeSpanString(en_US, tz, 0, 2 * DAY_IN_MILLIS, DAY_IN_MILLIS, 0)); 89 90 final long DAY_DURATION = 5 * 24 * 60 * 60 * 1000; 91 assertEquals("5 days ago", 92 getRelativeTimeSpanString(en_US, tz, baseTime - DAY_DURATION, baseTime, 93 DAY_IN_MILLIS, 0)); 94 } 95 96 private void test_getRelativeTimeSpanString_helper(long delta, long minResolution, int flags, 97 String expectedInPast, 98 String expectedInFuture) throws Exception { 99 Locale en_US = new Locale("en", "US"); 100 TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); 101 Calendar cal = Calendar.getInstance(tz, en_US); 102 // Feb 5, 2015 at 10:50 PST 103 cal.set(2015, Calendar.FEBRUARY, 5, 10, 50, 0); 104 final long base = cal.getTimeInMillis(); 105 106 assertEquals(expectedInPast, 107 getRelativeTimeSpanString(en_US, tz, base - delta, base, minResolution, flags)); 108 assertEquals(expectedInFuture, 109 getRelativeTimeSpanString(en_US, tz, base + delta, base, minResolution, flags)); 110 } 111 112 private void test_getRelativeTimeSpanString_helper(long delta, long minResolution, 113 String expectedInPast, 114 String expectedInFuture) throws Exception { 115 test_getRelativeTimeSpanString_helper(delta, minResolution, 0, expectedInPast, expectedInFuture); 116 } 117 118 public void test_getRelativeTimeSpanString() throws Exception { 119 120 test_getRelativeTimeSpanString_helper(0 * SECOND_IN_MILLIS, 0, "0 seconds ago", "0 seconds ago"); 121 test_getRelativeTimeSpanString_helper(1 * MINUTE_IN_MILLIS, 0, "1 minute ago", "In 1 minute"); 122 test_getRelativeTimeSpanString_helper(1 * MINUTE_IN_MILLIS, 0, "1 minute ago", "In 1 minute"); 123 test_getRelativeTimeSpanString_helper(5 * DAY_IN_MILLIS, 0, "5 days ago", "In 5 days"); 124 125 test_getRelativeTimeSpanString_helper(0 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, "0 seconds ago", 126 "0 seconds ago"); 127 test_getRelativeTimeSpanString_helper(1 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, "1 second ago", 128 "In 1 second"); 129 test_getRelativeTimeSpanString_helper(2 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, "2 seconds ago", 130 "In 2 seconds"); 131 test_getRelativeTimeSpanString_helper(25 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, "25 seconds ago", 132 "In 25 seconds"); 133 test_getRelativeTimeSpanString_helper(75 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, "1 minute ago", 134 "In 1 minute"); 135 test_getRelativeTimeSpanString_helper(5000 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, "1 hour ago", 136 "In 1 hour"); 137 138 test_getRelativeTimeSpanString_helper(0 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, "0 minutes ago", 139 "0 minutes ago"); 140 test_getRelativeTimeSpanString_helper(1 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, "1 minute ago", 141 "In 1 minute"); 142 test_getRelativeTimeSpanString_helper(2 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, "2 minutes ago", 143 "In 2 minutes"); 144 test_getRelativeTimeSpanString_helper(25 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, "25 minutes ago", 145 "In 25 minutes"); 146 test_getRelativeTimeSpanString_helper(75 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, "1 hour ago", 147 "In 1 hour"); 148 test_getRelativeTimeSpanString_helper(720 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, "12 hours ago", 149 "In 12 hours"); 150 151 test_getRelativeTimeSpanString_helper(0 * HOUR_IN_MILLIS, HOUR_IN_MILLIS, "0 hours ago", 152 "0 hours ago"); 153 test_getRelativeTimeSpanString_helper(1 * HOUR_IN_MILLIS, HOUR_IN_MILLIS, "1 hour ago", 154 "In 1 hour"); 155 test_getRelativeTimeSpanString_helper(2 * HOUR_IN_MILLIS, HOUR_IN_MILLIS, "2 hours ago", 156 "In 2 hours"); 157 test_getRelativeTimeSpanString_helper(5 * HOUR_IN_MILLIS, HOUR_IN_MILLIS, "5 hours ago", 158 "In 5 hours"); 159 test_getRelativeTimeSpanString_helper(20 * HOUR_IN_MILLIS, HOUR_IN_MILLIS, "20 hours ago", 160 "In 20 hours"); 161 162 test_getRelativeTimeSpanString_helper(0 * DAY_IN_MILLIS, DAY_IN_MILLIS, "Today", "Today"); 163 test_getRelativeTimeSpanString_helper(20 * HOUR_IN_MILLIS, DAY_IN_MILLIS, "Yesterday", 164 "Tomorrow"); 165 test_getRelativeTimeSpanString_helper(24 * HOUR_IN_MILLIS, DAY_IN_MILLIS, "Yesterday", 166 "Tomorrow"); 167 test_getRelativeTimeSpanString_helper(2 * DAY_IN_MILLIS, DAY_IN_MILLIS, "2 days ago", 168 "In 2 days"); 169 test_getRelativeTimeSpanString_helper(25 * DAY_IN_MILLIS, DAY_IN_MILLIS, "January 11", 170 "March 2"); 171 172 test_getRelativeTimeSpanString_helper(0 * WEEK_IN_MILLIS, WEEK_IN_MILLIS, "0 weeks ago", 173 "0 weeks ago"); 174 test_getRelativeTimeSpanString_helper(1 * WEEK_IN_MILLIS, WEEK_IN_MILLIS, "1 week ago", 175 "In 1 week"); 176 test_getRelativeTimeSpanString_helper(2 * WEEK_IN_MILLIS, WEEK_IN_MILLIS, "2 weeks ago", 177 "In 2 weeks"); 178 test_getRelativeTimeSpanString_helper(25 * WEEK_IN_MILLIS, WEEK_IN_MILLIS, "25 weeks ago", 179 "In 25 weeks"); 180 181 // duration >= minResolution 182 test_getRelativeTimeSpanString_helper(30 * SECOND_IN_MILLIS, 0, "30 seconds ago", 183 "In 30 seconds"); 184 test_getRelativeTimeSpanString_helper(30 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, 185 "30 minutes ago", "In 30 minutes"); 186 test_getRelativeTimeSpanString_helper(30 * HOUR_IN_MILLIS, MINUTE_IN_MILLIS, "Yesterday", 187 "Tomorrow"); 188 test_getRelativeTimeSpanString_helper(5 * DAY_IN_MILLIS, MINUTE_IN_MILLIS, "5 days ago", 189 "In 5 days"); 190 test_getRelativeTimeSpanString_helper(30 * WEEK_IN_MILLIS, MINUTE_IN_MILLIS, "July 10, 2014", 191 "September 3"); 192 test_getRelativeTimeSpanString_helper(5 * 365 * DAY_IN_MILLIS, MINUTE_IN_MILLIS, 193 "February 6, 2010", "February 4, 2020"); 194 195 test_getRelativeTimeSpanString_helper(60 * SECOND_IN_MILLIS, MINUTE_IN_MILLIS, "1 minute ago", 196 "In 1 minute"); 197 test_getRelativeTimeSpanString_helper(120 * SECOND_IN_MILLIS - 1, MINUTE_IN_MILLIS, 198 "1 minute ago", "In 1 minute"); 199 test_getRelativeTimeSpanString_helper(60 * MINUTE_IN_MILLIS, HOUR_IN_MILLIS, "1 hour ago", 200 "In 1 hour"); 201 test_getRelativeTimeSpanString_helper(120 * MINUTE_IN_MILLIS - 1, HOUR_IN_MILLIS, "1 hour ago", 202 "In 1 hour"); 203 test_getRelativeTimeSpanString_helper(2 * HOUR_IN_MILLIS, DAY_IN_MILLIS, "Today", "Today"); 204 test_getRelativeTimeSpanString_helper(12 * HOUR_IN_MILLIS, DAY_IN_MILLIS, "Yesterday", 205 "Today"); 206 test_getRelativeTimeSpanString_helper(24 * HOUR_IN_MILLIS, DAY_IN_MILLIS, "Yesterday", 207 "Tomorrow"); 208 test_getRelativeTimeSpanString_helper(48 * HOUR_IN_MILLIS, DAY_IN_MILLIS, "2 days ago", 209 "In 2 days"); 210 test_getRelativeTimeSpanString_helper(45 * HOUR_IN_MILLIS, DAY_IN_MILLIS, "2 days ago", 211 "In 2 days"); 212 test_getRelativeTimeSpanString_helper(7 * DAY_IN_MILLIS, WEEK_IN_MILLIS, "1 week ago", 213 "In 1 week"); 214 test_getRelativeTimeSpanString_helper(14 * DAY_IN_MILLIS - 1, WEEK_IN_MILLIS, "1 week ago", 215 "In 1 week"); 216 217 // duration < minResolution 218 test_getRelativeTimeSpanString_helper(59 * SECOND_IN_MILLIS, MINUTE_IN_MILLIS, "0 minutes ago", 219 "In 0 minutes"); 220 test_getRelativeTimeSpanString_helper(59 * MINUTE_IN_MILLIS, HOUR_IN_MILLIS, "0 hours ago", 221 "In 0 hours"); 222 test_getRelativeTimeSpanString_helper(HOUR_IN_MILLIS - 1, HOUR_IN_MILLIS, "0 hours ago", 223 "In 0 hours"); 224 test_getRelativeTimeSpanString_helper(DAY_IN_MILLIS - 1, DAY_IN_MILLIS, "Yesterday", 225 "Tomorrow"); 226 test_getRelativeTimeSpanString_helper(20 * SECOND_IN_MILLIS, WEEK_IN_MILLIS, "0 weeks ago", 227 "In 0 weeks"); 228 test_getRelativeTimeSpanString_helper(WEEK_IN_MILLIS - 1, WEEK_IN_MILLIS, "0 weeks ago", 229 "In 0 weeks"); 230 } 231 232 public void test_getRelativeTimeSpanStringAbbrev() throws Exception { 233 int flags = FORMAT_ABBREV_RELATIVE; 234 235 test_getRelativeTimeSpanString_helper(0 * SECOND_IN_MILLIS, 0, flags, "0 sec. ago", 236 "0 sec. ago"); 237 test_getRelativeTimeSpanString_helper(1 * MINUTE_IN_MILLIS, 0, flags, "1 min. ago", 238 "In 1 min."); 239 test_getRelativeTimeSpanString_helper(5 * DAY_IN_MILLIS, 0, flags, "5 days ago", "In 5 days"); 240 241 test_getRelativeTimeSpanString_helper(0 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, flags, 242 "0 sec. ago", "0 sec. ago"); 243 test_getRelativeTimeSpanString_helper(1 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, flags, 244 "1 sec. ago", "In 1 sec."); 245 test_getRelativeTimeSpanString_helper(2 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, flags, 246 "2 sec. ago", "In 2 sec."); 247 test_getRelativeTimeSpanString_helper(25 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, flags, 248 "25 sec. ago", "In 25 sec."); 249 test_getRelativeTimeSpanString_helper(75 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, flags, 250 "1 min. ago", "In 1 min."); 251 test_getRelativeTimeSpanString_helper(5000 * SECOND_IN_MILLIS, SECOND_IN_MILLIS, flags, 252 "1 hr. ago", "In 1 hr."); 253 254 test_getRelativeTimeSpanString_helper(0 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, flags, 255 "0 min. ago", "0 min. ago"); 256 test_getRelativeTimeSpanString_helper(1 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, flags, 257 "1 min. ago", "In 1 min."); 258 test_getRelativeTimeSpanString_helper(2 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, flags, 259 "2 min. ago", "In 2 min."); 260 test_getRelativeTimeSpanString_helper(25 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, flags, 261 "25 min. ago", "In 25 min."); 262 test_getRelativeTimeSpanString_helper(75 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, flags, 263 "1 hr. ago", "In 1 hr."); 264 test_getRelativeTimeSpanString_helper(720 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, flags, 265 "12 hr. ago", "In 12 hr."); 266 267 test_getRelativeTimeSpanString_helper(0 * HOUR_IN_MILLIS, HOUR_IN_MILLIS, flags, 268 "0 hr. ago", "0 hr. ago"); 269 test_getRelativeTimeSpanString_helper(1 * HOUR_IN_MILLIS, HOUR_IN_MILLIS, flags, 270 "1 hr. ago", "In 1 hr."); 271 test_getRelativeTimeSpanString_helper(2 * HOUR_IN_MILLIS, HOUR_IN_MILLIS, flags, 272 "2 hr. ago", "In 2 hr."); 273 test_getRelativeTimeSpanString_helper(5 * HOUR_IN_MILLIS, HOUR_IN_MILLIS, flags, 274 "5 hr. ago", "In 5 hr."); 275 test_getRelativeTimeSpanString_helper(20 * HOUR_IN_MILLIS, HOUR_IN_MILLIS, flags, 276 "20 hr. ago", "In 20 hr."); 277 278 test_getRelativeTimeSpanString_helper(0 * DAY_IN_MILLIS, DAY_IN_MILLIS, flags, "Today", 279 "Today"); 280 test_getRelativeTimeSpanString_helper(20 * HOUR_IN_MILLIS, DAY_IN_MILLIS, flags, 281 "Yesterday", "Tomorrow"); 282 test_getRelativeTimeSpanString_helper(24 * HOUR_IN_MILLIS, DAY_IN_MILLIS, flags, 283 "Yesterday", "Tomorrow"); 284 test_getRelativeTimeSpanString_helper(2 * DAY_IN_MILLIS, DAY_IN_MILLIS, flags, 285 "2 days ago", "In 2 days"); 286 test_getRelativeTimeSpanString_helper(25 * DAY_IN_MILLIS, DAY_IN_MILLIS, flags, 287 "January 11", "March 2"); 288 289 test_getRelativeTimeSpanString_helper(0 * WEEK_IN_MILLIS, WEEK_IN_MILLIS, flags, 290 "0 wk. ago", "0 wk. ago"); 291 test_getRelativeTimeSpanString_helper(1 * WEEK_IN_MILLIS, WEEK_IN_MILLIS, flags, 292 "1 wk. ago", "In 1 wk."); 293 test_getRelativeTimeSpanString_helper(2 * WEEK_IN_MILLIS, WEEK_IN_MILLIS, flags, 294 "2 wk. ago", "In 2 wk."); 295 test_getRelativeTimeSpanString_helper(25 * WEEK_IN_MILLIS, WEEK_IN_MILLIS, flags, 296 "25 wk. ago", "In 25 wk."); 297 298 // duration >= minResolution 299 test_getRelativeTimeSpanString_helper(30 * SECOND_IN_MILLIS, 0, flags, "30 sec. ago", 300 "In 30 sec."); 301 test_getRelativeTimeSpanString_helper(30 * MINUTE_IN_MILLIS, MINUTE_IN_MILLIS, flags, 302 "30 min. ago", "In 30 min."); 303 test_getRelativeTimeSpanString_helper(30 * HOUR_IN_MILLIS, MINUTE_IN_MILLIS, flags, 304 "Yesterday", "Tomorrow"); 305 test_getRelativeTimeSpanString_helper(5 * DAY_IN_MILLIS, MINUTE_IN_MILLIS, flags, 306 "5 days ago", "In 5 days"); 307 test_getRelativeTimeSpanString_helper(30 * WEEK_IN_MILLIS, MINUTE_IN_MILLIS, flags, 308 "July 10, 2014", "September 3"); 309 test_getRelativeTimeSpanString_helper(5 * 365 * DAY_IN_MILLIS, MINUTE_IN_MILLIS, flags, 310 "February 6, 2010", "February 4, 2020"); 311 312 test_getRelativeTimeSpanString_helper(60 * SECOND_IN_MILLIS, MINUTE_IN_MILLIS, flags, 313 "1 min. ago", "In 1 min."); 314 test_getRelativeTimeSpanString_helper(120 * SECOND_IN_MILLIS - 1, MINUTE_IN_MILLIS, flags, 315 "1 min. ago", "In 1 min."); 316 test_getRelativeTimeSpanString_helper(60 * MINUTE_IN_MILLIS, HOUR_IN_MILLIS, flags, 317 "1 hr. ago", "In 1 hr."); 318 test_getRelativeTimeSpanString_helper(120 * MINUTE_IN_MILLIS - 1, HOUR_IN_MILLIS, flags, 319 "1 hr. ago", "In 1 hr."); 320 test_getRelativeTimeSpanString_helper(2 * HOUR_IN_MILLIS, DAY_IN_MILLIS, flags, "Today", 321 "Today"); 322 test_getRelativeTimeSpanString_helper(12 * HOUR_IN_MILLIS, DAY_IN_MILLIS, flags, 323 "Yesterday", "Today"); 324 test_getRelativeTimeSpanString_helper(24 * HOUR_IN_MILLIS, DAY_IN_MILLIS, flags, 325 "Yesterday", "Tomorrow"); 326 test_getRelativeTimeSpanString_helper(48 * HOUR_IN_MILLIS, DAY_IN_MILLIS, flags, 327 "2 days ago", "In 2 days"); 328 test_getRelativeTimeSpanString_helper(45 * HOUR_IN_MILLIS, DAY_IN_MILLIS, flags, 329 "2 days ago", "In 2 days"); 330 test_getRelativeTimeSpanString_helper(7 * DAY_IN_MILLIS, WEEK_IN_MILLIS, flags, 331 "1 wk. ago", "In 1 wk."); 332 test_getRelativeTimeSpanString_helper(14 * DAY_IN_MILLIS - 1, WEEK_IN_MILLIS, flags, 333 "1 wk. ago", "In 1 wk."); 334 335 // duration < minResolution 336 test_getRelativeTimeSpanString_helper(59 * SECOND_IN_MILLIS, MINUTE_IN_MILLIS, flags, 337 "0 min. ago", "In 0 min."); 338 test_getRelativeTimeSpanString_helper(59 * MINUTE_IN_MILLIS, HOUR_IN_MILLIS, flags, 339 "0 hr. ago", "In 0 hr."); 340 test_getRelativeTimeSpanString_helper(HOUR_IN_MILLIS - 1, HOUR_IN_MILLIS, flags, 341 "0 hr. ago", "In 0 hr."); 342 test_getRelativeTimeSpanString_helper(DAY_IN_MILLIS - 1, DAY_IN_MILLIS, flags, 343 "Yesterday", "Tomorrow"); 344 test_getRelativeTimeSpanString_helper(20 * SECOND_IN_MILLIS, WEEK_IN_MILLIS, flags, 345 "0 wk. ago", "In 0 wk."); 346 test_getRelativeTimeSpanString_helper(WEEK_IN_MILLIS - 1, WEEK_IN_MILLIS, flags, 347 "0 wk. ago", "In 0 wk."); 348 349 } 350 351 public void test_getRelativeTimeSpanStringGerman() throws Exception { 352 // Bug: 19744876 353 // We need to specify the timezone and the time explicitly. Otherwise it 354 // may not always give a correct answer of "tomorrow" by using 355 // (now + DAY_IN_MILLIS). 356 Locale de_DE = new Locale("de", "DE"); 357 TimeZone tz = TimeZone.getTimeZone("Europe/Berlin"); 358 Calendar cal = Calendar.getInstance(tz, de_DE); 359 // Feb 5, 2015 at 10:50 CET 360 cal.set(2015, Calendar.FEBRUARY, 5, 10, 50, 0); 361 final long now = cal.getTimeInMillis(); 362 363 // 42 minutes ago 364 assertEquals("Vor 42 Minuten", getRelativeTimeSpanString(de_DE, tz, 365 now - 42 * MINUTE_IN_MILLIS, now, MINUTE_IN_MILLIS, 0)); 366 // In 42 minutes 367 assertEquals("In 42 Minuten", getRelativeTimeSpanString(de_DE, tz, 368 now + 42 * MINUTE_IN_MILLIS, now, MINUTE_IN_MILLIS, 0)); 369 // Yesterday 370 assertEquals("Gestern", getRelativeTimeSpanString(de_DE, tz, 371 now - DAY_IN_MILLIS, now, DAY_IN_MILLIS, 0)); 372 // The day before yesterday 373 assertEquals("Vorgestern", getRelativeTimeSpanString(de_DE, tz, 374 now - 2 * DAY_IN_MILLIS, now, DAY_IN_MILLIS, 0)); 375 // Tomorrow 376 assertEquals("Morgen", getRelativeTimeSpanString(de_DE, tz, 377 now + DAY_IN_MILLIS, now, DAY_IN_MILLIS, 0)); 378 // The day after tomorrow 379 assertEquals("Übermorgen", getRelativeTimeSpanString(de_DE, tz, 380 now + 2 * DAY_IN_MILLIS, now, DAY_IN_MILLIS, 0)); 381 } 382 383 public void test_getRelativeTimeSpanStringFrench() throws Exception { 384 Locale fr_FR = new Locale("fr", "FR"); 385 TimeZone tz = TimeZone.getTimeZone("Europe/Paris"); 386 Calendar cal = Calendar.getInstance(tz, fr_FR); 387 // Feb 5, 2015 at 10:50 CET 388 cal.set(2015, Calendar.FEBRUARY, 5, 10, 50, 0); 389 final long now = cal.getTimeInMillis(); 390 391 // 42 minutes ago 392 assertEquals("Il y a 42 minutes", getRelativeTimeSpanString(fr_FR, tz, 393 now - (42 * MINUTE_IN_MILLIS), now, MINUTE_IN_MILLIS, 0)); 394 // In 42 minutes 395 assertEquals("Dans 42 minutes", getRelativeTimeSpanString(fr_FR, tz, 396 now + (42 * MINUTE_IN_MILLIS), now, MINUTE_IN_MILLIS, 0)); 397 // Yesterday 398 assertEquals("Hier", getRelativeTimeSpanString(fr_FR, tz, 399 now - DAY_IN_MILLIS, now, DAY_IN_MILLIS, 0)); 400 // The day before yesterday 401 assertEquals("Avant-hier", getRelativeTimeSpanString(fr_FR, tz, 402 now - 2 * DAY_IN_MILLIS, now, DAY_IN_MILLIS, 0)); 403 // Tomorrow 404 assertEquals("Demain", getRelativeTimeSpanString(fr_FR, tz, 405 now + DAY_IN_MILLIS, now, DAY_IN_MILLIS, 0)); 406 // The day after tomorrow 407 assertEquals("Après-demain", getRelativeTimeSpanString(fr_FR, tz, 408 now + 2 * DAY_IN_MILLIS, now, DAY_IN_MILLIS, 0)); 409 } 410 411 // Tests adopted from CTS tests for DateUtils.getRelativeDateTimeString. 412 public void test_getRelativeDateTimeStringCTS() throws Exception { 413 Locale en_US = Locale.getDefault(); 414 TimeZone tz = TimeZone.getDefault(); 415 final long baseTime = System.currentTimeMillis(); 416 417 final long DAY_DURATION = 5 * 24 * 60 * 60 * 1000; 418 assertNotNull(getRelativeDateTimeString(en_US, tz, baseTime - DAY_DURATION, baseTime, 419 MINUTE_IN_MILLIS, DAY_IN_MILLIS, 420 FORMAT_NUMERIC_DATE)); 421 } 422 423 public void test_getRelativeDateTimeString() throws Exception { 424 Locale en_US = new Locale("en", "US"); 425 TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); 426 Calendar cal = Calendar.getInstance(tz, en_US); 427 // Feb 5, 2015 at 10:50 PST 428 cal.set(2015, Calendar.FEBRUARY, 5, 10, 50, 0); 429 final long base = cal.getTimeInMillis(); 430 431 assertEquals("5 seconds ago, 10:49 AM", 432 getRelativeDateTimeString(en_US, tz, base - 5 * SECOND_IN_MILLIS, base, 0, 433 MINUTE_IN_MILLIS, 0)); 434 assertEquals("5 min. ago, 10:45 AM", 435 getRelativeDateTimeString(en_US, tz, base - 5 * MINUTE_IN_MILLIS, base, 0, 436 HOUR_IN_MILLIS, FORMAT_ABBREV_RELATIVE)); 437 assertEquals("0 hr. ago, 10:45 AM", 438 getRelativeDateTimeString(en_US, tz, base - 5 * MINUTE_IN_MILLIS, base, 439 HOUR_IN_MILLIS, DAY_IN_MILLIS, FORMAT_ABBREV_RELATIVE)); 440 assertEquals("5 hours ago, 5:50 AM", 441 getRelativeDateTimeString(en_US, tz, base - 5 * HOUR_IN_MILLIS, base, 442 HOUR_IN_MILLIS, DAY_IN_MILLIS, 0)); 443 assertEquals("Yesterday, 7:50 PM", 444 getRelativeDateTimeString(en_US, tz, base - 15 * HOUR_IN_MILLIS, base, 0, 445 WEEK_IN_MILLIS, FORMAT_ABBREV_RELATIVE)); 446 assertEquals("5 days ago, 10:50 AM", 447 getRelativeDateTimeString(en_US, tz, base - 5 * DAY_IN_MILLIS, base, 0, 448 WEEK_IN_MILLIS, 0)); 449 assertEquals("Jan 29, 10:50 AM", 450 getRelativeDateTimeString(en_US, tz, base - 7 * DAY_IN_MILLIS, base, 0, 451 WEEK_IN_MILLIS, 0)); 452 assertEquals("11/27/2014, 10:50 AM", 453 getRelativeDateTimeString(en_US, tz, base - 10 * WEEK_IN_MILLIS, base, 0, 454 WEEK_IN_MILLIS, 0)); 455 assertEquals("11/27/2014, 10:50 AM", 456 getRelativeDateTimeString(en_US, tz, base - 10 * WEEK_IN_MILLIS, base, 0, 457 YEAR_IN_MILLIS, 0)); 458 459 // User-supplied flags should be ignored when formatting the date clause. 460 final int FORMAT_SHOW_WEEKDAY = 0x00002; 461 assertEquals("11/27/2014, 10:50 AM", 462 getRelativeDateTimeString(en_US, tz, base - 10 * WEEK_IN_MILLIS, base, 0, 463 WEEK_IN_MILLIS, 464 FORMAT_ABBREV_ALL | FORMAT_SHOW_WEEKDAY)); 465 } 466 467 public void test_getRelativeDateTimeStringDST() throws Exception { 468 Locale en_US = new Locale("en", "US"); 469 TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); 470 Calendar cal = Calendar.getInstance(tz, en_US); 471 472 // DST starts on Mar 9, 2014 at 2:00 AM. 473 // So 5 hours before 3:15 AM should be formatted as 'Yesterday, 9:15 PM'. 474 cal.set(2014, Calendar.MARCH, 9, 3, 15, 0); 475 long base = cal.getTimeInMillis(); 476 assertEquals("Yesterday, 9:15 PM", 477 getRelativeDateTimeString(en_US, tz, base - 5 * HOUR_IN_MILLIS, base, 0, 478 WEEK_IN_MILLIS, 0)); 479 480 // 1 hour after 2:00 AM should be formatted as 'In 1 hour, 4:00 AM'. 481 cal.set(2014, Calendar.MARCH, 9, 2, 0, 0); 482 base = cal.getTimeInMillis(); 483 assertEquals("In 1 hour, 4:00 AM", 484 getRelativeDateTimeString(en_US, tz, base + 1 * HOUR_IN_MILLIS, base, 0, 485 WEEK_IN_MILLIS, 0)); 486 487 // DST ends on Nov 2, 2014 at 2:00 AM. Clocks are turned backward 1 hour to 488 // 1:00 AM. 8 hours before 5:20 AM should be 'Yesterday, 10:20 PM'. 489 cal.set(2014, Calendar.NOVEMBER, 2, 5, 20, 0); 490 base = cal.getTimeInMillis(); 491 assertEquals("Yesterday, 10:20 PM", 492 getRelativeDateTimeString(en_US, tz, base - 8 * HOUR_IN_MILLIS, base, 0, 493 WEEK_IN_MILLIS, 0)); 494 495 cal.set(2014, Calendar.NOVEMBER, 2, 0, 45, 0); 496 base = cal.getTimeInMillis(); 497 // 45 minutes after 0:45 AM should be 'In 45 minutes, 1:30 AM'. 498 assertEquals("In 45 minutes, 1:30 AM", 499 getRelativeDateTimeString(en_US, tz, base + 45 * MINUTE_IN_MILLIS, base, 0, 500 WEEK_IN_MILLIS, 0)); 501 // 45 minutes later, it should be 'In 45 minutes, 1:15 AM'. 502 assertEquals("In 45 minutes, 1:15 AM", 503 getRelativeDateTimeString(en_US, tz, base + 90 * MINUTE_IN_MILLIS, 504 base + 45 * MINUTE_IN_MILLIS, 0, WEEK_IN_MILLIS, 0)); 505 // Another 45 minutes later, it should be 'In 45 minutes, 2:00 AM'. 506 assertEquals("In 45 minutes, 2:00 AM", 507 getRelativeDateTimeString(en_US, tz, base + 135 * MINUTE_IN_MILLIS, 508 base + 90 * MINUTE_IN_MILLIS, 0, WEEK_IN_MILLIS, 0)); 509 } 510 511 512 public void test_getRelativeDateTimeStringItalian() throws Exception { 513 Locale it_IT = new Locale("it", "IT"); 514 TimeZone tz = TimeZone.getTimeZone("Europe/Rome"); 515 Calendar cal = Calendar.getInstance(tz, it_IT); 516 // 05 febbraio 2015 20:15 517 cal.set(2015, Calendar.FEBRUARY, 5, 20, 15, 0); 518 final long base = cal.getTimeInMillis(); 519 520 assertEquals("5 secondi fa, 20:14", 521 getRelativeDateTimeString(it_IT, tz, base - 5 * SECOND_IN_MILLIS, base, 0, 522 MINUTE_IN_MILLIS, 0)); 523 assertEquals("5 min fa, 20:10", 524 getRelativeDateTimeString(it_IT, tz, base - 5 * MINUTE_IN_MILLIS, base, 0, 525 HOUR_IN_MILLIS, FORMAT_ABBREV_RELATIVE)); 526 assertEquals("0 h fa, 20:10", 527 getRelativeDateTimeString(it_IT, tz, base - 5 * MINUTE_IN_MILLIS, base, 528 HOUR_IN_MILLIS, DAY_IN_MILLIS, FORMAT_ABBREV_RELATIVE)); 529 assertEquals("Ieri, 22:15", 530 getRelativeDateTimeString(it_IT, tz, base - 22 * HOUR_IN_MILLIS, base, 0, 531 WEEK_IN_MILLIS, FORMAT_ABBREV_RELATIVE)); 532 assertEquals("5 giorni fa, 20:15", 533 getRelativeDateTimeString(it_IT, tz, base - 5 * DAY_IN_MILLIS, base, 0, 534 WEEK_IN_MILLIS, 0)); 535 assertEquals("27/11/2014, 20:15", 536 getRelativeDateTimeString(it_IT, tz, base - 10 * WEEK_IN_MILLIS, base, 0, 537 WEEK_IN_MILLIS, 0)); 538 } 539 540 // http://b/5252772: detect the actual date difference 541 public void test5252772() throws Exception { 542 Locale en_US = new Locale("en", "US"); 543 TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); 544 545 // Now is Sep 2, 2011, 10:23 AM PDT. 546 Calendar nowCalendar = Calendar.getInstance(tz, en_US); 547 nowCalendar.set(2011, Calendar.SEPTEMBER, 2, 10, 23, 0); 548 final long now = nowCalendar.getTimeInMillis(); 549 550 // Sep 1, 2011, 10:24 AM 551 Calendar yesterdayCalendar1 = Calendar.getInstance(tz, en_US); 552 yesterdayCalendar1.set(2011, Calendar.SEPTEMBER, 1, 10, 24, 0); 553 long yesterday1 = yesterdayCalendar1.getTimeInMillis(); 554 assertEquals("Yesterday, 10:24 AM", 555 getRelativeDateTimeString(en_US, tz, yesterday1, now, MINUTE_IN_MILLIS, 556 WEEK_IN_MILLIS, 0)); 557 558 // Sep 1, 2011, 10:22 AM 559 Calendar yesterdayCalendar2 = Calendar.getInstance(tz, en_US); 560 yesterdayCalendar2.set(2011, Calendar.SEPTEMBER, 1, 10, 22, 0); 561 long yesterday2 = yesterdayCalendar2.getTimeInMillis(); 562 assertEquals("Yesterday, 10:22 AM", 563 getRelativeDateTimeString(en_US, tz, yesterday2, now, MINUTE_IN_MILLIS, 564 WEEK_IN_MILLIS, 0)); 565 566 // Aug 31, 2011, 10:24 AM 567 Calendar twoDaysAgoCalendar1 = Calendar.getInstance(tz, en_US); 568 twoDaysAgoCalendar1.set(2011, Calendar.AUGUST, 31, 10, 24, 0); 569 long twoDaysAgo1 = twoDaysAgoCalendar1.getTimeInMillis(); 570 assertEquals("2 days ago, 10:24 AM", 571 getRelativeDateTimeString(en_US, tz, twoDaysAgo1, now, MINUTE_IN_MILLIS, 572 WEEK_IN_MILLIS, 0)); 573 574 // Aug 31, 2011, 10:22 AM 575 Calendar twoDaysAgoCalendar2 = Calendar.getInstance(tz, en_US); 576 twoDaysAgoCalendar2.set(2011, Calendar.AUGUST, 31, 10, 22, 0); 577 long twoDaysAgo2 = twoDaysAgoCalendar2.getTimeInMillis(); 578 assertEquals("2 days ago, 10:22 AM", 579 getRelativeDateTimeString(en_US, tz, twoDaysAgo2, now, MINUTE_IN_MILLIS, 580 WEEK_IN_MILLIS, 0)); 581 582 // Sep 3, 2011, 10:22 AM 583 Calendar tomorrowCalendar1 = Calendar.getInstance(tz, en_US); 584 tomorrowCalendar1.set(2011, Calendar.SEPTEMBER, 3, 10, 22, 0); 585 long tomorrow1 = tomorrowCalendar1.getTimeInMillis(); 586 assertEquals("Tomorrow, 10:22 AM", 587 getRelativeDateTimeString(en_US, tz, tomorrow1, now, MINUTE_IN_MILLIS, 588 WEEK_IN_MILLIS, 0)); 589 590 // Sep 3, 2011, 10:24 AM 591 Calendar tomorrowCalendar2 = Calendar.getInstance(tz, en_US); 592 tomorrowCalendar2.set(2011, Calendar.SEPTEMBER, 3, 10, 24, 0); 593 long tomorrow2 = tomorrowCalendar2.getTimeInMillis(); 594 assertEquals("Tomorrow, 10:24 AM", 595 getRelativeDateTimeString(en_US, tz, tomorrow2, now, MINUTE_IN_MILLIS, 596 WEEK_IN_MILLIS, 0)); 597 598 // Sep 4, 2011, 10:22 AM 599 Calendar twoDaysLaterCalendar1 = Calendar.getInstance(tz, en_US); 600 twoDaysLaterCalendar1.set(2011, Calendar.SEPTEMBER, 4, 10, 22, 0); 601 long twoDaysLater1 = twoDaysLaterCalendar1.getTimeInMillis(); 602 assertEquals("In 2 days, 10:22 AM", 603 getRelativeDateTimeString(en_US, tz, twoDaysLater1, now, MINUTE_IN_MILLIS, 604 WEEK_IN_MILLIS, 0)); 605 606 // Sep 4, 2011, 10:24 AM 607 Calendar twoDaysLaterCalendar2 = Calendar.getInstance(tz, en_US); 608 twoDaysLaterCalendar2.set(2011, Calendar.SEPTEMBER, 4, 10, 24, 0); 609 long twoDaysLater2 = twoDaysLaterCalendar2.getTimeInMillis(); 610 assertEquals("In 2 days, 10:24 AM", 611 getRelativeDateTimeString(en_US, tz, twoDaysLater2, now, MINUTE_IN_MILLIS, 612 WEEK_IN_MILLIS, 0)); 613 } 614 615 // b/19822016: show / hide the year based on the dates in the arguments. 616 public void test_bug19822016() throws Exception { 617 Locale en_US = new Locale("en", "US"); 618 TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); 619 Calendar cal = Calendar.getInstance(tz, en_US); 620 // Feb 5, 2012 at 10:50 PST 621 cal.set(2012, Calendar.FEBRUARY, 5, 10, 50, 0); 622 long base = cal.getTimeInMillis(); 623 624 assertEquals("Feb 5, 5:50 AM", getRelativeDateTimeString(en_US, tz, 625 base - 5 * HOUR_IN_MILLIS, base, 0, MINUTE_IN_MILLIS, 0)); 626 assertEquals("Jan 29, 10:50 AM", getRelativeDateTimeString(en_US, tz, 627 base - 7 * DAY_IN_MILLIS, base, 0, WEEK_IN_MILLIS, 0)); 628 assertEquals("11/27/2011, 10:50 AM", getRelativeDateTimeString(en_US, tz, 629 base - 10 * WEEK_IN_MILLIS, base, 0, WEEK_IN_MILLIS, 0)); 630 631 assertEquals("January 6", getRelativeTimeSpanString(en_US, tz, 632 base - 30 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, 0)); 633 assertEquals("January 6", getRelativeTimeSpanString(en_US, tz, 634 base - 30 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, FORMAT_NO_YEAR)); 635 assertEquals("January 6, 2012", getRelativeTimeSpanString(en_US, tz, 636 base - 30 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, FORMAT_SHOW_YEAR)); 637 assertEquals("December 7, 2011", getRelativeTimeSpanString(en_US, tz, 638 base - 60 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, 0)); 639 assertEquals("December 7, 2011", getRelativeTimeSpanString(en_US, tz, 640 base - 60 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, FORMAT_SHOW_YEAR)); 641 assertEquals("December 7", getRelativeTimeSpanString(en_US, tz, 642 base - 60 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, FORMAT_NO_YEAR)); 643 644 // Feb 5, 2018 at 10:50 PST 645 cal.set(2018, Calendar.FEBRUARY, 5, 10, 50, 0); 646 base = cal.getTimeInMillis(); 647 assertEquals("Feb 5, 5:50 AM", getRelativeDateTimeString(en_US, tz, 648 base - 5 * HOUR_IN_MILLIS, base, 0, MINUTE_IN_MILLIS, 0)); 649 assertEquals("Jan 29, 10:50 AM", getRelativeDateTimeString(en_US, tz, 650 base - 7 * DAY_IN_MILLIS, base, 0, WEEK_IN_MILLIS, 0)); 651 assertEquals("11/27/2017, 10:50 AM", getRelativeDateTimeString(en_US, tz, 652 base - 10 * WEEK_IN_MILLIS, base, 0, WEEK_IN_MILLIS, 0)); 653 654 assertEquals("January 6", getRelativeTimeSpanString(en_US, tz, 655 base - 30 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, 0)); 656 assertEquals("January 6", getRelativeTimeSpanString(en_US, tz, 657 base - 30 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, FORMAT_NO_YEAR)); 658 assertEquals("January 6, 2018", getRelativeTimeSpanString(en_US, tz, 659 base - 30 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, FORMAT_SHOW_YEAR)); 660 assertEquals("December 7, 2017", getRelativeTimeSpanString(en_US, tz, 661 base - 60 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, 0)); 662 assertEquals("December 7, 2017", getRelativeTimeSpanString(en_US, tz, 663 base - 60 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, FORMAT_SHOW_YEAR)); 664 assertEquals("December 7", getRelativeTimeSpanString(en_US, tz, 665 base - 60 * DAY_IN_MILLIS, base, DAY_IN_MILLIS, FORMAT_NO_YEAR)); 666 } 667 668 // Check for missing ICU data. http://b/25821045 669 public void test_bug25821045() { 670 final TimeZone tz = TimeZone.getDefault(); 671 final long now = System.currentTimeMillis(); 672 final long time = now + 1000; 673 final int minResolution = 1000 * 60; 674 final int transitionResolution = minResolution; 675 final int flags = FORMAT_ABBREV_RELATIVE; 676 // Exercise all available locales, forcing the ICU implementation to pre-cache the data. This 677 // highlights data issues. It can take a while. 678 for (Locale locale : Locale.getAvailableLocales()) { 679 // In (e.g.) ICU56 an exception is thrown on the first use for a locale if required data for 680 // the "other" plural is missing. It doesn't matter what is actually formatted. 681 try { 682 RelativeDateTimeFormatter.getRelativeDateTimeString( 683 locale, tz, time, now, minResolution, transitionResolution, flags); 684 } catch (IllegalStateException e) { 685 fail("Failed to format for " + locale); 686 } 687 } 688 } 689 690 // Check for ICU data lookup fallback failure. http://b/25883157 691 public void test_bug25883157() { 692 final Locale locale = new Locale("en", "GB"); 693 final TimeZone tz = TimeZone.getTimeZone("GMT"); 694 695 final Calendar cal = Calendar.getInstance(tz, locale); 696 cal.set(2015, Calendar.JUNE, 19, 12, 0, 0); 697 698 final long base = cal.getTimeInMillis(); 699 final long time = base + 2 * WEEK_IN_MILLIS; 700 701 assertEquals("In 2 wk", getRelativeTimeSpanString( 702 locale, tz, time, base, WEEK_IN_MILLIS, FORMAT_ABBREV_RELATIVE)); 703 } 704 705 // http://b/63745717 706 public void test_combineDateAndTime_apostrophe() { 707 final Locale locale = new Locale("fr"); 708 android.icu.text.RelativeDateTimeFormatter icuFormatter = 709 android.icu.text.RelativeDateTimeFormatter.getInstance(locale); 710 assertEquals("D à T", icuFormatter.combineDateAndTime("D", "T")); 711 // Ensure single quote ' and curly braces {} are not interpreted in input values. 712 assertEquals("D'x' à T{0}", icuFormatter.combineDateAndTime("D'x'", "T{0}")); 713 } 714} 715