1 16 package org.joda.time; 17 18 import java.io.IOException ; 19 import java.io.ObjectInputStream ; 20 import java.io.ObjectOutputStream ; 21 import java.io.Serializable ; 22 import java.util.Calendar ; 23 import java.util.Date ; 24 import java.util.Locale ; 25 26 import org.joda.time.base.AbstractPartial; 27 import org.joda.time.chrono.ISOChronology; 28 import org.joda.time.convert.ConverterManager; 29 import org.joda.time.convert.PartialConverter; 30 import org.joda.time.field.AbstractReadableInstantFieldProperty; 31 import org.joda.time.format.DateTimeFormat; 32 import org.joda.time.format.ISODateTimeFormat; 33 34 76 public final class LocalDateTime 77 extends AbstractPartial 78 implements ReadablePartial, Serializable { 79 80 81 private static final long serialVersionUID = -268716875315837168L; 82 83 84 private static final int YEAR = 0; 85 86 private static final int MONTH_OF_YEAR = 1; 87 88 private static final int DAY_OF_MONTH = 2; 89 90 private static final int MILLIS_OF_DAY = 3; 91 92 93 private long iLocalMillis; 94 95 private Chronology iChronology; 96 97 116 public static LocalDateTime fromCalendarFields(Calendar calendar) { 117 if (calendar == null) { 118 throw new IllegalArgumentException ("The calendar must not be null"); 119 } 120 return new LocalDateTime( 121 calendar.get(Calendar.YEAR), 122 calendar.get(Calendar.MONTH) + 1, 123 calendar.get(Calendar.DAY_OF_MONTH), 124 calendar.get(Calendar.HOUR_OF_DAY), 125 calendar.get(Calendar.MINUTE), 126 calendar.get(Calendar.SECOND), 127 calendar.get(Calendar.MILLISECOND) 128 ); 129 } 130 131 146 public static LocalDateTime fromDateFields(Date date) { 147 if (date == null) { 148 throw new IllegalArgumentException ("The date must not be null"); 149 } 150 return new LocalDateTime( 151 date.getYear() + 1900, 152 date.getMonth() + 1, 153 date.getDate(), 154 date.getHours(), 155 date.getMinutes(), 156 date.getSeconds(), 157 (int) (date.getTime() % 1000) 158 ); 159 } 160 161 168 public LocalDateTime() { 169 this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance()); 170 } 171 172 181 public LocalDateTime(DateTimeZone zone) { 182 this(DateTimeUtils.currentTimeMillis(), ISOChronology.getInstance(zone)); 183 } 184 185 194 public LocalDateTime(Chronology chronology) { 195 this(DateTimeUtils.currentTimeMillis(), chronology); 196 } 197 198 207 public LocalDateTime(long instant) { 208 this(instant, ISOChronology.getInstance()); 209 } 210 211 221 public LocalDateTime(long instant, DateTimeZone zone) { 222 this(instant, ISOChronology.getInstance(zone)); 223 } 224 225 235 public LocalDateTime(long instant, Chronology chronology) { 236 chronology = DateTimeUtils.getChronology(chronology); 237 238 long localMillis = chronology.getZone().getMillisKeepLocal(DateTimeZone.UTC, instant); 239 iLocalMillis = localMillis; 240 iChronology = chronology.withUTC(); 241 } 242 243 260 public LocalDateTime(Object instant) { 261 this(instant, (Chronology) null); 262 } 263 264 282 public LocalDateTime(Object instant, DateTimeZone zone) { 283 PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant); 284 Chronology chronology = converter.getChronology(instant, zone); 285 chronology = DateTimeUtils.getChronology(chronology); 286 iChronology = chronology.withUTC(); 287 int[] values = converter.getPartialValues(this, instant, chronology, ISODateTimeFormat.localDateOptionalTimeParser()); 288 iLocalMillis = iChronology.getDateTimeMillis(values[0], values[1], values[2], values[3]); 289 } 290 291 308 public LocalDateTime(Object instant, Chronology chronology) { 309 PartialConverter converter = ConverterManager.getInstance().getPartialConverter(instant); 310 chronology = converter.getChronology(instant, chronology); 311 chronology = DateTimeUtils.getChronology(chronology); 312 iChronology = chronology.withUTC(); 313 int[] values = converter.getPartialValues(this, instant, chronology, ISODateTimeFormat.localDateOptionalTimeParser()); 314 iLocalMillis = iChronology.getDateTimeMillis(values[0], values[1], values[2], values[3]); 315 } 316 317 328 public LocalDateTime( 329 int year, 330 int monthOfYear, 331 int dayOfMonth, 332 int hourOfDay, 333 int minuteOfHour) { 334 this(year, monthOfYear, dayOfMonth, hourOfDay, 335 minuteOfHour, 0, 0, ISOChronology.getInstanceUTC()); 336 } 337 338 349 public LocalDateTime( 350 int year, 351 int monthOfYear, 352 int dayOfMonth, 353 int hourOfDay, 354 int minuteOfHour, 355 int secondOfMinute) { 356 this(year, monthOfYear, dayOfMonth, hourOfDay, 357 minuteOfHour, secondOfMinute, 0, ISOChronology.getInstanceUTC()); 358 } 359 360 372 public LocalDateTime( 373 int year, 374 int monthOfYear, 375 int dayOfMonth, 376 int hourOfDay, 377 int minuteOfHour, 378 int secondOfMinute, 379 int millisOfSecond) { 380 this(year, monthOfYear, dayOfMonth, hourOfDay, 381 minuteOfHour, secondOfMinute, millisOfSecond, ISOChronology.getInstanceUTC()); 382 } 383 384 399 public LocalDateTime( 400 int year, 401 int monthOfYear, 402 int dayOfMonth, 403 int hourOfDay, 404 int minuteOfHour, 405 int secondOfMinute, 406 int millisOfSecond, 407 Chronology chronology) { 408 super(); 409 chronology = DateTimeUtils.getChronology(chronology).withUTC(); 410 long instant = chronology.getDateTimeMillis(year, monthOfYear, dayOfMonth, 411 hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond); 412 iChronology = chronology; 413 iLocalMillis = instant; 414 } 415 416 423 public int size() { 424 return 4; 425 } 426 427 436 protected DateTimeField getField(int index, Chronology chrono) { 437 switch (index) { 438 case YEAR: 439 return chrono.year(); 440 case MONTH_OF_YEAR: 441 return chrono.monthOfYear(); 442 case DAY_OF_MONTH: 443 return chrono.dayOfMonth(); 444 case MILLIS_OF_DAY: 445 return chrono.millisOfDay(); 446 default: 447 throw new IndexOutOfBoundsException ("Invalid index: " + index); 448 } 449 } 450 451 461 public int getValue(int index) { 462 switch (index) { 463 case YEAR: 464 return getChronology().year().get(getLocalMillis()); 465 case MONTH_OF_YEAR: 466 return getChronology().monthOfYear().get(getLocalMillis()); 467 case DAY_OF_MONTH: 468 return getChronology().dayOfMonth().get(getLocalMillis()); 469 case MILLIS_OF_DAY: 470 return getChronology().millisOfDay().get(getLocalMillis()); 471 default: 472 throw new IndexOutOfBoundsException ("Invalid index: " + index); 473 } 474 } 475 476 491 public int get(DateTimeFieldType type) { 492 if (type == null) { 493 throw new IllegalArgumentException ("The DateTimeFieldType must not be null"); 494 } 495 return type.getField(getChronology()).get(getLocalMillis()); 496 } 497 498 506 public boolean isSupported(DateTimeFieldType type) { 507 if (type == null) { 508 return false; 509 } 510 return type.getField(getChronology()).isSupported(); 511 } 512 513 520 public boolean isSupported(DurationFieldType type) { 521 if (type == null) { 522 return false; 523 } 524 return type.getField(getChronology()).isSupported(); 525 } 526 527 534 long getLocalMillis() { 535 return iLocalMillis; 536 } 537 538 543 public Chronology getChronology() { 544 return iChronology; 545 } 546 547 553 public DateTime toDateTime() { 554 return toDateTime((DateTimeZone) null); 555 } 556 557 563 public DateTime toDateTime(DateTimeZone zone) { 564 zone = DateTimeUtils.getZone(zone); 565 Chronology chrono = iChronology.withZone(zone); 566 return new DateTime( 567 getYear(), getMonthOfYear(), getDayOfMonth(), 568 getHourOfDay(), getMinuteOfHour(), 569 getSecondOfMinute(), getMillisOfSecond(), chrono); 570 } 571 572 578 public LocalDate toLocalDate() { 579 return new LocalDate(getLocalMillis(), getChronology()); 580 } 581 582 587 public LocalTime toLocalTime() { 588 return new LocalTime(getLocalMillis(), getChronology()); 589 } 590 591 602 LocalDateTime withLocalMillis(long newMillis) { 603 return (newMillis == getLocalMillis() ? this : new LocalDateTime(newMillis, getChronology())); 604 } 605 606 624 public LocalDateTime withDate(int year, int monthOfYear, int dayOfMonth) { 625 Chronology chrono = getChronology(); 626 long instant = getLocalMillis(); 627 instant = chrono.year().set(instant, year); 628 instant = chrono.monthOfYear().set(instant, monthOfYear); 629 instant = chrono.dayOfMonth().set(instant, dayOfMonth); 630 return withLocalMillis(instant); 631 } 632 633 651 public LocalDateTime withTime(int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) { 652 Chronology chrono = getChronology(); 653 long instant = getLocalMillis(); 654 instant = chrono.hourOfDay().set(instant, hourOfDay); 655 instant = chrono.minuteOfHour().set(instant, minuteOfHour); 656 instant = chrono.secondOfMinute().set(instant, secondOfMinute); 657 instant = chrono.millisOfSecond().set(instant, millisOfSecond); 658 return withLocalMillis(instant); 659 } 660 661 674 public LocalDateTime withFields(ReadablePartial partial) { 675 if (partial == null) { 676 return this; 677 } 678 return withLocalMillis(getChronology().set(partial, getLocalMillis())); 679 } 680 681 700 public LocalDateTime withField(DateTimeFieldType fieldType, int value) { 701 if (fieldType == null) { 702 throw new IllegalArgumentException ("Field must not be null"); 703 } 704 long instant = fieldType.getField(getChronology()).set(getLocalMillis(), value); 705 return withLocalMillis(instant); 706 } 707 708 727 public LocalDateTime withFieldAdded(DurationFieldType fieldType, int amount) { 728 if (fieldType == null) { 729 throw new IllegalArgumentException ("Field must not be null"); 730 } 731 if (amount == 0) { 732 return this; 733 } 734 long instant = fieldType.getField(getChronology()).add(getLocalMillis(), amount); 735 return withLocalMillis(instant); 736 } 737 738 749 public LocalDateTime withDurationAdded(ReadableDuration durationToAdd, int scalar) { 750 if (durationToAdd == null || scalar == 0) { 751 return this; 752 } 753 long instant = getChronology().add(getLocalMillis(), durationToAdd.getMillis(), scalar); 754 return withLocalMillis(instant); 755 } 756 757 772 public LocalDateTime withPeriodAdded(ReadablePeriod period, int scalar) { 773 if (period == null || scalar == 0) { 774 return this; 775 } 776 long instant = getChronology().add(period, getLocalMillis(), scalar); 777 return withLocalMillis(instant); 778 } 779 780 790 public LocalDateTime plus(ReadableDuration duration) { 791 return withDurationAdded(duration, 1); 792 } 793 794 807 public LocalDateTime plus(ReadablePeriod period) { 808 return withPeriodAdded(period, 1); 809 } 810 811 827 public LocalDateTime plusYears(int years) { 828 if (years == 0) { 829 return this; 830 } 831 long instant = getChronology().years().add(getLocalMillis(), years); 832 return withLocalMillis(instant); 833 } 834 835 850 public LocalDateTime plusMonths(int months) { 851 if (months == 0) { 852 return this; 853 } 854 long instant = getChronology().months().add(getLocalMillis(), months); 855 return withLocalMillis(instant); 856 } 857 858 873 public LocalDateTime plusWeeks(int weeks) { 874 if (weeks == 0) { 875 return this; 876 } 877 long instant = getChronology().weeks().add(getLocalMillis(), weeks); 878 return withLocalMillis(instant); 879 } 880 881 896 public LocalDateTime plusDays(int days) { 897 if (days == 0) { 898 return this; 899 } 900 long instant = getChronology().days().add(getLocalMillis(), days); 901 return withLocalMillis(instant); 902 } 903 904 920 public LocalDateTime plusHours(int hours) { 921 if (hours == 0) { 922 return this; 923 } 924 long instant = getChronology().hours().add(getLocalMillis(), hours); 925 return withLocalMillis(instant); 926 } 927 928 943 public LocalDateTime plusMinutes(int minutes) { 944 if (minutes == 0) { 945 return this; 946 } 947 long instant = getChronology().minutes().add(getLocalMillis(), minutes); 948 return withLocalMillis(instant); 949 } 950 951 966 public LocalDateTime plusSeconds(int seconds) { 967 if (seconds == 0) { 968 return this; 969 } 970 long instant = getChronology().seconds().add(getLocalMillis(), seconds); 971 return withLocalMillis(instant); 972 } 973 974 989 public LocalDateTime plusMillis(int millis) { 990 if (millis == 0) { 991 return this; 992 } 993 long instant = getChronology().millis().add(getLocalMillis(), millis); 994 return withLocalMillis(instant); 995 } 996 997 1007 public LocalDateTime minus(ReadableDuration duration) { 1008 return withDurationAdded(duration, -1); 1009 } 1010 1011 1024 public LocalDateTime minus(ReadablePeriod period) { 1025 return withPeriodAdded(period, -1); 1026 } 1027 1028 1044 public LocalDateTime minusYears(int years) { 1045 if (years == 0) { 1046 return this; 1047 } 1048 long instant = getChronology().years().subtract(getLocalMillis(), years); 1049 return withLocalMillis(instant); 1050 } 1051 1052 1067 public LocalDateTime minusMonths(int months) { 1068 if (months == 0) { 1069 return this; 1070 } 1071 long instant = getChronology().months().subtract(getLocalMillis(), months); 1072 return withLocalMillis(instant); 1073 } 1074 1075 1090 public LocalDateTime minusWeeks(int weeks) { 1091 if (weeks == 0) { 1092 return this; 1093 } 1094 long instant = getChronology().weeks().subtract(getLocalMillis(), weeks); 1095 return withLocalMillis(instant); 1096 } 1097 1098 1113 public LocalDateTime minusDays(int days) { 1114 if (days == 0) { 1115 return this; 1116 } 1117 long instant = getChronology().days().subtract(getLocalMillis(), days); 1118 return withLocalMillis(instant); 1119 } 1120 1121 1137 public LocalDateTime minusHours(int hours) { 1138 if (hours == 0) { 1139 return this; 1140 } 1141 long instant = getChronology().hours().subtract(getLocalMillis(), hours); 1142 return withLocalMillis(instant); 1143 } 1144 1145 1160 public LocalDateTime minusMinutes(int minutes) { 1161 if (minutes == 0) { 1162 return this; 1163 } 1164 long instant = getChronology().minutes().subtract(getLocalMillis(), minutes); 1165 return withLocalMillis(instant); 1166 } 1167 1168 1183 public LocalDateTime minusSeconds(int seconds) { 1184 if (seconds == 0) { 1185 return this; 1186 } 1187 long instant = getChronology().seconds().subtract(getLocalMillis(), seconds); 1188 return withLocalMillis(instant); 1189 } 1190 1191 1206 public LocalDateTime minusMillis(int millis) { 1207 if (millis == 0) { 1208 return this; 1209 } 1210 long instant = getChronology().millis().subtract(getLocalMillis(), millis); 1211 return withLocalMillis(instant); 1212 } 1213 1214 1223 public Property property(DateTimeFieldType fieldType) { 1224 if (fieldType == null) { 1225 throw new IllegalArgumentException ("The DateTimeFieldType must not be null"); 1226 } 1227 if (isSupported(fieldType) == false) { 1228 throw new IllegalArgumentException ("Field '" + fieldType + "' is not supported"); 1229 } 1230 return new Property(this, fieldType.getField(getChronology())); 1231 } 1232 1233 1239 public int getEra() { 1240 return getChronology().era().get(getLocalMillis()); 1241 } 1242 1243 1248 public int getCenturyOfEra() { 1249 return getChronology().centuryOfEra().get(getLocalMillis()); 1250 } 1251 1252 1257 public int getYearOfEra() { 1258 return getChronology().yearOfEra().get(getLocalMillis()); 1259 } 1260 1261 1266 public int getYearOfCentury() { 1267 return getChronology().yearOfCentury().get(getLocalMillis()); 1268 } 1269 1270 1275 public int getYear() { 1276 return getChronology().year().get(getLocalMillis()); 1277 } 1278 1279 1290 public int getWeekyear() { 1291 return getChronology().weekyear().get(getLocalMillis()); 1292 } 1293 1294 1299 public int getMonthOfYear() { 1300 return getChronology().monthOfYear().get(getLocalMillis()); 1301 } 1302 1303 1308 public int getWeekOfWeekyear() { 1309 return getChronology().weekOfWeekyear().get(getLocalMillis()); 1310 } 1311 1312 1317 public int getDayOfYear() { 1318 return getChronology().dayOfYear().get(getLocalMillis()); 1319 } 1320 1321 1328 public int getDayOfMonth() { 1329 return getChronology().dayOfMonth().get(getLocalMillis()); 1330 } 1331 1332 1339 public int getDayOfWeek() { 1340 return getChronology().dayOfWeek().get(getLocalMillis()); 1341 } 1342 1343 1349 public int getHourOfDay() { 1350 return getChronology().hourOfDay().get(getLocalMillis()); 1351 } 1352 1353 1358 public int getMinuteOfHour() { 1359 return getChronology().minuteOfHour().get(getLocalMillis()); 1360 } 1361 1362 1367 public int getSecondOfMinute() { 1368 return getChronology().secondOfMinute().get(getLocalMillis()); 1369 } 1370 1371 1376 public int getMillisOfSecond() { 1377 return getChronology().millisOfSecond().get(getLocalMillis()); 1378 } 1379 1380 1385 public int getMillisOfDay() { 1386 return getChronology().millisOfDay().get(getLocalMillis()); 1387 } 1388 1389 1401 public LocalDateTime withEra(int era) { 1402 return withLocalMillis(getChronology().era().set(getLocalMillis(), era)); 1403 } 1404 1405 1416 public LocalDateTime withCenturyOfEra(int centuryOfEra) { 1417 return withLocalMillis(getChronology().centuryOfEra().set(getLocalMillis(), centuryOfEra)); 1418 } 1419 1420 1431 public LocalDateTime withYearOfEra(int yearOfEra) { 1432 return withLocalMillis(getChronology().yearOfEra().set(getLocalMillis(), yearOfEra)); 1433 } 1434 1435 1446 public LocalDateTime withYearOfCentury(int yearOfCentury) { 1447 return withLocalMillis(getChronology().yearOfCentury().set(getLocalMillis(), yearOfCentury)); 1448 } 1449 1450 1461 public LocalDateTime withYear(int year) { 1462 return withLocalMillis(getChronology().year().set(getLocalMillis(), year)); 1463 } 1464 1465 1476 public LocalDateTime withWeekyear(int weekyear) { 1477 return withLocalMillis(getChronology().weekyear().set(getLocalMillis(), weekyear)); 1478 } 1479 1480 1491 public LocalDateTime withMonthOfYear(int monthOfYear) { 1492 return withLocalMillis(getChronology().monthOfYear().set(getLocalMillis(), monthOfYear)); 1493 } 1494 1495 1506 public LocalDateTime withWeekOfWeekyear(int weekOfWeekyear) { 1507 return withLocalMillis(getChronology().weekOfWeekyear().set(getLocalMillis(), weekOfWeekyear)); 1508 } 1509 1510 1521 public LocalDateTime withDayOfYear(int dayOfYear) { 1522 return withLocalMillis(getChronology().dayOfYear().set(getLocalMillis(), dayOfYear)); 1523 } 1524 1525 1536 public LocalDateTime withDayOfMonth(int dayOfMonth) { 1537 return withLocalMillis(getChronology().dayOfMonth().set(getLocalMillis(), dayOfMonth)); 1538 } 1539 1540 1551 public LocalDateTime withDayOfWeek(int dayOfWeek) { 1552 return withLocalMillis(getChronology().dayOfWeek().set(getLocalMillis(), dayOfWeek)); 1553 } 1554 1555 1567 public LocalDateTime withHourOfDay(int hour) { 1568 return withLocalMillis(getChronology().hourOfDay().set(getLocalMillis(), hour)); 1569 } 1570 1571 1582 public LocalDateTime withMinuteOfHour(int minute) { 1583 return withLocalMillis(getChronology().minuteOfHour().set(getLocalMillis(), minute)); 1584 } 1585 1586 1597 public LocalDateTime withSecondOfMinute(int second) { 1598 return withLocalMillis(getChronology().secondOfMinute().set(getLocalMillis(), second)); 1599 } 1600 1601 1612 public LocalDateTime withMillisOfSecond(int millis) { 1613 return withLocalMillis(getChronology().millisOfSecond().set(getLocalMillis(), millis)); 1614 } 1615 1616 1627 public LocalDateTime withMillisOfDay(int millis) { 1628 return withLocalMillis(getChronology().millisOfDay().set(getLocalMillis(), millis)); 1629 } 1630 1631 1637 public Property era() { 1638 return new Property(this, getChronology().era()); 1639 } 1640 1641 1646 public Property centuryOfEra() { 1647 return new Property(this, getChronology().centuryOfEra()); 1648 } 1649 1650 1655 public Property yearOfCentury() { 1656 return new Property(this, getChronology().yearOfCentury()); 1657 } 1658 1659 1664 public Property yearOfEra() { 1665 return new Property(this, getChronology().yearOfEra()); 1666 } 1667 1668 1673 public Property year() { 1674 return new Property(this, getChronology().year()); 1675 } 1676 1677 1682 public Property weekyear() { 1683 return new Property(this, getChronology().weekyear()); 1684 } 1685 1686 1691 public Property monthOfYear() { 1692 return new Property(this, getChronology().monthOfYear()); 1693 } 1694 1695 1700 public Property weekOfWeekyear() { 1701 return new Property(this, getChronology().weekOfWeekyear()); 1702 } 1703 1704 1709 public Property dayOfYear() { 1710 return new Property(this, getChronology().dayOfYear()); 1711 } 1712 1713 1718 public Property dayOfMonth() { 1719 return new Property(this, getChronology().dayOfMonth()); 1720 } 1721 1722 1727 public Property dayOfWeek() { 1728 return new Property(this, getChronology().dayOfWeek()); 1729 } 1730 1731 1737 public Property hourOfDay() { 1738 return new Property(this, getChronology().hourOfDay()); 1739 } 1740 1741 1746 public Property minuteOfHour() { 1747 return new Property(this, getChronology().minuteOfHour()); 1748 } 1749 1750 1755 public Property secondOfMinute() { 1756 return new Property(this, getChronology().secondOfMinute()); 1757 } 1758 1759 1764 public Property millisOfSecond() { 1765 return new Property(this, getChronology().millisOfSecond()); 1766 } 1767 1768 1773 public Property millisOfDay() { 1774 return new Property(this, getChronology().millisOfDay()); 1775 } 1776 1777 1783 public String toString() { 1784 return ISODateTimeFormat.dateTime().print(this); 1785 } 1786 1787 1793 public String toString(String pattern) { 1794 if (pattern == null) { 1795 return toString(); 1796 } 1797 return DateTimeFormat.forPattern(pattern).print(this); 1798 } 1799 1800 1807 public String toString(String pattern, Locale locale) throws IllegalArgumentException { 1808 if (pattern == null) { 1809 return toString(); 1810 } 1811 return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this); 1812 } 1813 1814 1843 public static final class Property extends AbstractReadableInstantFieldProperty { 1844 1845 1846 private static final long serialVersionUID = -358138762846288L; 1847 1848 1849 private transient LocalDateTime iInstant; 1850 1851 private transient DateTimeField iField; 1852 1853 1859 Property(LocalDateTime instant, DateTimeField field) { 1860 super(); 1861 iInstant = instant; 1862 iField = field; 1863 } 1864 1865 1868 private void writeObject(ObjectOutputStream oos) throws IOException { 1869 oos.writeObject(iInstant); 1870 oos.writeObject(iField.getType()); 1871 } 1872 1873 1876 private void readObject(ObjectInputStream oos) throws IOException , ClassNotFoundException { 1877 iInstant = (LocalDateTime) oos.readObject(); 1878 DateTimeFieldType type = (DateTimeFieldType) oos.readObject(); 1879 iField = type.getField(iInstant.getChronology()); 1880 } 1881 1882 1888 public DateTimeField getField() { 1889 return iField; 1890 } 1891 1892 1897 protected long getMillis() { 1898 return iInstant.getLocalMillis(); 1899 } 1900 1901 1907 protected Chronology getChronology() { 1908 return iInstant.getChronology(); 1909 } 1910 1911 1916 public LocalDateTime getLocalDateTime() { 1917 return iInstant; 1918 } 1919 1920 1930 public LocalDateTime addToCopy(int value) { 1931 return iInstant.withLocalMillis(iField.add(iInstant.getLocalMillis(), value)); 1932 } 1933 1934 1943 public LocalDateTime addToCopy(long value) { 1944 return iInstant.withLocalMillis(iField.add(iInstant.getLocalMillis(), value)); 1945 } 1946 1947 1958 public LocalDateTime addWrapFieldToCopy(int value) { 1959 return iInstant.withLocalMillis(iField.addWrapField(iInstant.getLocalMillis(), value)); 1960 } 1961 1962 1972 public LocalDateTime setCopy(int value) { 1973 return iInstant.withLocalMillis(iField.set(iInstant.getLocalMillis(), value)); 1974 } 1975 1976 1986 public LocalDateTime setCopy(String text, Locale locale) { 1987 return iInstant.withLocalMillis(iField.set(iInstant.getLocalMillis(), text, locale)); 1988 } 1989 1990 1999 public LocalDateTime setCopy(String text) { 2000 return setCopy(text, null); 2001 } 2002 2003 2018 public LocalDateTime withMaximumValue() { 2019 return setCopy(getMaximumValue()); 2020 } 2021 2022 2030 public LocalDateTime withMinimumValue() { 2031 return setCopy(getMinimumValue()); 2032 } 2033 2034 2045 public LocalDateTime roundFloorCopy() { 2046 return iInstant.withLocalMillis(iField.roundFloor(iInstant.getLocalMillis())); 2047 } 2048 2049 2059 public LocalDateTime roundCeilingCopy() { 2060 return iInstant.withLocalMillis(iField.roundCeiling(iInstant.getLocalMillis())); 2061 } 2062 2063 2069 public LocalDateTime roundHalfFloorCopy() { 2070 return iInstant.withLocalMillis(iField.roundHalfFloor(iInstant.getLocalMillis())); 2071 } 2072 2073 2079 public LocalDateTime roundHalfCeilingCopy() { 2080 return iInstant.withLocalMillis(iField.roundHalfCeiling(iInstant.getLocalMillis())); 2081 } 2082 2083 2090 public LocalDateTime roundHalfEvenCopy() { 2091 return iInstant.withLocalMillis(iField.roundHalfEven(iInstant.getLocalMillis())); 2092 } 2093 } 2094 2095} 2096 | Popular Tags |