Mayan calendar: Difference between revisions

Content deleted Content added
Alextretyak (talk | contribs)
Added 11l
PSNOW123 (talk | contribs)
New post.
Line 660: Line 660:
3 Imix’ 14 K’ayab G2
3 Imix’ 14 K’ayab G2
13.0.5.13.1</syntaxhighlight>
13.0.5.13.1</syntaxhighlight>

=={{header|Java}}==
<syntaxhighlight lang="java">
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.List;

public final class MayanCalendar {

public static void main(String[] aArgs) {
List<LocalDate> testDates = List.of( LocalDate.parse("2004-06-19"),
LocalDate.parse("2012-12-18"),
LocalDate.parse("2012-12-21"),
LocalDate.parse("2019-01-19"),
LocalDate.parse("2019-03-27"),
LocalDate.parse("2020-02-29"),
LocalDate.parse("2020-03-01"),
LocalDate.parse("2071-05-16"),
LocalDate.parse("2020-02-02") );
System.out.println("Gregorian Long Count Tzolk'in Haab' Nightlord");
System.out.println("---------------------------------------------------------------------");
for ( LocalDate date : testDates ) {
System.out.println(String.format("%-15s%-19s%-12s%-17s%s",
date.toString(), longDate(date), tzolkin(date), haab(date), nightLord(date)));
}
}
private static String nightLord(LocalDate aGregorian) {
long daysBetween = ChronoUnit.DAYS.between(CREATION_TZOLKIN, aGregorian);
long remainder = Math.floorMod(daysBetween, 9);
return "G" + ( ( remainder <= 0 ) ? remainder + 9 : remainder );
}
private static String longDate(LocalDate aGregorian) {
long daysBetween = ChronoUnit.DAYS.between(CREATION_TZOLKIN, aGregorian) + 13 * 360 * 400;
long baktun = Math.floorDiv(daysBetween, 360 * 400);
daysBetween = Math.floorMod(daysBetween, 360 * 400);
long katun = Math.floorDiv(daysBetween, 20 * 360);
daysBetween = Math.floorMod(daysBetween, 20 * 360);
long tun = Math.floorDiv(daysBetween, 360);
daysBetween = Math.floorMod(daysBetween, 360);
long winal = Math.floorDiv(daysBetween, 20);
long kin = Math.floorMod(daysBetween, 20);
StringBuilder result = new StringBuilder();
for ( long number : List.of( baktun, katun, tun, winal, kin ) ) {
String value = String.valueOf(number) + " ";
result.append( number <= 9 ? " " + value : value );
}
return result.toString();
}
private static String haab(LocalDate aGregorian) {
long daysBetween = ChronoUnit.DAYS.between(ZERO_HAAB, aGregorian);
int remainder = Math.floorMod(daysBetween, 365);
String month = Haab.get(( remainder + 1) / 20);
int dayOfMonth = remainder % 20 + 1;
return ( dayOfMonth < daysPerMayanMonth(month) ) ? dayOfMonth + " " + month : "Chum " + month;
}

private static String tzolkin(LocalDate aGregorian) {
long daysBetween = ChronoUnit.DAYS.between(CREATION_TZOLKIN, aGregorian);
int remainder = Math.floorMod(daysBetween, 13);
remainder += ( remainder <= 9 ) ? 4 : -9;
return remainder + " " + Tzolkin.get(Math.floorMod(daysBetween - 1, 20));
}
private static int daysPerMayanMonth(String aMonth) {
return ( aMonth == "Wayeb´" ) ? 5 : 20;
}
private static List<String> Tzolkin = List.of( "Imix'", "Ik'", "Ak'bal", "K'an", "Chikchan", "Kimi", "Manik'",
"Lamat", "Muluk", "Ok", "Chuwen", "Eb", "Ben", "Hix", "Men", "K'ib'", "Kaban", "Etz'nab'", "Kawak", "Ajaw" );

private static List<String> Haab = List.of( "Pop", "Wo'", "Sip", "Sotz'", "Sek", "Xul", "Yaxk'in", "Mol",
"Ch'en", "Yax", "Sak'", "Keh", "Mak", "K'ank'in", "Muwan", "Pax", "K'ayab", "Kumk'u", "Wayeb'" );
private static final LocalDate CREATION_TZOLKIN = LocalDate.parse("2012-12-21");
private static final LocalDate ZERO_HAAB = LocalDate.parse("2019-04-02");

}
</syntaxhighlight>
{{ out }}
<pre>
Gregorian Long Count Tzolk'in Haab' Nightlord
---------------------------------------------------------------------
2004-06-19 12 19 11 6 13 4 Ben 16 Sotz' G7
2012-12-18 12 19 19 17 17 1 Kaban Chum K'ank'in G6
2012-12-21 13 0 0 0 0 4 Ajaw 3 K'ank'in G9
2019-01-19 13 0 6 3 0 1 Ajaw 13 Muwan G6
2019-03-27 13 0 6 6 7 3 Manik' Chum Wayeb' G1
2020-02-29 13 0 7 5 6 4 Kimi 14 K'ayab G7
2020-03-01 13 0 7 5 7 5 Manik' 15 K'ayab G8
2071-05-16 13 2 19 4 10 1 Ok 18 Sip G9
2020-02-02 13 0 7 3 19 3 Kawak 7 Pax G7
</pre>


=={{header|Julia}}==
=={{header|Julia}}==