Skip to content

Commit 7660023

Browse files
committed
extra javadoc-example for chinese calendar
see issue #982
1 parent 182b67f commit 7660023

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

base/src/main/java/net/time4j/calendar/ChineseCalendar.java

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* -----------------------------------------------------------------------
3-
* Copyright © 2013-2022 Meno Hochschild, <http://www.menodata.de/>
3+
* Copyright © 2013-2024 Meno Hochschild, <http://www.menodata.de/>
44
* -----------------------------------------------------------------------
55
* This file (ChineseCalendar.java) is part of project Time4J.
66
*
@@ -67,7 +67,9 @@
6767
*
6868
* <p><strong>Introduction</strong></p>
6969
*
70-
* <p>It is a lunisolar calendar which defines years consisting of 12 or 13 months. See also
70+
* <p>It is a lunisolar calendar which defines years consisting of 12 or 13 months. Modern China now uses
71+
* the gregorian calendar and uses this calendar mainly for determining the dates some festivals and the
72+
* actual cyclic year and zodiac. See also
7173
* <a href="https://en.wikipedia.org/wiki/Chinese_calendar">Wikipedia</a>. </p>
7274
*
7375
* <p><strong>Following elements which are declared as constants are registered by this class</strong></p>
@@ -135,6 +137,36 @@
135137
* formatter.format(chineseDate),
136138
* is(&quot;Sat, 16. Eleventh Month 2018(wù-xū) dōngzhì&quot;));
137139
* </pre>
140+
*
141+
* <p>Printing gregorian dates together with Chinese cyclic year and zodiac: </p>
142+
*
143+
* <pre>
144+
* ChronoPrinter&lt;PlainDate&gt; yearPrinter = // for display of cyclic year
145+
* (PlainDate gregorianDate, StringBuilder buffer, AttributeQuery attributes) -&gt; {
146+
* buffer.append(
147+
* gregorianDate.transform(ChineseCalendar.axis()).getYear().getDisplayName(Locale.TRADITIONAL_CHINESE));
148+
* return Collections.emptySet();
149+
* };
150+
*
151+
* ChronoPrinter&lt;PlainDate&gt; zodiacPrinter =
152+
* (PlainDate gregorianDate, StringBuilder buffer, AttributeQuery attributes) -&gt; {
153+
* buffer.append(gregorianDate.transform(ChineseCalendar.axis()).getYear().getZodiac(Locale.TRADITIONAL_CHINESE));
154+
* return Collections.emptySet();
155+
* };
156+
*
157+
* ChronoFormatter&lt;PlainDate&gt; gf = ChronoFormatter.setUp(PlainDate.axis(), Locale.TRADITIONAL_CHINESE)
158+
* .addPattern(&quot;y(&quot;, PatternType.CLDR)
159+
* .addCustomized(PlainDate.COMPONENT, yearPrinter, ChronoParser.unsupported())
160+
* //.startSection(Attributes.NUMBER_SYSTEM, NumberSystem.CHINESE_MANDARIN) // month and day in Chinese?
161+
* .addPattern(&quot;)年M月d日(&quot;, PatternType.CLDR)
162+
* //.endSection()
163+
* .addCustomized(PlainDate.COMPONENT, zodiacPrinter, ChronoParser.unsupported())
164+
* .addLiteral(')')
165+
* .build();
166+
*
167+
* String s = gf.print(PlainDate.of(2023, 11, 5));
168+
* System.out.println(s); // 2023(癸卯)年11月5日(兔)
169+
* </pre>
138170
*
139171
* <p>Leap months can be formatted in various ways. Following example shows how to customize numerical printing
140172
* when a non-Chinese language is used: </p>
@@ -171,7 +203,10 @@
171203
* <p><strong>Einleitung</strong></p>
172204
*
173205
* <p>Es handelt sich um einen lunisolaren Kalender, dessen Jahre aus 12 oder 13 Monaten bestehen.
174-
* Siehe auch <a href="https://en.wikipedia.org/wiki/Chinese_calendar">Wikipedia</a>. </p>
206+
* Das moderne China verwendet den gregorianischen Kalender und braucht diesen alten Bauernkalender
207+
* im wesentlichen zur zeitlichen Bestimmung einiger chinesischer Feste und des chinesischen
208+
* zyklischen Jahrs und Tierkreiszeichens (Zodiak). Siehe auch
209+
* <a href="https://en.wikipedia.org/wiki/Chinese_calendar">Wikipedia</a>. </p>
175210
*
176211
* <p><strong>Registriert sind folgende als Konstanten deklarierte Elemente</strong></p>
177212
*
@@ -241,6 +276,37 @@
241276
* is(&quot;Sat, 16. Eleventh Month 2018(wù-xū) dōngzhì&quot;));
242277
* </pre>
243278
*
279+
* <p>Darstellung eines gregorianischen Datums zusammen mit dem chinesischen
280+
* zyklischen Jahr und Tierkreiszeichen (Zodiak): </p>
281+
*
282+
* <pre>
283+
* ChronoPrinter&lt;PlainDate&gt; yearPrinter = // zur Anzeige des zyklischen Jahres
284+
* (PlainDate gregorianDate, StringBuilder buffer, AttributeQuery attributes) -&gt; {
285+
* buffer.append(
286+
* gregorianDate.transform(ChineseCalendar.axis()).getYear().getDisplayName(Locale.TRADITIONAL_CHINESE));
287+
* return Collections.emptySet();
288+
* };
289+
*
290+
* ChronoPrinter&lt;PlainDate&gt; zodiacPrinter = // Tierkreiszeichen
291+
* (PlainDate gregorianDate, StringBuilder buffer, AttributeQuery attributes) -&gt; {
292+
* buffer.append(gregorianDate.transform(ChineseCalendar.axis()).getYear().getZodiac(Locale.TRADITIONAL_CHINESE));
293+
* return Collections.emptySet();
294+
* };
295+
*
296+
* ChronoFormatter&lt;PlainDate&gt; gf = ChronoFormatter.setUp(PlainDate.axis(), Locale.TRADITIONAL_CHINESE)
297+
* .addPattern(&quot;y(&quot;, PatternType.CLDR)
298+
* .addCustomized(PlainDate.COMPONENT, yearPrinter, ChronoParser.unsupported())
299+
* //.startSection(Attributes.NUMBER_SYSTEM, NumberSystem.CHINESE_MANDARIN) // Monat und Tag auf Chinesisch?
300+
* .addPattern(&quot;)年M月d日(&quot;, PatternType.CLDR)
301+
* //.endSection()
302+
* .addCustomized(PlainDate.COMPONENT, zodiacPrinter, ChronoParser.unsupported())
303+
* .addLiteral(')')
304+
* .build();
305+
*
306+
* String s = gf.print(PlainDate.of(2023, 11, 5));
307+
* System.out.println(s); // 2023(癸卯)年11月5日(兔)
308+
* </pre>
309+
*
244310
* <p>Schaltmonate k&ouml;nnen verschieden formatiert werden. Das folgende Beispiel zeigt, wie man
245311
* die numerische Formatierung im Fall einer nicht-chinesischen Sprache anpassen kann: </p>
246312
*

0 commit comments

Comments
 (0)