-
Notifications
You must be signed in to change notification settings - Fork 62
/
EastAsianYear.java
136 lines (125 loc) · 4.97 KB
/
EastAsianYear.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* -----------------------------------------------------------------------
* Copyright © 2013-2018 Meno Hochschild, <http://www.menodata.de/>
* -----------------------------------------------------------------------
* This file (EastAsianYear.java) is part of project Time4J.
*
* Time4J is free software: You can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* Time4J is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Time4J. If not, see <http://www.gnu.org/licenses/>.
* -----------------------------------------------------------------------
*/
package net.time4j.calendar;
import net.time4j.base.MathUtils;
/**
* <p>Represents a way to specify the year used in Chinese calendar and its derivates. </p>
*
* @author Meno Hochschild
* @since 3.40/4.35
* @see CyclicYear#inQingDynasty(ChineseEra)
* @see CyclicYear#inCycle(int)
*/
/*[deutsch]
* <p>Repräsentiert einen Weg, das Jahr im chinesischen Kalender oder dessen Ableitungen anzugeben. </p>
*
* @author Meno Hochschild
* @since 3.40/4.35
* @see CyclicYear#inQingDynasty(ChineseEra)
* @see CyclicYear#inCycle(int)
*/
@FunctionalInterface
public interface EastAsianYear {
//~ Methoden ----------------------------------------------------------
/**
* <p>Determines the East Asian year corresponding to given related gregorian year. </p>
*
* @param relatedGregorianYear the gregorian calendar year which contains the first day of East Asian year
* @return EastAsianYear
*/
/*[deutsch]
* <p>Bestimmt das ostasiatische Jahr, das dem angegebenen gregorianischen Kalenderjahr entspricht, so daß
* das gregorianische Jahr den Neujahrstag des ostasiatischen Jahres enthält. </p>
*
* @param relatedGregorianYear the gregorian calendar year which contains the first day of East Asian year
* @return EastAsianYear
*/
static EastAsianYear forGregorian(int relatedGregorianYear) {
return () -> MathUtils.safeAdd(relatedGregorianYear, 2636);
}
/**
* <p>Determines the East Asian year corresponding to given minguo year
* which starts counting in gregorian year 1912 or later. </p>
*
* @param minguoYear the minguo year which contains the first day of East Asian year
* @return EastAsianYear
* @throws IllegalArgumentException if the year is smaller than 1
*/
/*[deutsch]
* <p>Bestimmt das ostasiatische Jahr, das dem angegebenen Minguo-Kalenderjahr entspricht, so daß
* das Minguo-Jahr (ab gregorianisch 1912) den Neujahrstag des ostasiatischen Jahres enthält. </p>
*
* @param relatedGregorianYear the gregorian calendar year which contains the first day of East Asian year
* @return EastAsianYear
* @throws IllegalArgumentException if the year is smaller than 1
*/
static EastAsianYear forMinguo(int minguoYear) {
if (minguoYear < 1) {
throw new IllegalArgumentException("Minguo year must not be smaller than 1: " + minguoYear);
}
return forGregorian(MathUtils.safeAdd(minguoYear, 1911));
}
/**
* <p>Determines the number of associated sexagesimal year cycle. </p>
*
* @return number of cycle
*/
/*[deutsch]
* <p>Bestimmt die Nummer des assoziierten sexagesimalen Jahreszyklus. </p>
*
* @return number of cycle
*/
default int getCycle() {
int extYear = this.getElapsedCyclicYears() + 1;
return MathUtils.floorDivide(extYear - 1, 60) + 1;
}
/**
* <p>Determines the cyclic year. </p>
*
* @return cyclic year
*/
/*[deutsch]
* <p>Bestimmt das zyklische Jahr. </p>
*
* @return cyclic year
*/
default CyclicYear getYearOfCycle() {
int extYear = this.getElapsedCyclicYears() + 1;
int yearOfCycle = MathUtils.floorModulo(extYear, 60);
if (yearOfCycle == 0) {
yearOfCycle = 60;
}
return CyclicYear.of(yearOfCycle);
}
/**
* Marks the traditional introduction date of sexagesimal cyclic years in Julian year 2637 BCE
* by the legendary yellow emperor Huang-di.
*
* @return count of sexagesimal cyclic years since Julian year 2637 BCE
*/
/*[deutsch]
* Kennzeichnet das Datum, das traditionell mit der Einführung der sexagesimalen Jahreszyklen
* durch den mythischen Kaiser Huang-di im (julianischen) Jahr 2637 BC verknüpft ist.
*
* @return count of sexagesimal cyclic years since Julian year 2637 BCE
*/
int getElapsedCyclicYears();
}