1 16 package org.joda.time; 17 18 import java.util.Locale ; 19 20 import junit.framework.TestCase; 21 import junit.framework.TestSuite; 22 23 import org.joda.time.chrono.CopticChronology; 24 import org.joda.time.chrono.LenientChronology; 25 import org.joda.time.chrono.StrictChronology; 26 27 33 public class TestDateTime_Properties extends TestCase { 34 37 private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris"); 38 private static final Chronology COPTIC_PARIS = CopticChronology.getInstance(PARIS); 39 40 private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London"); 42 43 long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 44 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 45 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 46 366 + 365; 47 long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 48 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 49 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 50 366 + 365 + 365; 51 52 private long TEST_TIME_NOW = 54 (y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY; 55 56 private long TEST_TIME1 = 58 (y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY 59 + 12L * DateTimeConstants.MILLIS_PER_HOUR 60 + 24L * DateTimeConstants.MILLIS_PER_MINUTE; 61 62 private long TEST_TIME2 = 64 (y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY 65 + 14L * DateTimeConstants.MILLIS_PER_HOUR 66 + 28L * DateTimeConstants.MILLIS_PER_MINUTE; 67 68 private DateTimeZone zone = null; 69 private Locale locale = null; 70 71 public static void main(String [] args) { 72 junit.textui.TestRunner.run(suite()); 73 } 74 75 public static TestSuite suite() { 76 return new TestSuite(TestDateTime_Properties.class); 77 } 78 79 public TestDateTime_Properties(String name) { 80 super(name); 81 } 82 83 protected void setUp() throws Exception { 84 DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW); 85 zone = DateTimeZone.getDefault(); 86 locale = Locale.getDefault(); 87 DateTimeZone.setDefault(LONDON); 88 Locale.setDefault(Locale.UK); 89 } 90 91 protected void tearDown() throws Exception { 92 DateTimeUtils.setCurrentMillisSystem(); 93 DateTimeZone.setDefault(zone); 94 Locale.setDefault(locale); 95 zone = null; 96 } 97 98 public void testTest() { 100 assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW).toString()); 101 assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1).toString()); 102 assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2).toString()); 103 } 104 105 public void testPropertyGetEra() { 107 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 108 assertSame(test.getChronology().era(), test.era().getField()); 109 assertEquals("era", test.era().getName()); 110 assertEquals("Property[era]", test.era().toString()); 111 assertSame(test, test.era().getDateTime()); 112 assertEquals(1, test.era().get()); 113 assertEquals("1", test.era().getAsString()); 114 assertEquals("AD", test.era().getAsText()); 115 assertEquals("AD", test.era().getField().getAsText(1, Locale.ENGLISH)); 116 assertEquals("ap. J.-C.", test.era().getAsText(Locale.FRENCH)); 117 assertEquals("ap. J.-C.", test.era().getField().getAsText(1, Locale.FRENCH)); 118 assertEquals("AD", test.era().getAsShortText()); 119 assertEquals("AD", test.era().getField().getAsShortText(1, Locale.ENGLISH)); 120 assertEquals("ap. J.-C.", test.era().getAsShortText(Locale.FRENCH)); 121 assertEquals("ap. J.-C.", test.era().getField().getAsShortText(1, Locale.FRENCH)); 122 assertEquals(test.getChronology().eras(), test.era().getDurationField()); 123 assertEquals(null, test.era().getRangeDurationField()); 124 assertEquals(2, test.era().getMaximumTextLength(null)); 125 assertEquals(9, test.era().getMaximumTextLength(Locale.FRENCH)); 126 assertEquals(2, test.era().getMaximumShortTextLength(null)); 127 assertEquals(9, test.era().getMaximumShortTextLength(Locale.FRENCH)); 128 } 129 130 public void testPropertyGetYearOfEra() { 132 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 133 assertSame(test.getChronology().yearOfEra(), test.yearOfEra().getField()); 134 assertEquals("yearOfEra", test.yearOfEra().getName()); 135 assertEquals("Property[yearOfEra]", test.yearOfEra().toString()); 136 assertSame(test, test.yearOfEra().getDateTime()); 137 assertEquals(2004, test.yearOfEra().get()); 138 assertEquals("2004", test.yearOfEra().getAsString()); 139 assertEquals("2004", test.yearOfEra().getAsText()); 140 assertEquals("2004", test.yearOfEra().getAsText(Locale.FRENCH)); 141 assertEquals("2004", test.yearOfEra().getAsShortText()); 142 assertEquals("2004", test.yearOfEra().getAsShortText(Locale.FRENCH)); 143 assertEquals(test.getChronology().years(), test.yearOfEra().getDurationField()); 144 assertEquals(null, test.yearOfEra().getRangeDurationField()); 145 assertEquals(9, test.yearOfEra().getMaximumTextLength(null)); 146 assertEquals(9, test.yearOfEra().getMaximumShortTextLength(null)); 147 } 148 149 public void testPropertyGetCenturyOfEra() { 151 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 152 assertSame(test.getChronology().centuryOfEra(), test.centuryOfEra().getField()); 153 assertEquals("centuryOfEra", test.centuryOfEra().getName()); 154 assertEquals("Property[centuryOfEra]", test.centuryOfEra().toString()); 155 assertSame(test, test.centuryOfEra().getDateTime()); 156 assertEquals(20, test.centuryOfEra().get()); 157 assertEquals("20", test.centuryOfEra().getAsString()); 158 assertEquals("20", test.centuryOfEra().getAsText()); 159 assertEquals("20", test.centuryOfEra().getAsText(Locale.FRENCH)); 160 assertEquals("20", test.centuryOfEra().getAsShortText()); 161 assertEquals("20", test.centuryOfEra().getAsShortText(Locale.FRENCH)); 162 assertEquals(test.getChronology().centuries(), test.centuryOfEra().getDurationField()); 163 assertEquals(null, test.centuryOfEra().getRangeDurationField()); 164 assertEquals(7, test.centuryOfEra().getMaximumTextLength(null)); 165 assertEquals(7, test.centuryOfEra().getMaximumShortTextLength(null)); 166 } 167 168 public void testPropertyGetYearOfCentury() { 170 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 171 assertSame(test.getChronology().yearOfCentury(), test.yearOfCentury().getField()); 172 assertEquals("yearOfCentury", test.yearOfCentury().getName()); 173 assertEquals("Property[yearOfCentury]", test.yearOfCentury().toString()); 174 assertSame(test, test.yearOfCentury().getDateTime()); 175 assertEquals(4, test.yearOfCentury().get()); 176 assertEquals("4", test.yearOfCentury().getAsString()); 177 assertEquals("4", test.yearOfCentury().getAsText()); 178 assertEquals("4", test.yearOfCentury().getAsText(Locale.FRENCH)); 179 assertEquals("4", test.yearOfCentury().getAsShortText()); 180 assertEquals("4", test.yearOfCentury().getAsShortText(Locale.FRENCH)); 181 assertEquals(test.getChronology().years(), test.yearOfCentury().getDurationField()); 182 assertEquals(test.getChronology().centuries(), test.yearOfCentury().getRangeDurationField()); 183 assertEquals(2, test.yearOfCentury().getMaximumTextLength(null)); 184 assertEquals(2, test.yearOfCentury().getMaximumShortTextLength(null)); 185 } 186 187 public void testPropertyGetWeekyear() { 189 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 190 assertSame(test.getChronology().weekyear(), test.weekyear().getField()); 191 assertEquals("weekyear", test.weekyear().getName()); 192 assertEquals("Property[weekyear]", test.weekyear().toString()); 193 assertSame(test, test.weekyear().getDateTime()); 194 assertEquals(2004, test.weekyear().get()); 195 assertEquals("2004", test.weekyear().getAsString()); 196 assertEquals("2004", test.weekyear().getAsText()); 197 assertEquals("2004", test.weekyear().getAsText(Locale.FRENCH)); 198 assertEquals("2004", test.weekyear().getAsShortText()); 199 assertEquals("2004", test.weekyear().getAsShortText(Locale.FRENCH)); 200 assertEquals(test.getChronology().weekyears(), test.weekyear().getDurationField()); 201 assertEquals(null, test.weekyear().getRangeDurationField()); 202 assertEquals(9, test.weekyear().getMaximumTextLength(null)); 203 assertEquals(9, test.weekyear().getMaximumShortTextLength(null)); 204 } 205 206 public void testPropertyGetYear() { 208 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 209 assertSame(test.getChronology().year(), test.year().getField()); 210 assertEquals("year", test.year().getName()); 211 assertEquals("Property[year]", test.year().toString()); 212 assertSame(test, test.year().getDateTime()); 213 assertEquals(2004, test.year().get()); 214 assertEquals("2004", test.year().getAsString()); 215 assertEquals("2004", test.year().getAsText()); 216 assertEquals("2004", test.year().getAsText(Locale.FRENCH)); 217 assertEquals("2004", test.year().getAsShortText()); 218 assertEquals("2004", test.year().getAsShortText(Locale.FRENCH)); 219 assertEquals(test.getChronology().years(), test.year().getDurationField()); 220 assertEquals(null, test.year().getRangeDurationField()); 221 assertEquals(9, test.year().getMaximumTextLength(null)); 222 assertEquals(9, test.year().getMaximumShortTextLength(null)); 223 assertEquals(-292275054, test.year().getMinimumValue()); 224 assertEquals(-292275054, test.year().getMinimumValueOverall()); 225 assertEquals(292278993, test.year().getMaximumValue()); 226 assertEquals(292278993, test.year().getMaximumValueOverall()); 227 } 228 229 public void testPropertyLeapYear() { 230 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 231 assertEquals(true, test.year().isLeap()); 232 assertEquals(1, test.year().getLeapAmount()); 233 assertEquals(test.getChronology().days(), test.year().getLeapDurationField()); 234 test = new DateTime(2003, 6, 9, 0, 0, 0, 0); 235 assertEquals(false, test.year().isLeap()); 236 assertEquals(0, test.year().getLeapAmount()); 237 assertEquals(test.getChronology().days(), test.year().getLeapDurationField()); 238 } 239 240 public void testPropertyAddYear() { 241 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 242 DateTime copy = test.year().addToCopy(9); 243 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 244 assertEquals("2013-06-09T00:00:00.000+01:00", copy.toString()); 245 246 copy = test.year().addToCopy(0); 247 assertEquals("2004-06-09T00:00:00.000+01:00", copy.toString()); 248 249 copy = test.year().addToCopy(292277023 - 2004); 250 assertEquals(292277023, copy.getYear()); 251 252 try { 253 test.year().addToCopy(292278993 - 2004 + 1); 254 fail(); 255 } catch (IllegalArgumentException ex) {} 256 257 copy = test.year().addToCopy(-2004); 258 assertEquals(0, copy.getYear()); 259 260 copy = test.year().addToCopy(-2005); 261 assertEquals(-1, copy.getYear()); 262 263 try { 264 test.year().addToCopy(-292275054 - 2004 - 1); 265 fail(); 266 } catch (IllegalArgumentException ex) {} 267 } 268 269 public void testPropertyAddWrapFieldYear() { 270 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 271 DateTime copy = test.year().addWrapFieldToCopy(9); 272 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 273 assertEquals("2013-06-09T00:00:00.000+01:00", copy.toString()); 274 275 copy = test.year().addWrapFieldToCopy(0); 276 assertEquals(2004, copy.getYear()); 277 278 copy = test.year().addWrapFieldToCopy(292278993 - 2004 + 1); 279 assertEquals(-292275054, copy.getYear()); 280 281 copy = test.year().addWrapFieldToCopy(-292275054 - 2004 - 1); 282 assertEquals(292278993, copy.getYear()); 283 } 284 285 public void testPropertySetYear() { 286 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 287 DateTime copy = test.year().setCopy(1960); 288 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 289 assertEquals("1960-06-09T00:00:00.000+01:00", copy.toString()); 290 } 291 292 public void testPropertySetTextYear() { 293 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 294 DateTime copy = test.year().setCopy("1960"); 295 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 296 assertEquals("1960-06-09T00:00:00.000+01:00", copy.toString()); 297 } 298 299 public void testPropertyCompareToYear() { 300 DateTime test1 = new DateTime(TEST_TIME1); 301 DateTime test2 = new DateTime(TEST_TIME2); 302 assertEquals(true, test1.year().compareTo(test2) < 0); 303 assertEquals(true, test2.year().compareTo(test1) > 0); 304 assertEquals(true, test1.year().compareTo(test1) == 0); 305 try { 306 test1.year().compareTo((ReadableInstant) null); 307 fail(); 308 } catch (IllegalArgumentException ex) {} 309 } 310 311 public void testPropertyCompareToYear2() { 312 DateTime test1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); 313 YearMonthDay ymd1 = new YearMonthDay(2003, 6, 9); 314 YearMonthDay ymd2 = new YearMonthDay(2004, 6, 9); 315 YearMonthDay ymd3 = new YearMonthDay(2005, 6, 9); 316 assertEquals(true, test1.year().compareTo(ymd1) > 0); 317 assertEquals(true, test1.year().compareTo(ymd2) == 0); 318 assertEquals(true, test1.year().compareTo(ymd3) < 0); 319 try { 320 test1.year().compareTo((ReadablePartial) null); 321 fail(); 322 } catch (IllegalArgumentException ex) {} 323 } 324 325 public void testPropertyEqualsHashCodeYear() { 326 DateTime test1 = new DateTime(2004, 6, 9, 0, 0, 0, 0); 327 assertEquals(true, test1.year().equals(test1.year())); 328 assertEquals(true, test1.year().equals(new DateTime(2004, 6, 9, 0, 0, 0, 0).year())); 329 assertEquals(false, test1.year().equals(new DateTime(2004, 6, 9, 0, 0, 0, 0).monthOfYear())); 330 assertEquals(false, test1.year().equals(new DateTime(2004, 6, 9, 0, 0, 0, 0, CopticChronology.getInstance()).year())); 331 332 assertEquals(true, test1.year().hashCode() == test1.year().hashCode()); 333 assertEquals(true, test1.year().hashCode() == new DateTime(2004, 6, 9, 0, 0, 0, 0).year().hashCode()); 334 assertEquals(false, test1.year().hashCode() == new DateTime(2004, 6, 9, 0, 0, 0, 0).monthOfYear().hashCode()); 335 assertEquals(false, test1.year().hashCode() == new DateTime(2004, 6, 9, 0, 0, 0, 0, CopticChronology.getInstance()).year().hashCode()); 336 } 337 338 public void testPropertyGetMonthOfYear() { 340 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 341 assertSame(test.getChronology().monthOfYear(), test.monthOfYear().getField()); 342 assertEquals("monthOfYear", test.monthOfYear().getName()); 343 assertEquals("Property[monthOfYear]", test.monthOfYear().toString()); 344 assertSame(test, test.monthOfYear().getDateTime()); 345 assertEquals(6, test.monthOfYear().get()); 346 assertEquals("6", test.monthOfYear().getAsString()); 347 assertEquals("June", test.monthOfYear().getAsText()); 348 assertEquals("June", test.monthOfYear().getField().getAsText(6, Locale.ENGLISH)); 349 assertEquals("juin", test.monthOfYear().getAsText(Locale.FRENCH)); 350 assertEquals("juin", test.monthOfYear().getField().getAsText(6, Locale.FRENCH)); 351 assertEquals("Jun", test.monthOfYear().getAsShortText()); 352 assertEquals("Jun", test.monthOfYear().getField().getAsShortText(6, Locale.ENGLISH)); 353 assertEquals("juin", test.monthOfYear().getAsShortText(Locale.FRENCH)); 354 assertEquals("juin", test.monthOfYear().getField().getAsShortText(6, Locale.FRENCH)); 355 assertEquals(test.getChronology().months(), test.monthOfYear().getDurationField()); 356 assertEquals(test.getChronology().years(), test.monthOfYear().getRangeDurationField()); 357 assertEquals(9, test.monthOfYear().getMaximumTextLength(null)); 358 assertEquals(3, test.monthOfYear().getMaximumShortTextLength(null)); 359 test = new DateTime(2004, 7, 9, 0, 0, 0, 0); 360 assertEquals("juillet", test.monthOfYear().getAsText(Locale.FRENCH)); 361 assertEquals("juillet", test.monthOfYear().getField().getAsText(7, Locale.FRENCH)); 362 assertEquals("juil.", test.monthOfYear().getAsShortText(Locale.FRENCH)); 363 assertEquals("juil.", test.monthOfYear().getField().getAsShortText(7, Locale.FRENCH)); 364 assertEquals(1, test.monthOfYear().getMinimumValue()); 365 assertEquals(1, test.monthOfYear().getMinimumValueOverall()); 366 assertEquals(12, test.monthOfYear().getMaximumValue()); 367 assertEquals(12, test.monthOfYear().getMaximumValueOverall()); 368 assertEquals(1, test.monthOfYear().getMinimumValue()); 369 assertEquals(1, test.monthOfYear().getMinimumValueOverall()); 370 assertEquals(12, test.monthOfYear().getMaximumValue()); 371 assertEquals(12, test.monthOfYear().getMaximumValueOverall()); 372 } 373 374 public void testPropertyLeapMonthOfYear() { 375 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 376 assertEquals(false, test.monthOfYear().isLeap()); 377 assertEquals(0, test.monthOfYear().getLeapAmount()); 378 assertEquals(test.getChronology().days(), test.monthOfYear().getLeapDurationField()); 379 380 test = new DateTime(2004, 2, 9, 0, 0, 0, 0); 381 assertEquals(true, test.monthOfYear().isLeap()); 382 assertEquals(1, test.monthOfYear().getLeapAmount()); 383 assertEquals(test.getChronology().days(), test.monthOfYear().getLeapDurationField()); 384 385 test = new DateTime(2003, 6, 9, 0, 0, 0, 0); 386 assertEquals(false, test.monthOfYear().isLeap()); 387 assertEquals(0, test.monthOfYear().getLeapAmount()); 388 assertEquals(test.getChronology().days(), test.monthOfYear().getLeapDurationField()); 389 390 test = new DateTime(2003, 2, 9, 0, 0, 0, 0); 391 assertEquals(false, test.monthOfYear().isLeap()); 392 assertEquals(0, test.monthOfYear().getLeapAmount()); 393 assertEquals(test.getChronology().days(), test.monthOfYear().getLeapDurationField()); 394 } 395 396 public void testPropertyAddMonthOfYear() { 397 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 398 DateTime copy = test.monthOfYear().addToCopy(6); 399 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 400 assertEquals("2004-12-09T00:00:00.000Z", copy.toString()); 401 402 copy = test.monthOfYear().addToCopy(7); 403 assertEquals("2005-01-09T00:00:00.000Z", copy.toString()); 404 405 copy = test.monthOfYear().addToCopy(-5); 406 assertEquals("2004-01-09T00:00:00.000Z", copy.toString()); 407 408 copy = test.monthOfYear().addToCopy(-6); 409 assertEquals("2003-12-09T00:00:00.000Z", copy.toString()); 410 411 test = new DateTime(2004, 1, 31, 0, 0, 0, 0); 412 copy = test.monthOfYear().addToCopy(1); 413 assertEquals("2004-01-31T00:00:00.000Z", test.toString()); 414 assertEquals("2004-02-29T00:00:00.000Z", copy.toString()); 415 416 copy = test.monthOfYear().addToCopy(2); 417 assertEquals("2004-03-31T00:00:00.000+01:00", copy.toString()); 418 419 copy = test.monthOfYear().addToCopy(3); 420 assertEquals("2004-04-30T00:00:00.000+01:00", copy.toString()); 421 422 test = new DateTime(2003, 1, 31, 0, 0, 0, 0); 423 copy = test.monthOfYear().addToCopy(1); 424 assertEquals("2003-02-28T00:00:00.000Z", copy.toString()); 425 } 426 427 public void testPropertyAddWrapFieldMonthOfYear() { 428 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 429 DateTime copy = test.monthOfYear().addWrapFieldToCopy(4); 430 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 431 assertEquals("2004-10-09T00:00:00.000+01:00", copy.toString()); 432 433 copy = test.monthOfYear().addWrapFieldToCopy(8); 434 assertEquals("2004-02-09T00:00:00.000Z", copy.toString()); 435 436 copy = test.monthOfYear().addWrapFieldToCopy(-8); 437 assertEquals("2004-10-09T00:00:00.000+01:00", copy.toString()); 438 439 test = new DateTime(2004, 1, 31, 0, 0, 0, 0); 440 copy = test.monthOfYear().addWrapFieldToCopy(1); 441 assertEquals("2004-01-31T00:00:00.000Z", test.toString()); 442 assertEquals("2004-02-29T00:00:00.000Z", copy.toString()); 443 444 copy = test.monthOfYear().addWrapFieldToCopy(2); 445 assertEquals("2004-03-31T00:00:00.000+01:00", copy.toString()); 446 447 copy = test.monthOfYear().addWrapFieldToCopy(3); 448 assertEquals("2004-04-30T00:00:00.000+01:00", copy.toString()); 449 450 test = new DateTime(2005, 1, 31, 0, 0, 0, 0); 451 copy = test.monthOfYear().addWrapFieldToCopy(1); 452 assertEquals("2005-01-31T00:00:00.000Z", test.toString()); 453 assertEquals("2005-02-28T00:00:00.000Z", copy.toString()); 454 } 455 456 public void testPropertySetMonthOfYear() { 457 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 458 DateTime copy = test.monthOfYear().setCopy(12); 459 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 460 assertEquals("2004-12-09T00:00:00.000Z", copy.toString()); 461 462 test = new DateTime(2004, 1, 31, 0, 0, 0, 0); 463 copy = test.monthOfYear().setCopy(2); 464 assertEquals("2004-02-29T00:00:00.000Z", copy.toString()); 465 466 try { 467 test.monthOfYear().setCopy(13); 468 fail(); 469 } catch (IllegalArgumentException ex) {} 470 try { 471 test.monthOfYear().setCopy(0); 472 fail(); 473 } catch (IllegalArgumentException ex) {} 474 } 475 476 public void testPropertySetTextMonthOfYear() { 477 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 478 DateTime copy = test.monthOfYear().setCopy("12"); 479 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 480 assertEquals("2004-12-09T00:00:00.000Z", copy.toString()); 481 482 copy = test.monthOfYear().setCopy("December"); 483 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 484 assertEquals("2004-12-09T00:00:00.000Z", copy.toString()); 485 486 copy = test.monthOfYear().setCopy("Dec"); 487 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 488 assertEquals("2004-12-09T00:00:00.000Z", copy.toString()); 489 } 490 491 public void testPropertyCompareToMonthOfYear() { 492 DateTime test1 = new DateTime(TEST_TIME1); 493 DateTime test2 = new DateTime(TEST_TIME2); 494 assertEquals(true, test1.monthOfYear().compareTo(test2) < 0); 495 assertEquals(true, test2.monthOfYear().compareTo(test1) > 0); 496 assertEquals(true, test1.monthOfYear().compareTo(test1) == 0); 497 try { 498 test1.monthOfYear().compareTo((ReadableInstant) null); 499 fail(); 500 } catch (IllegalArgumentException ex) {} 501 502 DateTime dt1 = new DateTime(TEST_TIME1); 503 DateTime dt2 = new DateTime(TEST_TIME2); 504 assertEquals(true, test1.monthOfYear().compareTo(dt2) < 0); 505 assertEquals(true, test2.monthOfYear().compareTo(dt1) > 0); 506 assertEquals(true, test1.monthOfYear().compareTo(dt1) == 0); 507 try { 508 test1.monthOfYear().compareTo((ReadableInstant) null); 509 fail(); 510 } catch (IllegalArgumentException ex) {} 511 } 512 513 public void testPropertyGetDayOfMonth() { 515 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 516 assertSame(test.getChronology().dayOfMonth(), test.dayOfMonth().getField()); 517 assertEquals("dayOfMonth", test.dayOfMonth().getName()); 518 assertEquals("Property[dayOfMonth]", test.dayOfMonth().toString()); 519 assertSame(test, test.dayOfMonth().getDateTime()); 520 assertEquals(9, test.dayOfMonth().get()); 521 assertEquals("9", test.dayOfMonth().getAsString()); 522 assertEquals("9", test.dayOfMonth().getAsText()); 523 assertEquals("9", test.dayOfMonth().getAsText(Locale.FRENCH)); 524 assertEquals("9", test.dayOfMonth().getAsShortText()); 525 assertEquals("9", test.dayOfMonth().getAsShortText(Locale.FRENCH)); 526 assertEquals(test.getChronology().days(), test.dayOfMonth().getDurationField()); 527 assertEquals(test.getChronology().months(), test.dayOfMonth().getRangeDurationField()); 528 assertEquals(2, test.dayOfMonth().getMaximumTextLength(null)); 529 assertEquals(2, test.dayOfMonth().getMaximumShortTextLength(null)); 530 assertEquals(1, test.dayOfMonth().getMinimumValue()); 531 assertEquals(1, test.dayOfMonth().getMinimumValueOverall()); 532 assertEquals(30, test.dayOfMonth().getMaximumValue()); 533 assertEquals(31, test.dayOfMonth().getMaximumValueOverall()); 534 assertEquals(false, test.dayOfMonth().isLeap()); 535 assertEquals(0, test.dayOfMonth().getLeapAmount()); 536 assertEquals(null, test.dayOfMonth().getLeapDurationField()); 537 } 538 539 public void testPropertyGetMaxMinValuesDayOfMonth() { 540 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 541 assertEquals(1, test.dayOfMonth().getMinimumValue()); 542 assertEquals(1, test.dayOfMonth().getMinimumValueOverall()); 543 assertEquals(30, test.dayOfMonth().getMaximumValue()); 544 assertEquals(31, test.dayOfMonth().getMaximumValueOverall()); 545 test = new DateTime(2004, 7, 9, 0, 0, 0, 0); 546 assertEquals(31, test.dayOfMonth().getMaximumValue()); 547 test = new DateTime(2004, 2, 9, 0, 0, 0, 0); 548 assertEquals(29, test.dayOfMonth().getMaximumValue()); 549 test = new DateTime(2003, 2, 9, 0, 0, 0, 0); 550 assertEquals(28, test.dayOfMonth().getMaximumValue()); 551 } 552 553 public void testPropertyAddDayOfMonth() { 554 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 555 DateTime copy = test.dayOfMonth().addToCopy(9); 556 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 557 assertEquals("2004-06-18T00:00:00.000+01:00", copy.toString()); 558 559 copy = test.dayOfMonth().addToCopy(21); 560 assertEquals("2004-06-30T00:00:00.000+01:00", copy.toString()); 561 562 copy = test.dayOfMonth().addToCopy(22); 563 assertEquals("2004-07-01T00:00:00.000+01:00", copy.toString()); 564 565 copy = test.dayOfMonth().addToCopy(22 + 30); 566 assertEquals("2004-07-31T00:00:00.000+01:00", copy.toString()); 567 568 copy = test.dayOfMonth().addToCopy(22 + 31); 569 assertEquals("2004-08-01T00:00:00.000+01:00", copy.toString()); 570 571 copy = test.dayOfMonth().addToCopy(21 + 31 + 31 + 30 + 31 + 30 + 31); 572 assertEquals("2004-12-31T00:00:00.000Z", copy.toString()); 573 574 copy = test.dayOfMonth().addToCopy(22 + 31 + 31 + 30 + 31 + 30 + 31); 575 assertEquals("2005-01-01T00:00:00.000Z", copy.toString()); 576 577 copy = test.dayOfMonth().addToCopy(-8); 578 assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString()); 579 580 copy = test.dayOfMonth().addToCopy(-9); 581 assertEquals("2004-05-31T00:00:00.000+01:00", copy.toString()); 582 583 copy = test.dayOfMonth().addToCopy(-8 - 31 - 30 - 31 - 29 - 31); 584 assertEquals("2004-01-01T00:00:00.000Z", copy.toString()); 585 586 copy = test.dayOfMonth().addToCopy(-9 - 31 - 30 - 31 - 29 - 31); 587 assertEquals("2003-12-31T00:00:00.000Z", copy.toString()); 588 } 589 590 public void testPropertyAddWrapFieldDayOfMonth() { 591 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 592 DateTime copy = test.dayOfMonth().addWrapFieldToCopy(21); 593 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 594 assertEquals("2004-06-30T00:00:00.000+01:00", copy.toString()); 595 596 copy = test.dayOfMonth().addWrapFieldToCopy(22); 597 assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString()); 598 599 copy = test.dayOfMonth().addWrapFieldToCopy(-12); 600 assertEquals("2004-06-27T00:00:00.000+01:00", copy.toString()); 601 602 test = new DateTime(2004, 7, 9, 0, 0, 0, 0); 603 copy = test.dayOfMonth().addWrapFieldToCopy(21); 604 assertEquals("2004-07-30T00:00:00.000+01:00", copy.toString()); 605 606 copy = test.dayOfMonth().addWrapFieldToCopy(22); 607 assertEquals("2004-07-31T00:00:00.000+01:00", copy.toString()); 608 609 copy = test.dayOfMonth().addWrapFieldToCopy(23); 610 assertEquals("2004-07-01T00:00:00.000+01:00", copy.toString()); 611 612 copy = test.dayOfMonth().addWrapFieldToCopy(-12); 613 assertEquals("2004-07-28T00:00:00.000+01:00", copy.toString()); 614 } 615 616 public void testPropertySetDayOfMonth() { 617 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 618 DateTime copy = test.dayOfMonth().setCopy(12); 619 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 620 assertEquals("2004-06-12T00:00:00.000+01:00", copy.toString()); 621 622 try { 623 test.dayOfMonth().setCopy(31); 624 fail(); 625 } catch (IllegalArgumentException ex) {} 626 try { 627 test.dayOfMonth().setCopy(0); 628 fail(); 629 } catch (IllegalArgumentException ex) {} 630 } 631 632 public void testPropertySetTextDayOfMonth() { 633 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 634 DateTime copy = test.dayOfMonth().setCopy("12"); 635 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 636 assertEquals("2004-06-12T00:00:00.000+01:00", copy.toString()); 637 } 638 639 public void testPropertyWithMaximumValueDayOfMonth() { 640 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 641 DateTime copy = test.dayOfMonth().withMaximumValue(); 642 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 643 assertEquals("2004-06-30T00:00:00.000+01:00", copy.toString()); 644 } 645 646 public void testPropertyWithMinimumValueDayOfMonth() { 647 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 648 DateTime copy = test.dayOfMonth().withMinimumValue(); 649 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 650 assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString()); 651 } 652 653 public void testPropertyCompareToDayOfMonth() { 654 DateTime test1 = new DateTime(TEST_TIME1); 655 DateTime test2 = new DateTime(TEST_TIME2); 656 assertEquals(true, test1.dayOfMonth().compareTo(test2) < 0); 657 assertEquals(true, test2.dayOfMonth().compareTo(test1) > 0); 658 assertEquals(true, test1.dayOfMonth().compareTo(test1) == 0); 659 try { 660 test1.dayOfMonth().compareTo((ReadableInstant) null); 661 fail(); 662 } catch (IllegalArgumentException ex) {} 663 664 DateTime dt1 = new DateTime(TEST_TIME1); 665 DateTime dt2 = new DateTime(TEST_TIME2); 666 assertEquals(true, test1.dayOfMonth().compareTo(dt2) < 0); 667 assertEquals(true, test2.dayOfMonth().compareTo(dt1) > 0); 668 assertEquals(true, test1.dayOfMonth().compareTo(dt1) == 0); 669 try { 670 test1.dayOfMonth().compareTo((ReadableInstant) null); 671 fail(); 672 } catch (IllegalArgumentException ex) {} 673 } 674 675 public void testPropertyGetDayOfYear() { 677 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 679 assertSame(test.getChronology().dayOfYear(), test.dayOfYear().getField()); 680 assertEquals("dayOfYear", test.dayOfYear().getName()); 681 assertEquals("Property[dayOfYear]", test.dayOfYear().toString()); 682 assertSame(test, test.dayOfYear().getDateTime()); 683 assertEquals(161, test.dayOfYear().get()); 684 assertEquals("161", test.dayOfYear().getAsString()); 685 assertEquals("161", test.dayOfYear().getAsText()); 686 assertEquals("161", test.dayOfYear().getAsText(Locale.FRENCH)); 687 assertEquals("161", test.dayOfYear().getAsShortText()); 688 assertEquals("161", test.dayOfYear().getAsShortText(Locale.FRENCH)); 689 assertEquals(test.getChronology().days(), test.dayOfYear().getDurationField()); 690 assertEquals(test.getChronology().years(), test.dayOfYear().getRangeDurationField()); 691 assertEquals(3, test.dayOfYear().getMaximumTextLength(null)); 692 assertEquals(3, test.dayOfYear().getMaximumShortTextLength(null)); 693 assertEquals(false, test.dayOfYear().isLeap()); 694 assertEquals(0, test.dayOfYear().getLeapAmount()); 695 assertEquals(null, test.dayOfYear().getLeapDurationField()); 696 } 697 698 public void testPropertyGetMaxMinValuesDayOfYear() { 699 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 700 assertEquals(1, test.dayOfYear().getMinimumValue()); 701 assertEquals(1, test.dayOfYear().getMinimumValueOverall()); 702 assertEquals(366, test.dayOfYear().getMaximumValue()); 703 assertEquals(366, test.dayOfYear().getMaximumValueOverall()); 704 test = new DateTime(2002, 6, 9, 0, 0, 0, 0); 705 assertEquals(365, test.dayOfYear().getMaximumValue()); 706 assertEquals(366, test.dayOfYear().getMaximumValueOverall()); 707 } 708 709 public void testPropertyAddDayOfYear() { 710 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 711 DateTime copy = test.dayOfYear().addToCopy(9); 712 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 713 assertEquals("2004-06-18T00:00:00.000+01:00", copy.toString()); 714 715 copy = test.dayOfYear().addToCopy(21); 716 assertEquals("2004-06-30T00:00:00.000+01:00", copy.toString()); 717 718 copy = test.dayOfYear().addToCopy(22); 719 assertEquals("2004-07-01T00:00:00.000+01:00", copy.toString()); 720 721 copy = test.dayOfYear().addToCopy(21 + 31 + 31 + 30 + 31 + 30 + 31); 722 assertEquals("2004-12-31T00:00:00.000Z", copy.toString()); 723 724 copy = test.dayOfYear().addToCopy(22 + 31 + 31 + 30 + 31 + 30 + 31); 725 assertEquals("2005-01-01T00:00:00.000Z", copy.toString()); 726 727 copy = test.dayOfYear().addToCopy(-8); 728 assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString()); 729 730 copy = test.dayOfYear().addToCopy(-9); 731 assertEquals("2004-05-31T00:00:00.000+01:00", copy.toString()); 732 733 copy = test.dayOfYear().addToCopy(-8 - 31 - 30 - 31 - 29 - 31); 734 assertEquals("2004-01-01T00:00:00.000Z", copy.toString()); 735 736 copy = test.dayOfYear().addToCopy(-9 - 31 - 30 - 31 - 29 - 31); 737 assertEquals("2003-12-31T00:00:00.000Z", copy.toString()); 738 } 739 740 public void testPropertyAddWrapFieldDayOfYear() { 741 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 742 DateTime copy = test.dayOfYear().addWrapFieldToCopy(21); 743 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 744 assertEquals("2004-06-30T00:00:00.000+01:00", copy.toString()); 745 746 copy = test.dayOfYear().addWrapFieldToCopy(22); 747 assertEquals("2004-07-01T00:00:00.000+01:00", copy.toString()); 748 749 copy = test.dayOfYear().addWrapFieldToCopy(-12); 750 assertEquals("2004-05-28T00:00:00.000+01:00", copy.toString()); 751 752 copy = test.dayOfYear().addWrapFieldToCopy(205); 753 assertEquals("2004-12-31T00:00:00.000Z", copy.toString()); 754 755 copy = test.dayOfYear().addWrapFieldToCopy(206); 756 assertEquals("2004-01-01T00:00:00.000Z", copy.toString()); 757 758 copy = test.dayOfYear().addWrapFieldToCopy(-160); 759 assertEquals("2004-01-01T00:00:00.000Z", copy.toString()); 760 761 copy = test.dayOfYear().addWrapFieldToCopy(-161); 762 assertEquals("2004-12-31T00:00:00.000Z", copy.toString()); 763 } 764 765 public void testPropertySetDayOfYear() { 766 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 767 DateTime copy = test.dayOfYear().setCopy(12); 768 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 769 assertEquals("2004-01-12T00:00:00.000Z", copy.toString()); 770 771 try { 772 test.dayOfYear().setCopy(367); 773 fail(); 774 } catch (IllegalArgumentException ex) {} 775 try { 776 test.dayOfYear().setCopy(0); 777 fail(); 778 } catch (IllegalArgumentException ex) {} 779 } 780 781 public void testPropertySetTextDayOfYear() { 782 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 783 DateTime copy = test.dayOfYear().setCopy("12"); 784 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 785 assertEquals("2004-01-12T00:00:00.000Z", copy.toString()); 786 } 787 788 public void testPropertyCompareToDayOfYear() { 789 DateTime test1 = new DateTime(TEST_TIME1); 790 DateTime test2 = new DateTime(TEST_TIME2); 791 assertEquals(true, test1.dayOfYear().compareTo(test2) < 0); 792 assertEquals(true, test2.dayOfYear().compareTo(test1) > 0); 793 assertEquals(true, test1.dayOfYear().compareTo(test1) == 0); 794 try { 795 test1.dayOfYear().compareTo((ReadableInstant) null); 796 fail(); 797 } catch (IllegalArgumentException ex) {} 798 799 DateTime dt1 = new DateTime(TEST_TIME1); 800 DateTime dt2 = new DateTime(TEST_TIME2); 801 assertEquals(true, test1.dayOfYear().compareTo(dt2) < 0); 802 assertEquals(true, test2.dayOfYear().compareTo(dt1) > 0); 803 assertEquals(true, test1.dayOfYear().compareTo(dt1) == 0); 804 try { 805 test1.dayOfYear().compareTo((ReadableInstant) null); 806 fail(); 807 } catch (IllegalArgumentException ex) {} 808 } 809 810 public void testPropertyGetWeekOfWeekyear() { 812 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 826 assertSame(test.getChronology().weekOfWeekyear(), test.weekOfWeekyear().getField()); 827 assertEquals("weekOfWeekyear", test.weekOfWeekyear().getName()); 828 assertEquals("Property[weekOfWeekyear]", test.weekOfWeekyear().toString()); 829 assertSame(test, test.weekOfWeekyear().getDateTime()); 830 assertEquals(24, test.weekOfWeekyear().get()); 831 assertEquals("24", test.weekOfWeekyear().getAsString()); 832 assertEquals("24", test.weekOfWeekyear().getAsText()); 833 assertEquals("24", test.weekOfWeekyear().getAsText(Locale.FRENCH)); 834 assertEquals("24", test.weekOfWeekyear().getAsShortText()); 835 assertEquals("24", test.weekOfWeekyear().getAsShortText(Locale.FRENCH)); 836 assertEquals(test.getChronology().weeks(), test.weekOfWeekyear().getDurationField()); 837 assertEquals(test.getChronology().weekyears(), test.weekOfWeekyear().getRangeDurationField()); 838 assertEquals(2, test.weekOfWeekyear().getMaximumTextLength(null)); 839 assertEquals(2, test.weekOfWeekyear().getMaximumShortTextLength(null)); 840 assertEquals(false, test.weekOfWeekyear().isLeap()); 841 assertEquals(0, test.weekOfWeekyear().getLeapAmount()); 842 assertEquals(null, test.weekOfWeekyear().getLeapDurationField()); 843 } 844 845 public void testPropertyGetMaxMinValuesWeekOfWeekyear() { 846 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 847 assertEquals(1, test.weekOfWeekyear().getMinimumValue()); 848 assertEquals(1, test.weekOfWeekyear().getMinimumValueOverall()); 849 assertEquals(53, test.weekOfWeekyear().getMaximumValue()); 850 assertEquals(53, test.weekOfWeekyear().getMaximumValueOverall()); 851 test = new DateTime(2005, 6, 9, 0, 0, 0, 0); 852 assertEquals(52, test.weekOfWeekyear().getMaximumValue()); 853 assertEquals(53, test.weekOfWeekyear().getMaximumValueOverall()); 854 } 855 856 public void testPropertyAddWeekOfWeekyear() { 857 DateTime test = new DateTime(2004, 6, 7, 0, 0, 0, 0); 858 DateTime copy = test.weekOfWeekyear().addToCopy(1); 859 assertEquals("2004-06-07T00:00:00.000+01:00", test.toString()); 860 assertEquals("2004-06-14T00:00:00.000+01:00", copy.toString()); 861 862 copy = test.weekOfWeekyear().addToCopy(29); 863 assertEquals("2004-12-27T00:00:00.000Z", copy.toString()); 864 865 copy = test.weekOfWeekyear().addToCopy(30); 866 assertEquals("2005-01-03T00:00:00.000Z", copy.toString()); 867 868 copy = test.weekOfWeekyear().addToCopy(-22); 869 assertEquals("2004-01-05T00:00:00.000Z", copy.toString()); 870 871 copy = test.weekOfWeekyear().addToCopy(-23); 872 assertEquals("2003-12-29T00:00:00.000Z", copy.toString()); 873 } 874 875 public void testPropertyAddWrapFieldWeekOfWeekyear() { 876 DateTime test = new DateTime(2004, 6, 7, 0, 0, 0, 0); 877 DateTime copy = test.weekOfWeekyear().addWrapFieldToCopy(1); 878 assertEquals("2004-06-07T00:00:00.000+01:00", test.toString()); 879 assertEquals("2004-06-14T00:00:00.000+01:00", copy.toString()); 880 881 copy = test.weekOfWeekyear().addWrapFieldToCopy(29); 882 assertEquals("2004-12-27T00:00:00.000Z", copy.toString()); 883 884 copy = test.weekOfWeekyear().addWrapFieldToCopy(30); 885 assertEquals("2003-12-29T00:00:00.000Z", copy.toString()); 886 887 copy = test.weekOfWeekyear().addWrapFieldToCopy(-23); 888 assertEquals("2003-12-29T00:00:00.000Z", copy.toString()); 889 } 890 891 public void testPropertySetWeekOfWeekyear() { 892 DateTime test = new DateTime(2004, 6, 7, 0, 0, 0, 0); 893 DateTime copy = test.weekOfWeekyear().setCopy(4); 894 assertEquals("2004-06-07T00:00:00.000+01:00", test.toString()); 895 assertEquals("2004-01-19T00:00:00.000Z", copy.toString()); 896 897 try { 898 test.weekOfWeekyear().setCopy(54); 899 fail(); 900 } catch (IllegalArgumentException ex) {} 901 try { 902 test.weekOfWeekyear().setCopy(0); 903 fail(); 904 } catch (IllegalArgumentException ex) {} 905 } 906 907 public void testPropertySetTextWeekOfWeekyear() { 908 DateTime test = new DateTime(2004, 6, 7, 0, 0, 0, 0); 909 DateTime copy = test.weekOfWeekyear().setCopy("4"); 910 assertEquals("2004-06-07T00:00:00.000+01:00", test.toString()); 911 assertEquals("2004-01-19T00:00:00.000Z", copy.toString()); 912 } 913 914 public void testPropertyCompareToWeekOfWeekyear() { 915 DateTime test1 = new DateTime(TEST_TIME1); 916 DateTime test2 = new DateTime(TEST_TIME2); 917 assertEquals(true, test1.weekOfWeekyear().compareTo(test2) < 0); 918 assertEquals(true, test2.weekOfWeekyear().compareTo(test1) > 0); 919 assertEquals(true, test1.weekOfWeekyear().compareTo(test1) == 0); 920 try { 921 test1.weekOfWeekyear().compareTo((ReadableInstant) null); 922 fail(); 923 } catch (IllegalArgumentException ex) {} 924 925 DateTime dt1 = new DateTime(TEST_TIME1); 926 DateTime dt2 = new DateTime(TEST_TIME2); 927 assertEquals(true, test1.weekOfWeekyear().compareTo(dt2) < 0); 928 assertEquals(true, test2.weekOfWeekyear().compareTo(dt1) > 0); 929 assertEquals(true, test1.weekOfWeekyear().compareTo(dt1) == 0); 930 try { 931 test1.weekOfWeekyear().compareTo((ReadableInstant) null); 932 fail(); 933 } catch (IllegalArgumentException ex) {} 934 } 935 936 public void testPropertyGetDayOfWeek() { 938 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 939 assertSame(test.getChronology().dayOfWeek(), test.dayOfWeek().getField()); 940 assertEquals("dayOfWeek", test.dayOfWeek().getName()); 941 assertEquals("Property[dayOfWeek]", test.dayOfWeek().toString()); 942 assertSame(test, test.dayOfWeek().getDateTime()); 943 assertEquals(3, test.dayOfWeek().get()); 944 assertEquals("3", test.dayOfWeek().getAsString()); 945 assertEquals("Wednesday", test.dayOfWeek().getAsText()); 946 assertEquals("Wednesday", test.dayOfWeek().getField().getAsText(3, Locale.ENGLISH)); 947 assertEquals("mercredi", test.dayOfWeek().getAsText(Locale.FRENCH)); 948 assertEquals("mercredi", test.dayOfWeek().getField().getAsText(3, Locale.FRENCH)); 949 assertEquals("Wed", test.dayOfWeek().getAsShortText()); 950 assertEquals("Wed", test.dayOfWeek().getField().getAsShortText(3, Locale.ENGLISH)); 951 assertEquals("mer.", test.dayOfWeek().getAsShortText(Locale.FRENCH)); 952 assertEquals("mer.", test.dayOfWeek().getField().getAsShortText(3, Locale.FRENCH)); 953 assertEquals(test.getChronology().days(), test.dayOfWeek().getDurationField()); 954 assertEquals(test.getChronology().weeks(), test.dayOfWeek().getRangeDurationField()); 955 assertEquals(9, test.dayOfWeek().getMaximumTextLength(null)); 956 assertEquals(8, test.dayOfWeek().getMaximumTextLength(Locale.FRENCH)); 957 assertEquals(3, test.dayOfWeek().getMaximumShortTextLength(null)); 958 assertEquals(4, test.dayOfWeek().getMaximumShortTextLength(Locale.FRENCH)); 959 assertEquals(1, test.dayOfWeek().getMinimumValue()); 960 assertEquals(1, test.dayOfWeek().getMinimumValueOverall()); 961 assertEquals(7, test.dayOfWeek().getMaximumValue()); 962 assertEquals(7, test.dayOfWeek().getMaximumValueOverall()); 963 assertEquals(false, test.dayOfWeek().isLeap()); 964 assertEquals(0, test.dayOfWeek().getLeapAmount()); 965 assertEquals(null, test.dayOfWeek().getLeapDurationField()); 966 } 967 968 public void testPropertyAddDayOfWeek() { 969 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 970 DateTime copy = test.dayOfWeek().addToCopy(1); 971 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 972 assertEquals("2004-06-10T00:00:00.000+01:00", copy.toString()); 973 974 copy = test.dayOfWeek().addToCopy(21); 975 assertEquals("2004-06-30T00:00:00.000+01:00", copy.toString()); 976 977 copy = test.dayOfWeek().addToCopy(22); 978 assertEquals("2004-07-01T00:00:00.000+01:00", copy.toString()); 979 980 copy = test.dayOfWeek().addToCopy(21 + 31 + 31 + 30 + 31 + 30 + 31); 981 assertEquals("2004-12-31T00:00:00.000Z", copy.toString()); 982 983 copy = test.dayOfWeek().addToCopy(22 + 31 + 31 + 30 + 31 + 30 + 31); 984 assertEquals("2005-01-01T00:00:00.000Z", copy.toString()); 985 986 copy = test.dayOfWeek().addToCopy(-8); 987 assertEquals("2004-06-01T00:00:00.000+01:00", copy.toString()); 988 989 copy = test.dayOfWeek().addToCopy(-9); 990 assertEquals("2004-05-31T00:00:00.000+01:00", copy.toString()); 991 992 copy = test.dayOfWeek().addToCopy(-8 - 31 - 30 - 31 - 29 - 31); 993 assertEquals("2004-01-01T00:00:00.000Z", copy.toString()); 994 995 copy = test.dayOfWeek().addToCopy(-9 - 31 - 30 - 31 - 29 - 31); 996 assertEquals("2003-12-31T00:00:00.000Z", copy.toString()); 997 } 998 999 public void testPropertyAddLongDayOfWeek() { 1000 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 1001 DateTime copy = test.dayOfWeek().addToCopy(1L); 1002 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 1003 assertEquals("2004-06-10T00:00:00.000+01:00", copy.toString()); 1004 } 1005 1006 public void testPropertyAddWrapFieldDayOfWeek() { 1007 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); DateTime copy = test.dayOfWeek().addWrapFieldToCopy(1); 1009 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 1010 assertEquals("2004-06-10T00:00:00.000+01:00", copy.toString()); 1011 1012 copy = test.dayOfWeek().addWrapFieldToCopy(5); 1013 assertEquals("2004-06-07T00:00:00.000+01:00", copy.toString()); 1014 1015 copy = test.dayOfWeek().addWrapFieldToCopy(-10); 1016 assertEquals("2004-06-13T00:00:00.000+01:00", copy.toString()); 1017 1018 test = new DateTime(2004, 6, 2, 0, 0, 0, 0); 1019 copy = test.dayOfWeek().addWrapFieldToCopy(5); 1020 assertEquals("2004-06-02T00:00:00.000+01:00", test.toString()); 1021 assertEquals("2004-05-31T00:00:00.000+01:00", copy.toString()); 1022 } 1023 1024 public void testPropertySetDayOfWeek() { 1025 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 1026 DateTime copy = test.dayOfWeek().setCopy(4); 1027 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 1028 assertEquals("2004-06-10T00:00:00.000+01:00", copy.toString()); 1029 1030 try { 1031 test.dayOfWeek().setCopy(8); 1032 fail(); 1033 } catch (IllegalArgumentException ex) {} 1034 try { 1035 test.dayOfWeek().setCopy(0); 1036 fail(); 1037 } catch (IllegalArgumentException ex) {} 1038 } 1039 1040 public void testPropertySetTextDayOfWeek() { 1041 DateTime test = new DateTime(2004, 6, 9, 0, 0, 0, 0); 1042 DateTime copy = test.dayOfWeek().setCopy("4"); 1043 assertEquals("2004-06-09T00:00:00.000+01:00", test.toString()); 1044 assertEquals("2004-06-10T00:00:00.000+01:00", copy.toString()); 1045 copy = test.dayOfWeek().setCopy("Mon"); 1046 assertEquals("2004-06-07T00:00:00.000+01:00", copy.toString()); 1047 copy = test.dayOfWeek().setCopy("Tuesday"); 1048 assertEquals("2004-06-08T00:00:00.000+01:00", copy.toString()); 1049 copy = test.dayOfWeek().setCopy("lundi", Locale.FRENCH); 1050 assertEquals("2004-06-07T00:00:00.000+01:00", copy.toString()); 1051 } 1052 1053 public void testPropertyCompareToDayOfWeek() { 1054 DateTime test1 = new DateTime(TEST_TIME1); 1055 DateTime test2 = new DateTime(TEST_TIME2); 1056 assertEquals(true, test2.dayOfWeek().compareTo(test1) < 0); 1057 assertEquals(true, test1.dayOfWeek().compareTo(test2) > 0); 1058 assertEquals(true, test1.dayOfWeek().compareTo(test1) == 0); 1059 try { 1060 test1.dayOfWeek().compareTo((ReadableInstant) null); 1061 fail(); 1062 } catch (IllegalArgumentException ex) {} 1063 1064 DateTime dt1 = new DateTime(TEST_TIME1); 1065 DateTime dt2 = new DateTime(TEST_TIME2); 1066 assertEquals(true, test2.dayOfWeek().compareTo(dt1) < 0); 1067 assertEquals(true, test1.dayOfWeek().compareTo(dt2) > 0); 1068 assertEquals(true, test1.dayOfWeek().compareTo(dt1) == 0); 1069 try { 1070 test1.dayOfWeek().compareTo((ReadableInstant) null); 1071 fail(); 1072 } catch (IllegalArgumentException ex) {} 1073 } 1074 1075 public void testPropertyGetHourOfDay() { 1077 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1078 assertSame(test.getChronology().hourOfDay(), test.hourOfDay().getField()); 1079 assertEquals("hourOfDay", test.hourOfDay().getName()); 1080 assertEquals("Property[hourOfDay]", test.hourOfDay().toString()); 1081 assertSame(test, test.hourOfDay().getDateTime()); 1082 assertEquals(13, test.hourOfDay().get()); 1083 assertEquals("13", test.hourOfDay().getAsString()); 1084 assertEquals("13", test.hourOfDay().getAsText()); 1085 assertEquals("13", test.hourOfDay().getAsText(Locale.FRENCH)); 1086 assertEquals("13", test.hourOfDay().getAsShortText()); 1087 assertEquals("13", test.hourOfDay().getAsShortText(Locale.FRENCH)); 1088 assertEquals(test.getChronology().hours(), test.hourOfDay().getDurationField()); 1089 assertEquals(test.getChronology().days(), test.hourOfDay().getRangeDurationField()); 1090 assertEquals(2, test.hourOfDay().getMaximumTextLength(null)); 1091 assertEquals(2, test.hourOfDay().getMaximumShortTextLength(null)); 1092 } 1093 1094 public void testPropertyGetDifferenceHourOfDay() { 1095 DateTime test1 = new DateTime(2004, 6, 9, 13, 30, 0, 0); 1096 DateTime test2 = new DateTime(2004, 6, 9, 15, 30, 0, 0); 1097 assertEquals(-2, test1.hourOfDay().getDifference(test2)); 1098 assertEquals(2, test2.hourOfDay().getDifference(test1)); 1099 assertEquals(-2L, test1.hourOfDay().getDifferenceAsLong(test2)); 1100 assertEquals(2L, test2.hourOfDay().getDifferenceAsLong(test1)); 1101 1102 DateTime test = new DateTime(TEST_TIME_NOW + (13L * DateTimeConstants.MILLIS_PER_HOUR)); 1103 assertEquals(13, test.hourOfDay().getDifference(null)); 1104 assertEquals(13L, test.hourOfDay().getDifferenceAsLong(null)); 1105 } 1106 1107 public void testPropertyRoundFloorHourOfDay() { 1108 DateTime test = new DateTime(2004, 6, 9, 13, 30, 0, 0); 1109 DateTime copy = test.hourOfDay().roundFloorCopy(); 1110 assertEquals("2004-06-09T13:00:00.000+01:00", copy.toString()); 1111 } 1112 1113 public void testPropertyRoundCeilingHourOfDay() { 1114 DateTime test = new DateTime(2004, 6, 9, 13, 30, 0, 0); 1115 DateTime copy = test.hourOfDay().roundCeilingCopy(); 1116 assertEquals("2004-06-09T14:00:00.000+01:00", copy.toString()); 1117 } 1118 1119 public void testPropertyRoundHalfFloorHourOfDay() { 1120 DateTime test = new DateTime(2004, 6, 9, 13, 30, 0, 0); 1121 DateTime copy = test.hourOfDay().roundHalfFloorCopy(); 1122 assertEquals("2004-06-09T13:00:00.000+01:00", copy.toString()); 1123 1124 test = new DateTime(2004, 6, 9, 13, 30, 0, 1); 1125 copy = test.hourOfDay().roundHalfFloorCopy(); 1126 assertEquals("2004-06-09T14:00:00.000+01:00", copy.toString()); 1127 1128 test = new DateTime(2004, 6, 9, 13, 29, 59, 999); 1129 copy = test.hourOfDay().roundHalfFloorCopy(); 1130 assertEquals("2004-06-09T13:00:00.000+01:00", copy.toString()); 1131 } 1132 1133 public void testPropertyRoundHalfCeilingHourOfDay() { 1134 DateTime test = new DateTime(2004, 6, 9, 13, 30, 0, 0); 1135 DateTime copy = test.hourOfDay().roundHalfCeilingCopy(); 1136 assertEquals("2004-06-09T14:00:00.000+01:00", copy.toString()); 1137 1138 test = new DateTime(2004, 6, 9, 13, 30, 0, 1); 1139 copy = test.hourOfDay().roundHalfCeilingCopy(); 1140 assertEquals("2004-06-09T14:00:00.000+01:00", copy.toString()); 1141 1142 test = new DateTime(2004, 6, 9, 13, 29, 59, 999); 1143 copy = test.hourOfDay().roundHalfCeilingCopy(); 1144 assertEquals("2004-06-09T13:00:00.000+01:00", copy.toString()); 1145 } 1146 1147 public void testPropertyRoundHalfEvenHourOfDay() { 1148 DateTime test = new DateTime(2004, 6, 9, 13, 30, 0, 0); 1149 DateTime copy = test.hourOfDay().roundHalfEvenCopy(); 1150 assertEquals("2004-06-09T14:00:00.000+01:00", copy.toString()); 1151 1152 test = new DateTime(2004, 6, 9, 14, 30, 0, 0); 1153 copy = test.hourOfDay().roundHalfEvenCopy(); 1154 assertEquals("2004-06-09T14:00:00.000+01:00", copy.toString()); 1155 1156 test = new DateTime(2004, 6, 9, 13, 30, 0, 1); 1157 copy = test.hourOfDay().roundHalfEvenCopy(); 1158 assertEquals("2004-06-09T14:00:00.000+01:00", copy.toString()); 1159 1160 test = new DateTime(2004, 6, 9, 13, 29, 59, 999); 1161 copy = test.hourOfDay().roundHalfEvenCopy(); 1162 assertEquals("2004-06-09T13:00:00.000+01:00", copy.toString()); 1163 } 1164 1165 public void testPropertyRemainderHourOfDay() { 1166 DateTime test = new DateTime(2004, 6, 9, 13, 30, 0, 0); 1167 assertEquals(30L * DateTimeConstants.MILLIS_PER_MINUTE, test.hourOfDay().remainder()); 1168 } 1169 1170 public void testPropertyGetMinuteOfHour() { 1172 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1173 assertSame(test.getChronology().minuteOfHour(), test.minuteOfHour().getField()); 1174 assertEquals("minuteOfHour", test.minuteOfHour().getName()); 1175 assertEquals("Property[minuteOfHour]", test.minuteOfHour().toString()); 1176 assertSame(test, test.minuteOfHour().getDateTime()); 1177 assertEquals(23, test.minuteOfHour().get()); 1178 assertEquals("23", test.minuteOfHour().getAsString()); 1179 assertEquals("23", test.minuteOfHour().getAsText()); 1180 assertEquals("23", test.minuteOfHour().getAsText(Locale.FRENCH)); 1181 assertEquals("23", test.minuteOfHour().getAsShortText()); 1182 assertEquals("23", test.minuteOfHour().getAsShortText(Locale.FRENCH)); 1183 assertEquals(test.getChronology().minutes(), test.minuteOfHour().getDurationField()); 1184 assertEquals(test.getChronology().hours(), test.minuteOfHour().getRangeDurationField()); 1185 assertEquals(2, test.minuteOfHour().getMaximumTextLength(null)); 1186 assertEquals(2, test.minuteOfHour().getMaximumShortTextLength(null)); 1187 } 1188 1189 public void testPropertyGetMinuteOfDay() { 1191 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1192 assertSame(test.getChronology().minuteOfDay(), test.minuteOfDay().getField()); 1193 assertEquals("minuteOfDay", test.minuteOfDay().getName()); 1194 assertEquals("Property[minuteOfDay]", test.minuteOfDay().toString()); 1195 assertSame(test, test.minuteOfDay().getDateTime()); 1196 assertEquals(803, test.minuteOfDay().get()); 1197 assertEquals("803", test.minuteOfDay().getAsString()); 1198 assertEquals("803", test.minuteOfDay().getAsText()); 1199 assertEquals("803", test.minuteOfDay().getAsText(Locale.FRENCH)); 1200 assertEquals("803", test.minuteOfDay().getAsShortText()); 1201 assertEquals("803", test.minuteOfDay().getAsShortText(Locale.FRENCH)); 1202 assertEquals(test.getChronology().minutes(), test.minuteOfDay().getDurationField()); 1203 assertEquals(test.getChronology().days(), test.minuteOfDay().getRangeDurationField()); 1204 assertEquals(4, test.minuteOfDay().getMaximumTextLength(null)); 1205 assertEquals(4, test.minuteOfDay().getMaximumShortTextLength(null)); 1206 } 1207 1208 public void testPropertyGetSecondOfMinute() { 1210 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1211 assertSame(test.getChronology().secondOfMinute(), test.secondOfMinute().getField()); 1212 assertEquals("secondOfMinute", test.secondOfMinute().getName()); 1213 assertEquals("Property[secondOfMinute]", test.secondOfMinute().toString()); 1214 assertSame(test, test.secondOfMinute().getDateTime()); 1215 assertEquals(43, test.secondOfMinute().get()); 1216 assertEquals("43", test.secondOfMinute().getAsString()); 1217 assertEquals("43", test.secondOfMinute().getAsText()); 1218 assertEquals("43", test.secondOfMinute().getAsText(Locale.FRENCH)); 1219 assertEquals("43", test.secondOfMinute().getAsShortText()); 1220 assertEquals("43", test.secondOfMinute().getAsShortText(Locale.FRENCH)); 1221 assertEquals(test.getChronology().seconds(), test.secondOfMinute().getDurationField()); 1222 assertEquals(test.getChronology().minutes(), test.secondOfMinute().getRangeDurationField()); 1223 assertEquals(2, test.secondOfMinute().getMaximumTextLength(null)); 1224 assertEquals(2, test.secondOfMinute().getMaximumShortTextLength(null)); 1225 } 1226 1227 public void testPropertyGetSecondOfDay() { 1229 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1230 assertSame(test.getChronology().secondOfDay(), test.secondOfDay().getField()); 1231 assertEquals("secondOfDay", test.secondOfDay().getName()); 1232 assertEquals("Property[secondOfDay]", test.secondOfDay().toString()); 1233 assertSame(test, test.secondOfDay().getDateTime()); 1234 assertEquals(48223, test.secondOfDay().get()); 1235 assertEquals("48223", test.secondOfDay().getAsString()); 1236 assertEquals("48223", test.secondOfDay().getAsText()); 1237 assertEquals("48223", test.secondOfDay().getAsText(Locale.FRENCH)); 1238 assertEquals("48223", test.secondOfDay().getAsShortText()); 1239 assertEquals("48223", test.secondOfDay().getAsShortText(Locale.FRENCH)); 1240 assertEquals(test.getChronology().seconds(), test.secondOfDay().getDurationField()); 1241 assertEquals(test.getChronology().days(), test.secondOfDay().getRangeDurationField()); 1242 assertEquals(5, test.secondOfDay().getMaximumTextLength(null)); 1243 assertEquals(5, test.secondOfDay().getMaximumShortTextLength(null)); 1244 } 1245 1246 public void testPropertyGetMillisOfSecond() { 1248 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1249 assertSame(test.getChronology().millisOfSecond(), test.millisOfSecond().getField()); 1250 assertEquals("millisOfSecond", test.millisOfSecond().getName()); 1251 assertEquals("Property[millisOfSecond]", test.millisOfSecond().toString()); 1252 assertSame(test, test.millisOfSecond().getDateTime()); 1253 assertEquals(53, test.millisOfSecond().get()); 1254 assertEquals("53", test.millisOfSecond().getAsString()); 1255 assertEquals("53", test.millisOfSecond().getAsText()); 1256 assertEquals("53", test.millisOfSecond().getAsText(Locale.FRENCH)); 1257 assertEquals("53", test.millisOfSecond().getAsShortText()); 1258 assertEquals("53", test.millisOfSecond().getAsShortText(Locale.FRENCH)); 1259 assertEquals(test.getChronology().millis(), test.millisOfSecond().getDurationField()); 1260 assertEquals(test.getChronology().seconds(), test.millisOfSecond().getRangeDurationField()); 1261 assertEquals(3, test.millisOfSecond().getMaximumTextLength(null)); 1262 assertEquals(3, test.millisOfSecond().getMaximumShortTextLength(null)); 1263 } 1264 1265 public void testPropertyGetMillisOfDay() { 1267 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1268 assertSame(test.getChronology().millisOfDay(), test.millisOfDay().getField()); 1269 assertEquals("millisOfDay", test.millisOfDay().getName()); 1270 assertEquals("Property[millisOfDay]", test.millisOfDay().toString()); 1271 assertSame(test, test.millisOfDay().getDateTime()); 1272 assertEquals(48223053, test.millisOfDay().get()); 1273 assertEquals("48223053", test.millisOfDay().getAsString()); 1274 assertEquals("48223053", test.millisOfDay().getAsText()); 1275 assertEquals("48223053", test.millisOfDay().getAsText(Locale.FRENCH)); 1276 assertEquals("48223053", test.millisOfDay().getAsShortText()); 1277 assertEquals("48223053", test.millisOfDay().getAsShortText(Locale.FRENCH)); 1278 assertEquals(test.getChronology().millis(), test.millisOfDay().getDurationField()); 1279 assertEquals(test.getChronology().days(), test.millisOfDay().getRangeDurationField()); 1280 assertEquals(8, test.millisOfDay().getMaximumTextLength(null)); 1281 assertEquals(8, test.millisOfDay().getMaximumShortTextLength(null)); 1282 } 1283 1284 public void testPropertyToIntervalYearOfEra() { 1286 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1287 Interval testInterval = test.yearOfEra().toInterval(); 1288 assertEquals(new DateTime(2004, 1, 1, 0, 0, 0, 0), testInterval.getStart()); 1289 assertEquals(new DateTime(2005, 1, 1, 0, 0, 0, 0), testInterval.getEnd()); 1290 } 1291 1292 public void testPropertyToIntervalYearOfCentury() { 1293 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1294 Interval testInterval = test.yearOfCentury().toInterval(); 1295 assertEquals(new DateTime(2004, 1, 1, 0, 0, 0, 0), testInterval.getStart()); 1296 assertEquals(new DateTime(2005, 1, 1, 0, 0, 0, 0), testInterval.getEnd()); 1297 } 1298 1299 public void testPropertyToIntervalYear() { 1300 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1301 Interval testInterval = test.year().toInterval(); 1302 assertEquals(new DateTime(2004, 1, 1, 0, 0, 0, 0), testInterval.getStart()); 1303 assertEquals(new DateTime(2005, 1, 1, 0, 0, 0, 0), testInterval.getEnd()); 1304 } 1305 1306 public void testPropertyToIntervalMonthOfYear() { 1307 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1308 Interval testInterval = test.monthOfYear().toInterval(); 1309 assertEquals(new DateTime(2004, 6, 1, 0, 0, 0, 0), testInterval.getStart()); 1310 assertEquals(new DateTime(2004, 7, 1, 0, 0, 0, 0), testInterval.getEnd()); 1311 } 1312 1313 public void testPropertyToIntervalDayOfMonth() { 1314 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1315 Interval testInterval = test.dayOfMonth().toInterval(); 1316 assertEquals(new DateTime(2004, 6, 9, 0, 0, 0, 0), testInterval.getStart()); 1317 assertEquals(new DateTime(2004, 6, 10, 0, 0, 0, 0), testInterval.getEnd()); 1318 1319 DateTime febTest = new DateTime(2004, 2, 29, 13, 23, 43, 53); 1320 Interval febTestInterval = febTest.dayOfMonth().toInterval(); 1321 assertEquals(new DateTime(2004, 2, 29, 0, 0, 0, 0), febTestInterval.getStart()); 1322 assertEquals(new DateTime(2004, 3, 1, 0, 0, 0, 0), febTestInterval.getEnd()); 1323 } 1324 1325 public void testPropertyToIntervalHourOfDay() { 1326 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1327 Interval testInterval = test.hourOfDay().toInterval(); 1328 assertEquals(new DateTime(2004, 6, 9, 13, 0, 0, 0), testInterval.getStart()); 1329 assertEquals(new DateTime(2004, 6, 9, 14, 0, 0, 0), testInterval.getEnd()); 1330 1331 DateTime midnightTest = new DateTime(2004, 6, 9, 23, 23, 43, 53); 1332 Interval midnightTestInterval = midnightTest.hourOfDay().toInterval(); 1333 assertEquals(new DateTime(2004, 6, 9, 23, 0, 0, 0), midnightTestInterval.getStart()); 1334 assertEquals(new DateTime(2004, 6, 10, 0, 0, 0, 0), midnightTestInterval.getEnd()); 1335 } 1336 1337 public void testPropertyToIntervalMinuteOfHour() { 1338 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1339 Interval testInterval = test.minuteOfHour().toInterval(); 1340 assertEquals(new DateTime(2004, 6, 9, 13, 23, 0, 0), testInterval.getStart()); 1341 assertEquals(new DateTime(2004, 6, 9, 13, 24, 0, 0), testInterval.getEnd()); 1342 } 1343 1344 public void testPropertyToIntervalSecondOfMinute() { 1345 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1346 Interval testInterval = test.secondOfMinute().toInterval(); 1347 assertEquals(new DateTime(2004, 6, 9, 13, 23, 43, 0), testInterval.getStart()); 1348 assertEquals(new DateTime(2004, 6, 9, 13, 23, 44, 0), testInterval.getEnd()); 1349 } 1350 1351 public void testPropertyToIntervalMillisOfSecond() { 1352 DateTime test = new DateTime(2004, 6, 9, 13, 23, 43, 53); 1353 Interval testInterval = test.millisOfSecond().toInterval(); 1354 assertEquals(new DateTime(2004, 6, 9, 13, 23, 43, 53), testInterval.getStart()); 1355 assertEquals(new DateTime(2004, 6, 9, 13, 23, 43, 54), testInterval.getEnd()); 1356 } 1357 1358 public void testPropertyEqualsHashCodeLenient() { 1359 DateTime test1 = new DateTime(1970, 6, 9, 0, 0, 0, 0, LenientChronology.getInstance(COPTIC_PARIS)); 1360 DateTime test2 = new DateTime(1970, 6, 9, 0, 0, 0, 0, LenientChronology.getInstance(COPTIC_PARIS)); 1361 assertEquals(true, test1.dayOfMonth().equals(test2.dayOfMonth())); 1362 assertEquals(true, test2.dayOfMonth().equals(test1.dayOfMonth())); 1363 assertEquals(true, test1.dayOfMonth().equals(test1.dayOfMonth())); 1364 assertEquals(true, test2.dayOfMonth().equals(test2.dayOfMonth())); 1365 assertEquals(true, test1.dayOfMonth().hashCode() == test2.dayOfMonth().hashCode()); 1366 assertEquals(true, test1.dayOfMonth().hashCode() == test1.dayOfMonth().hashCode()); 1367 assertEquals(true, test2.dayOfMonth().hashCode() == test2.dayOfMonth().hashCode()); 1368 } 1369 1370 public void testPropertyEqualsHashCodeStrict() { 1371 DateTime test1 = new DateTime(1970, 6, 9, 0, 0, 0, 0, StrictChronology.getInstance(COPTIC_PARIS)); 1372 DateTime test2 = new DateTime(1970, 6, 9, 0, 0, 0, 0, StrictChronology.getInstance(COPTIC_PARIS)); 1373 assertEquals(true, test1.dayOfMonth().equals(test2.dayOfMonth())); 1374 assertEquals(true, test2.dayOfMonth().equals(test1.dayOfMonth())); 1375 assertEquals(true, test1.dayOfMonth().equals(test1.dayOfMonth())); 1376 assertEquals(true, test2.dayOfMonth().equals(test2.dayOfMonth())); 1377 assertEquals(true, test1.dayOfMonth().hashCode() == test2.dayOfMonth().hashCode()); 1378 assertEquals(true, test1.dayOfMonth().hashCode() == test1.dayOfMonth().hashCode()); 1379 assertEquals(true, test2.dayOfMonth().hashCode() == test2.dayOfMonth().hashCode()); 1380 } 1381 1382} 1383 | Popular Tags |