Skip to content

Commit

Permalink
sexagesimal months and days
Browse files Browse the repository at this point in the history
  • Loading branch information
MenoData committed Jul 20, 2020
1 parent 0931a13 commit b0a7050
Showing 1 changed file with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import net.time4j.PlainTime;
import net.time4j.Weekday;
import net.time4j.base.MathUtils;
import net.time4j.engine.CalendarDays;
import net.time4j.engine.CalendarSystem;
import net.time4j.engine.Calendrical;
import net.time4j.engine.ChronoElement;
import net.time4j.engine.ElementRule;
import net.time4j.engine.EpochDays;
import net.time4j.engine.IntElementRule;
import net.time4j.engine.UnitRule;
import net.time4j.format.CalendarType;
Expand Down Expand Up @@ -204,6 +206,68 @@ public int getDayOfYear() {

}

/**
* <p>Obtains the sexagesimal name of solar month component which repeats every 60th solar term. </p>
*
* @return SexagesimalName
* @see #getSolarTerm()
* @since 4.7
*/
/*[deutsch]
* <p>Liefert den sexagesimalen Namen der Sonnenmonatskomponente, der sich alle 60 Sonnenmonate wiederholt. </p>
*
* @return SexagesimalName
* @see #getSolarTerm()
* @since 4.7
*/
public SexagesimalName getSexagesimalMonth() {

SolarTerm st = this.getSolarTerm();
int solarMonth = MathUtils.floorModulo(st.getIndex() + 1, 12);
SexagesimalName.Branch branch = SexagesimalName.Branch.values()[solarMonth];
int y = EastAsianYear.forGregorian(this.get(CommonElements.RELATED_GREGORIAN_YEAR)).getElapsedCyclicYears();

if (solarMonth <= 2) {
long daxue =
SolarTerm.MINOR_11_DAXUE_255.onOrAfter(
this.minus(CalendarDays.of(this.utcDays - this.newYearUTC(0)))
).getDaysSinceEpochUTC();

if ((this.utcDays >= daxue) && (this.utcDays < this.newYearUTC(1))) {
y++;
}
}

int elapsedMonths = MathUtils.floorModulo(12 * (y - 1) + solarMonth + 2, 10);
SexagesimalName.Stem stem = SexagesimalName.Stem.values()[elapsedMonths];
return SexagesimalName.of(stem, branch);

}

/**
* <p>Obtains the sexagesimal name of day component which repeats every 60th day. </p>
*
* @return SexagesimalName
* @since 4.7
*/
/*[deutsch]
* <p>Liefert den sexagesimalen Namen der Tageskomponente, der sich alle 60 Tage wiederholt. </p>
*
* @return SexagesimalName
* @since 4.7
*/
public SexagesimalName getSexagesimalDay() {

int elapsedDays = MathUtils.floorModulo(EpochDays.RATA_DIE.transform(this.utcDays, EpochDays.UTC) - 45, 60);

if (elapsedDays == 0) {
elapsedDays = 60;
}

return SexagesimalName.of(elapsedDays);

}

/**
* <p>Is the year of this date a leap year such that it contains a leap month? </p>
*
Expand Down Expand Up @@ -424,6 +488,10 @@ int getLeapMonth() {
// needs to be overridden due to calendar specific zone offsets and epochs
abstract EastAsianCS<D> getCalendarSystem();

private long newYearUTC(int delta) {
return this.getCalendarSystem().newYear(this.cycle, this.yearOfCycle + delta);
}

//~ Innere Klassen ----------------------------------------------------

private static class IntegerElementRule<D extends EastAsianCalendar<?, D>>
Expand Down

0 comments on commit b0a7050

Please sign in to comment.