示例#1
0
  public EarthTime subEarthTime(EarthTime pt) {

    // The easiest way to deal with subtraction is to work with minutes, since
    //	there wont be unit conversion issues. After converting and doing
    // 	the math, we convert back into proper clock units using our clockFriend.

    int totalMinute =
        (((this.getYears() * 365 * 24 * 60)
                + (this.getDays() * 24 * 60)
                + (this.getHours() * 60)
                + (this.getMinutes()))
            - ((pt.getYears() * 365 * 24 * 60)
                + (pt.getDays() * 24 * 60)
                + (pt.getHours() * 60)
                + (pt.getMinutes())));

    return clockFriend(totalMinute);
  }
示例#2
0
  public EarthTime addEarthTime(EarthTime pt) {

    // Adds two EarthTime objects together and adjusts for proper clock-time
    //	(i.e., clocks don't represent 61 minutes, but rather and 1 hour and 1 minute)

    int totalYears = this.getYears() + pt.getYears();
    int totalDays = this.getDays() + pt.getDays();
    int totalHours = this.getHours() + pt.getHours();
    int totalMinute = this.getMinutes() + pt.getMinutes();

    totalHours = totalHours + (totalMinute / 60);
    totalMinute = totalMinute % 60;

    totalDays = totalDays + (totalHours / 24);
    totalHours = totalHours % 24;

    totalYears = totalYears + (totalDays / 365);
    totalDays = totalDays % 365;

    EarthTime newpt = new EarthTime(totalYears, totalDays, totalHours, totalMinute);
    return newpt;
  }