content: package com.tyme.jd;
  
  import com.tyme.AbstractTyme;
  import com.tyme.culture.Week;
  import com.tyme.solar.SolarTime;
  import com.tyme.solar.SolarDay;
  
  /**
   * 儒略日
   *
   * @author 6tail
   */
  public class JulianDay extends AbstractTyme {
  
    /**
     * 2000年儒略日数(2000-1-1 12:00:00 UTC)
     */
    public static final double J2000 = 2451545;
  
    /**
     * 儒略日
     */
    protected double day;
  
    public JulianDay(double day) {
      this.day = day;
    }
  
    public static JulianDay fromJulianDay(double day) {
      return new JulianDay(day);
    }
  
    public static JulianDay fromYmdHms(int year, int month, int day, int hour, int minute, int second) {
      double d = day + ((second * 1D / 60 + minute) / 60 + hour) / 24;
      int n = 0;
      boolean g = year * 372 + month * 31 + (int) d >= 588829;
      if (month <= 2) {
        month += 12;
        year--;
      }
      if (g) {
        n = (int) (year * 0.01);
        n = 2 - n + (int) (n * 0.25);
      }
      return fromJulianDay((int) (365.25 * (year + 4716)) + (int) (30.6001 * (month + 1)) + d + n - 1524.5);
    }
  
    /**
     * 儒略日
     *
     * @return 儒略日
     */
    public double getDay() {
      return day;
    }
  
    public String getName() {
      return day + "";
    }
  
    public JulianDay next(int n) {
      return fromJulianDay(day + n);
    }
  
    /**
     * 公历日
     *
     * @return 公历日
     */
    public SolarDay getSolarDay() {
      return getSolarTime().getSolarDay();
    }
  
    /**
     * 公历时刻
     *
     * @return 公历时刻
     */
    public SolarTime getSolarTime() {
      int d = (int) (day + 0.5);
      double f = day + 0.5 - d;
  
      if (d >= 2299161) {
        int c = (int) ((d - 1867216.25) / 36524.25);
        d += 1 + c - (int) (c * 0.25);
      }
      d += 1524;
      int y = (int) ((d - 122.1) / 365.25);
      d -= (int) (365.25 * y);
      int m = (int) (d / 30.601);
      d -= (int) (30.601 * m);
      if (m > 13) {
        m -= 12;
      } else {
        y -= 1;
      }
      m -= 1;
      y -= 4715;
      f *= 24;
      int hour = (int) f;
  
      f -= hour;
      f *= 60;
      int minute = (int) f;
  
      f -= minute;
      f *= 60;
      int second = (int) Math.round(f);
      return second < 60 ? SolarTime.fromYmdHms(y, m, d, hour, minute, second) : SolarTime.fromYmdHms(y, m, d, hour, minute, second - 60).next(60);
    }
  
    /**
     * 星期
     *
     * @return 星期
     */
    public Week getWeek() {
      return Week.fromIndex((int) (day + 0.5) + 7000001);
    }
  
    /**
     * 儒略日相减
     *
     * @param target 儒略日
     * @return 差
     */
    public double subtract(JulianDay target) {
      return day - target.getDay();
    }
  }
  