1 16 package org.joda.time.format; 17 18 import java.util.Locale ; 19 import java.util.TimeZone ; 20 21 import junit.framework.TestCase; 22 import junit.framework.TestSuite; 23 24 import org.joda.time.DateTime; 25 import org.joda.time.DateTimeConstants; 26 import org.joda.time.DateTimeUtils; 27 import org.joda.time.DateTimeZone; 28 29 34 public class TestISODateTimeFormat extends TestCase { 35 36 private static final DateTimeZone UTC = DateTimeZone.UTC; 37 private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris"); 38 private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London"); 39 private static final DateTimeZone TOKYO = DateTimeZone.forID("Asia/Tokyo"); 40 41 long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 42 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 43 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 44 366 + 365; 45 private long TEST_TIME_NOW = 47 (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY; 48 49 private DateTimeZone originalDateTimeZone = null; 50 private TimeZone originalTimeZone = null; 51 private Locale originalLocale = null; 52 53 public static void main(String [] args) { 54 junit.textui.TestRunner.run(suite()); 55 } 56 57 public static TestSuite suite() { 58 return new TestSuite(TestISODateTimeFormat.class); 59 } 60 61 public TestISODateTimeFormat(String name) { 62 super(name); 63 } 64 65 protected void setUp() throws Exception { 66 DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW); 67 originalDateTimeZone = DateTimeZone.getDefault(); 68 originalTimeZone = TimeZone.getDefault(); 69 originalLocale = Locale.getDefault(); 70 DateTimeZone.setDefault(LONDON); 71 TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); 72 Locale.setDefault(Locale.UK); 73 } 74 75 protected void tearDown() throws Exception { 76 DateTimeUtils.setCurrentMillisSystem(); 77 DateTimeZone.setDefault(originalDateTimeZone); 78 TimeZone.setDefault(originalTimeZone); 79 Locale.setDefault(originalLocale); 80 originalDateTimeZone = null; 81 originalTimeZone = null; 82 originalLocale = null; 83 } 84 85 public void testSubclassableConstructor() { 87 ISODateTimeFormat f = new ISODateTimeFormat() { 88 }; 90 assertNotNull(f); 91 } 92 93 public void testFormat_date() { 95 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 96 assertEquals("2004-06-09", ISODateTimeFormat.date().print(dt)); 97 98 dt = dt.withZone(LONDON); 99 assertEquals("2004-06-09", ISODateTimeFormat.date().print(dt)); 100 101 dt = dt.withZone(PARIS); 102 assertEquals("2004-06-09", ISODateTimeFormat.date().print(dt)); 103 } 104 105 public void testFormat_time() { 106 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 107 assertEquals("10:20:30.040Z", ISODateTimeFormat.time().print(dt)); 108 109 dt = dt.withZone(LONDON); 110 assertEquals("11:20:30.040+01:00", ISODateTimeFormat.time().print(dt)); 111 112 dt = dt.withZone(PARIS); 113 assertEquals("12:20:30.040+02:00", ISODateTimeFormat.time().print(dt)); 114 } 115 116 public void testFormat_timeNoMillis() { 117 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 118 assertEquals("10:20:30Z", ISODateTimeFormat.timeNoMillis().print(dt)); 119 120 dt = dt.withZone(LONDON); 121 assertEquals("11:20:30+01:00", ISODateTimeFormat.timeNoMillis().print(dt)); 122 123 dt = dt.withZone(PARIS); 124 assertEquals("12:20:30+02:00", ISODateTimeFormat.timeNoMillis().print(dt)); 125 } 126 127 public void testFormat_tTime() { 128 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 129 assertEquals("T10:20:30.040Z", ISODateTimeFormat.tTime().print(dt)); 130 131 dt = dt.withZone(LONDON); 132 assertEquals("T11:20:30.040+01:00", ISODateTimeFormat.tTime().print(dt)); 133 134 dt = dt.withZone(PARIS); 135 assertEquals("T12:20:30.040+02:00", ISODateTimeFormat.tTime().print(dt)); 136 } 137 138 public void testFormat_tTimeNoMillis() { 139 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 140 assertEquals("T10:20:30Z", ISODateTimeFormat.tTimeNoMillis().print(dt)); 141 142 dt = dt.withZone(LONDON); 143 assertEquals("T11:20:30+01:00", ISODateTimeFormat.tTimeNoMillis().print(dt)); 144 145 dt = dt.withZone(PARIS); 146 assertEquals("T12:20:30+02:00", ISODateTimeFormat.tTimeNoMillis().print(dt)); 147 } 148 149 public void testFormat_dateTime() { 150 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 151 assertEquals("2004-06-09T10:20:30.040Z", ISODateTimeFormat.dateTime().print(dt)); 152 153 dt = dt.withZone(LONDON); 154 assertEquals("2004-06-09T11:20:30.040+01:00", ISODateTimeFormat.dateTime().print(dt)); 155 156 dt = dt.withZone(PARIS); 157 assertEquals("2004-06-09T12:20:30.040+02:00", ISODateTimeFormat.dateTime().print(dt)); 158 159 } 171 172 public void testFormat_dateTimeNoMillis() { 173 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 174 assertEquals("2004-06-09T10:20:30Z", ISODateTimeFormat.dateTimeNoMillis().print(dt)); 175 176 dt = dt.withZone(LONDON); 177 assertEquals("2004-06-09T11:20:30+01:00", ISODateTimeFormat.dateTimeNoMillis().print(dt)); 178 179 dt = dt.withZone(PARIS); 180 assertEquals("2004-06-09T12:20:30+02:00", ISODateTimeFormat.dateTimeNoMillis().print(dt)); 181 } 182 183 public void testFormat_ordinalDate() { 184 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 185 assertEquals("2004-161", ISODateTimeFormat.ordinalDate().print(dt)); 186 187 dt = dt.withZone(LONDON); 188 assertEquals("2004-161", ISODateTimeFormat.ordinalDate().print(dt)); 189 190 dt = dt.withZone(PARIS); 191 assertEquals("2004-161", ISODateTimeFormat.ordinalDate().print(dt)); 192 } 193 194 public void testFormat_ordinalDateTime() { 195 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 196 assertEquals("2004-161T10:20:30.040Z", ISODateTimeFormat.ordinalDateTime().print(dt)); 197 198 dt = dt.withZone(LONDON); 199 assertEquals("2004-161T11:20:30.040+01:00", ISODateTimeFormat.ordinalDateTime().print(dt)); 200 201 dt = dt.withZone(PARIS); 202 assertEquals("2004-161T12:20:30.040+02:00", ISODateTimeFormat.ordinalDateTime().print(dt)); 203 } 204 205 public void testFormat_ordinalDateTimeNoMillis() { 206 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 207 assertEquals("2004-161T10:20:30Z", ISODateTimeFormat.ordinalDateTimeNoMillis().print(dt)); 208 209 dt = dt.withZone(LONDON); 210 assertEquals("2004-161T11:20:30+01:00", ISODateTimeFormat.ordinalDateTimeNoMillis().print(dt)); 211 212 dt = dt.withZone(PARIS); 213 assertEquals("2004-161T12:20:30+02:00", ISODateTimeFormat.ordinalDateTimeNoMillis().print(dt)); 214 } 215 216 public void testFormat_weekDate() { 217 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 218 assertEquals("2004-W24-3", ISODateTimeFormat.weekDate().print(dt)); 219 220 dt = dt.withZone(LONDON); 221 assertEquals("2004-W24-3", ISODateTimeFormat.weekDate().print(dt)); 222 223 dt = dt.withZone(PARIS); 224 assertEquals("2004-W24-3", ISODateTimeFormat.weekDate().print(dt)); 225 } 226 227 public void testFormat_weekDateTime() { 228 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 229 assertEquals("2004-W24-3T10:20:30.040Z", ISODateTimeFormat.weekDateTime().print(dt)); 230 231 dt = dt.withZone(LONDON); 232 assertEquals("2004-W24-3T11:20:30.040+01:00", ISODateTimeFormat.weekDateTime().print(dt)); 233 234 dt = dt.withZone(PARIS); 235 assertEquals("2004-W24-3T12:20:30.040+02:00", ISODateTimeFormat.weekDateTime().print(dt)); 236 } 237 238 public void testFormat_weekDateTimeNoMillis() { 239 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 240 assertEquals("2004-W24-3T10:20:30Z", ISODateTimeFormat.weekDateTimeNoMillis().print(dt)); 241 242 dt = dt.withZone(LONDON); 243 assertEquals("2004-W24-3T11:20:30+01:00", ISODateTimeFormat.weekDateTimeNoMillis().print(dt)); 244 245 dt = dt.withZone(PARIS); 246 assertEquals("2004-W24-3T12:20:30+02:00", ISODateTimeFormat.weekDateTimeNoMillis().print(dt)); 247 } 248 249 public void testFormat_basicDate() { 251 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 252 assertEquals("20040609", ISODateTimeFormat.basicDate().print(dt)); 253 254 dt = dt.withZone(LONDON); 255 assertEquals("20040609", ISODateTimeFormat.basicDate().print(dt)); 256 257 dt = dt.withZone(PARIS); 258 assertEquals("20040609", ISODateTimeFormat.basicDate().print(dt)); 259 } 260 261 public void testFormat_basicTime() { 262 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 263 assertEquals("102030.040Z", ISODateTimeFormat.basicTime().print(dt)); 264 265 dt = dt.withZone(LONDON); 266 assertEquals("112030.040+0100", ISODateTimeFormat.basicTime().print(dt)); 267 268 dt = dt.withZone(PARIS); 269 assertEquals("122030.040+0200", ISODateTimeFormat.basicTime().print(dt)); 270 } 271 272 public void testFormat_basicTimeNoMillis() { 273 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 274 assertEquals("102030Z", ISODateTimeFormat.basicTimeNoMillis().print(dt)); 275 276 dt = dt.withZone(LONDON); 277 assertEquals("112030+0100", ISODateTimeFormat.basicTimeNoMillis().print(dt)); 278 279 dt = dt.withZone(PARIS); 280 assertEquals("122030+0200", ISODateTimeFormat.basicTimeNoMillis().print(dt)); 281 } 282 283 public void testFormat_basicTTime() { 284 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 285 assertEquals("T102030.040Z", ISODateTimeFormat.basicTTime().print(dt)); 286 287 dt = dt.withZone(LONDON); 288 assertEquals("T112030.040+0100", ISODateTimeFormat.basicTTime().print(dt)); 289 290 dt = dt.withZone(PARIS); 291 assertEquals("T122030.040+0200", ISODateTimeFormat.basicTTime().print(dt)); 292 } 293 294 public void testFormat_basicTTimeNoMillis() { 295 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 296 assertEquals("T102030Z", ISODateTimeFormat.basicTTimeNoMillis().print(dt)); 297 298 dt = dt.withZone(LONDON); 299 assertEquals("T112030+0100", ISODateTimeFormat.basicTTimeNoMillis().print(dt)); 300 301 dt = dt.withZone(PARIS); 302 assertEquals("T122030+0200", ISODateTimeFormat.basicTTimeNoMillis().print(dt)); 303 } 304 305 public void testFormat_basicDateTime() { 306 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 307 assertEquals("20040609T102030.040Z", ISODateTimeFormat.basicDateTime().print(dt)); 308 309 dt = dt.withZone(LONDON); 310 assertEquals("20040609T112030.040+0100", ISODateTimeFormat.basicDateTime().print(dt)); 311 312 dt = dt.withZone(PARIS); 313 assertEquals("20040609T122030.040+0200", ISODateTimeFormat.basicDateTime().print(dt)); 314 } 315 316 public void testFormat_basicDateTimeNoMillis() { 317 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 318 assertEquals("20040609T102030Z", ISODateTimeFormat.basicDateTimeNoMillis().print(dt)); 319 320 dt = dt.withZone(LONDON); 321 assertEquals("20040609T112030+0100", ISODateTimeFormat.basicDateTimeNoMillis().print(dt)); 322 323 dt = dt.withZone(PARIS); 324 assertEquals("20040609T122030+0200", ISODateTimeFormat.basicDateTimeNoMillis().print(dt)); 325 } 326 327 public void testFormat_basicOrdinalDate() { 328 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 329 assertEquals("2004161", ISODateTimeFormat.basicOrdinalDate().print(dt)); 330 331 dt = dt.withZone(LONDON); 332 assertEquals("2004161", ISODateTimeFormat.basicOrdinalDate().print(dt)); 333 334 dt = dt.withZone(PARIS); 335 assertEquals("2004161", ISODateTimeFormat.basicOrdinalDate().print(dt)); 336 } 337 338 public void testFormat_basicOrdinalDateTime() { 339 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 340 assertEquals("2004161T102030.040Z", ISODateTimeFormat.basicOrdinalDateTime().print(dt)); 341 342 dt = dt.withZone(LONDON); 343 assertEquals("2004161T112030.040+0100", ISODateTimeFormat.basicOrdinalDateTime().print(dt)); 344 345 dt = dt.withZone(PARIS); 346 assertEquals("2004161T122030.040+0200", ISODateTimeFormat.basicOrdinalDateTime().print(dt)); 347 } 348 349 public void testFormat_basicOrdinalDateTimeNoMillis() { 350 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 351 assertEquals("2004161T102030Z", ISODateTimeFormat.basicOrdinalDateTimeNoMillis().print(dt)); 352 353 dt = dt.withZone(LONDON); 354 assertEquals("2004161T112030+0100", ISODateTimeFormat.basicOrdinalDateTimeNoMillis().print(dt)); 355 356 dt = dt.withZone(PARIS); 357 assertEquals("2004161T122030+0200", ISODateTimeFormat.basicOrdinalDateTimeNoMillis().print(dt)); 358 } 359 360 public void testFormat_basicWeekDate() { 361 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 362 assertEquals("2004W243", ISODateTimeFormat.basicWeekDate().print(dt)); 363 364 dt = dt.withZone(LONDON); 365 assertEquals("2004W243", ISODateTimeFormat.basicWeekDate().print(dt)); 366 367 dt = dt.withZone(PARIS); 368 assertEquals("2004W243", ISODateTimeFormat.basicWeekDate().print(dt)); 369 } 370 371 public void testFormat_basicWeekDateTime() { 372 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 373 assertEquals("2004W243T102030.040Z", ISODateTimeFormat.basicWeekDateTime().print(dt)); 374 375 dt = dt.withZone(LONDON); 376 assertEquals("2004W243T112030.040+0100", ISODateTimeFormat.basicWeekDateTime().print(dt)); 377 378 dt = dt.withZone(PARIS); 379 assertEquals("2004W243T122030.040+0200", ISODateTimeFormat.basicWeekDateTime().print(dt)); 380 } 381 382 public void testFormat_basicWeekDateTimeNoMillis() { 383 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 384 assertEquals("2004W243T102030Z", ISODateTimeFormat.basicWeekDateTimeNoMillis().print(dt)); 385 386 dt = dt.withZone(LONDON); 387 assertEquals("2004W243T112030+0100", ISODateTimeFormat.basicWeekDateTimeNoMillis().print(dt)); 388 389 dt = dt.withZone(PARIS); 390 assertEquals("2004W243T122030+0200", ISODateTimeFormat.basicWeekDateTimeNoMillis().print(dt)); 391 } 392 393 public void testFormat_year() { 395 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 396 assertEquals("2004", ISODateTimeFormat.year().print(dt)); 397 398 dt = dt.withZone(LONDON); 399 assertEquals("2004", ISODateTimeFormat.year().print(dt)); 400 401 dt = dt.withZone(PARIS); 402 assertEquals("2004", ISODateTimeFormat.year().print(dt)); 403 } 404 405 public void testFormat_yearMonth() { 406 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 407 assertEquals("2004-06", ISODateTimeFormat.yearMonth().print(dt)); 408 409 dt = dt.withZone(LONDON); 410 assertEquals("2004-06", ISODateTimeFormat.yearMonth().print(dt)); 411 412 dt = dt.withZone(PARIS); 413 assertEquals("2004-06", ISODateTimeFormat.yearMonth().print(dt)); 414 } 415 416 public void testFormat_yearMonthDay() { 417 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 418 assertEquals("2004-06-09", ISODateTimeFormat.yearMonthDay().print(dt)); 419 420 dt = dt.withZone(LONDON); 421 assertEquals("2004-06-09", ISODateTimeFormat.yearMonthDay().print(dt)); 422 423 dt = dt.withZone(PARIS); 424 assertEquals("2004-06-09", ISODateTimeFormat.yearMonthDay().print(dt)); 425 } 426 427 public void testFormat_weekyear() { 428 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 429 assertEquals("2004", ISODateTimeFormat.weekyear().print(dt)); 430 431 dt = dt.withZone(LONDON); 432 assertEquals("2004", ISODateTimeFormat.weekyear().print(dt)); 433 434 dt = dt.withZone(PARIS); 435 assertEquals("2004", ISODateTimeFormat.weekyear().print(dt)); 436 } 437 438 public void testFormat_weekyearWeek() { 439 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 440 assertEquals("2004-W24", ISODateTimeFormat.weekyearWeek().print(dt)); 441 442 dt = dt.withZone(LONDON); 443 assertEquals("2004-W24", ISODateTimeFormat.weekyearWeek().print(dt)); 444 445 dt = dt.withZone(PARIS); 446 assertEquals("2004-W24", ISODateTimeFormat.weekyearWeek().print(dt)); 447 } 448 449 public void testFormat_weekyearWeekDay() { 450 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 451 assertEquals("2004-W24-3", ISODateTimeFormat.weekyearWeekDay().print(dt)); 452 453 dt = dt.withZone(LONDON); 454 assertEquals("2004-W24-3", ISODateTimeFormat.weekyearWeekDay().print(dt)); 455 456 dt = dt.withZone(PARIS); 457 assertEquals("2004-W24-3", ISODateTimeFormat.weekyearWeekDay().print(dt)); 458 } 459 460 public void testFormat_hour() { 462 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 463 assertEquals("10", ISODateTimeFormat.hour().print(dt)); 464 465 dt = dt.withZone(LONDON); 466 assertEquals("11", ISODateTimeFormat.hour().print(dt)); 467 468 dt = dt.withZone(PARIS); 469 assertEquals("12", ISODateTimeFormat.hour().print(dt)); 470 } 471 472 public void testFormat_hourMinute() { 473 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 474 assertEquals("10:20", ISODateTimeFormat.hourMinute().print(dt)); 475 476 dt = dt.withZone(LONDON); 477 assertEquals("11:20", ISODateTimeFormat.hourMinute().print(dt)); 478 479 dt = dt.withZone(PARIS); 480 assertEquals("12:20", ISODateTimeFormat.hourMinute().print(dt)); 481 } 482 483 public void testFormat_hourMinuteSecond() { 484 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 485 assertEquals("10:20:30", ISODateTimeFormat.hourMinuteSecond().print(dt)); 486 487 dt = dt.withZone(LONDON); 488 assertEquals("11:20:30", ISODateTimeFormat.hourMinuteSecond().print(dt)); 489 490 dt = dt.withZone(PARIS); 491 assertEquals("12:20:30", ISODateTimeFormat.hourMinuteSecond().print(dt)); 492 } 493 494 public void testFormat_hourMinuteSecondMillis() { 495 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 496 assertEquals("10:20:30.040", ISODateTimeFormat.hourMinuteSecondMillis().print(dt)); 497 498 dt = dt.withZone(LONDON); 499 assertEquals("11:20:30.040", ISODateTimeFormat.hourMinuteSecondMillis().print(dt)); 500 501 dt = dt.withZone(PARIS); 502 assertEquals("12:20:30.040", ISODateTimeFormat.hourMinuteSecondMillis().print(dt)); 503 } 504 505 public void testFormat_hourMinuteSecondFraction() { 506 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 507 assertEquals("10:20:30.040", ISODateTimeFormat.hourMinuteSecondFraction().print(dt)); 508 509 dt = dt.withZone(LONDON); 510 assertEquals("11:20:30.040", ISODateTimeFormat.hourMinuteSecondFraction().print(dt)); 511 512 dt = dt.withZone(PARIS); 513 assertEquals("12:20:30.040", ISODateTimeFormat.hourMinuteSecondFraction().print(dt)); 514 } 515 516 public void testFormat_dateHour() { 518 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 519 assertEquals("2004-06-09T10", ISODateTimeFormat.dateHour().print(dt)); 520 521 dt = dt.withZone(LONDON); 522 assertEquals("2004-06-09T11", ISODateTimeFormat.dateHour().print(dt)); 523 524 dt = dt.withZone(PARIS); 525 assertEquals("2004-06-09T12", ISODateTimeFormat.dateHour().print(dt)); 526 } 527 528 public void testFormat_dateHourMinute() { 529 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 530 assertEquals("2004-06-09T10:20", ISODateTimeFormat.dateHourMinute().print(dt)); 531 532 dt = dt.withZone(LONDON); 533 assertEquals("2004-06-09T11:20", ISODateTimeFormat.dateHourMinute().print(dt)); 534 535 dt = dt.withZone(PARIS); 536 assertEquals("2004-06-09T12:20", ISODateTimeFormat.dateHourMinute().print(dt)); 537 } 538 539 public void testFormat_dateHourMinuteSecond() { 540 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 541 assertEquals("2004-06-09T10:20:30", ISODateTimeFormat.dateHourMinuteSecond().print(dt)); 542 543 dt = dt.withZone(LONDON); 544 assertEquals("2004-06-09T11:20:30", ISODateTimeFormat.dateHourMinuteSecond().print(dt)); 545 546 dt = dt.withZone(PARIS); 547 assertEquals("2004-06-09T12:20:30", ISODateTimeFormat.dateHourMinuteSecond().print(dt)); 548 } 549 550 public void testFormat_dateHourMinuteSecondMillis() { 551 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 552 assertEquals("2004-06-09T10:20:30.040", ISODateTimeFormat.dateHourMinuteSecondMillis().print(dt)); 553 554 dt = dt.withZone(LONDON); 555 assertEquals("2004-06-09T11:20:30.040", ISODateTimeFormat.dateHourMinuteSecondMillis().print(dt)); 556 557 dt = dt.withZone(PARIS); 558 assertEquals("2004-06-09T12:20:30.040", ISODateTimeFormat.dateHourMinuteSecondMillis().print(dt)); 559 } 560 561 public void testFormat_dateHourMinuteSecondFraction() { 562 DateTime dt = new DateTime(2004, 6, 9, 10, 20, 30, 40, UTC); 563 assertEquals("2004-06-09T10:20:30.040", ISODateTimeFormat.dateHourMinuteSecondFraction().print(dt)); 564 565 dt = dt.withZone(LONDON); 566 assertEquals("2004-06-09T11:20:30.040", ISODateTimeFormat.dateHourMinuteSecondFraction().print(dt)); 567 568 dt = dt.withZone(PARIS); 569 assertEquals("2004-06-09T12:20:30.040", ISODateTimeFormat.dateHourMinuteSecondFraction().print(dt)); 570 } 571 572 } 573 | Popular Tags |