1846 long y = year; 1847 long m = month; 1848 long total = 0; 1849 total += 365 * y; 1850 if (y >= 0) { 1851 total += (y + 3) / 4 - (y + 99) / 100 + (y + 399) / 400; 1852 } else { 1853 total -= y / -4 - y / -100 + y / -400; 1854 } 1855 total += ((367 * m - 362) / 12); 1856 total += day - 1; 1857 if (m > 2) { 1858 total--; 1859 if (isLeapYear() == false) { 1860 total--; 1861 } 1862 } 1863 return total - DAYS_0000_TO_1970; 1864 } 1865 1866 //----------------------------------------------------------------------- 1867 /** 1868 * Compares this date to another date. 1869 * <p> 1870 * The comparison is primarily based on the date, from earliest to latest. 1871 * It is "consistent with equals", as defined by {@link Comparable}. 1872 * <p> 1873 * If all the dates being compared are instances of {@code LocalDate}, 1874 * then the comparison will be entirely based on the date. 1875 * If some dates being compared are in different chronologies, then the 1876 * chronology is also considered, see {@link java.time.chrono.ChronoLocalDate#compareTo}. 1877 * 1878 * @param other the other date to compare to, not null 1879 * @return the comparator value, negative if less, positive if greater 1880 */ 1881 @Override // override for Javadoc and performance 1882 public int compareTo(ChronoLocalDate other) { 1883 if (other instanceof LocalDate) { 1884 return compareTo0((LocalDate) other); 1885 } | 1846 long y = year; 1847 long m = month; 1848 long total = 0; 1849 total += 365 * y; 1850 if (y >= 0) { 1851 total += (y + 3) / 4 - (y + 99) / 100 + (y + 399) / 400; 1852 } else { 1853 total -= y / -4 - y / -100 + y / -400; 1854 } 1855 total += ((367 * m - 362) / 12); 1856 total += day - 1; 1857 if (m > 2) { 1858 total--; 1859 if (isLeapYear() == false) { 1860 total--; 1861 } 1862 } 1863 return total - DAYS_0000_TO_1970; 1864 } 1865 1866 /** 1867 * Converts this {@code LocalDate} to the number of seconds since the epoch 1868 * of 1970-01-01T00:00:00Z. 1869 * <p> 1870 * This returns the number of seconds from the epoch for this {@link LocalDate}. 1871 * 1872 * @param offset the zone offset, not null 1873 * @return the number of seconds since the epoch of 1970-01-01T00:00:00Z, may be negative 1874 */ 1875 public long toEpochSecond(ZoneOffset offset) { 1876 Objects.requireNonNull(offset, "offset"); 1877 long secs = toEpochDay() * SECONDS_PER_DAY; 1878 secs -= offset.getTotalSeconds(); 1879 return secs; 1880 } 1881 1882 //----------------------------------------------------------------------- 1883 /** 1884 * Compares this date to another date. 1885 * <p> 1886 * The comparison is primarily based on the date, from earliest to latest. 1887 * It is "consistent with equals", as defined by {@link Comparable}. 1888 * <p> 1889 * If all the dates being compared are instances of {@code LocalDate}, 1890 * then the comparison will be entirely based on the date. 1891 * If some dates being compared are in different chronologies, then the 1892 * chronology is also considered, see {@link java.time.chrono.ChronoLocalDate#compareTo}. 1893 * 1894 * @param other the other date to compare to, not null 1895 * @return the comparator value, negative if less, positive if greater 1896 */ 1897 @Override // override for Javadoc and performance 1898 public int compareTo(ChronoLocalDate other) { 1899 if (other instanceof LocalDate) { 1900 return compareTo0((LocalDate) other); 1901 } |