Mayan calendar: Difference between revisions
Content added Content deleted
m (Minor code improvements.) |
m (Minor alteration to coding.) |
||
Line 310: | Line 310: | ||
const std::vector<std::string> Haab = { "Pop", "Wo'", "Sip", "Sotz'", "Sek", "Xul", "Yaxk'in", "Mol", |
const std::vector<std::string> Haab = { "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'" }; |
"Ch'en", "Yax", "Sak'", "Keh", "Mak", "K'ank'in", "Muwan", "Pax", "K'ayab", "Kumk'u", "Wayeb'" }; |
||
int32_t positive_modulus(const int32_t& base, const int32_t& modulus) { |
|||
const int32_t result = base % modulus; |
|||
return ( result < 0 ) ? result + modulus : result; |
|||
⚫ | |||
std::chrono::sys_days create_date(const std::string& iso_date) { |
std::chrono::sys_days create_date(const std::string& iso_date) { |
||
Line 329: | Line 335: | ||
std::string tzolkin(const std::chrono::sys_days& gregorian) { |
std::string tzolkin(const std::chrono::sys_days& gregorian) { |
||
const int32_t days_between = ( gregorian - CREATION_TZOLKIN ).count(); |
const int32_t days_between = ( gregorian - CREATION_TZOLKIN ).count(); |
||
int32_t remainder = days_between |
int32_t remainder = positive_modulus(days_between, 13); |
||
remainder += ( remainder <= 9 ) ? 4 : -9; |
remainder += ( remainder <= 9 ) ? 4 : -9; |
||
return std::to_string(remainder) + " " + Tzolkin[positive_modulus(days_between - 1, 20)]; |
|||
if ( index < 0 ) { |
|||
index += 20; |
|||
⚫ | |||
return std::to_string(remainder) + " " + Tzolkin[index]; |
|||
} |
} |
||
std::string haab(const std::chrono::sys_days& gregorian) { |
std::string haab(const std::chrono::sys_days& gregorian) { |
||
const int32_t days_between = ( gregorian - ZERO_HAAB ).count(); |
const int32_t days_between = ( gregorian - ZERO_HAAB ).count(); |
||
int32_t remainder = days_between |
int32_t remainder = positive_modulus(days_between, 365); |
||
const std::string month = Haab[positive_modulus(remainder + 1, 20)]; |
|||
remainder += 365; |
|||
} |
|||
const std::string month = Haab[ ( remainder + 1 ) / 20 ]; |
|||
const int32_t day_of_month = remainder % 20 + 1; |
const int32_t day_of_month = remainder % 20 + 1; |
||
return ( day_of_month < days_per_mayan_month(month) ) ? |
return ( day_of_month < days_per_mayan_month(month) ) ? |
||
Line 352: | Line 351: | ||
std::string long_count(const std::chrono::sys_days& gregorian) { |
std::string long_count(const std::chrono::sys_days& gregorian) { |
||
int32_t days_between = ( gregorian - CREATION_TZOLKIN ).count() + 13 * 360 * 400; |
int32_t days_between = ( gregorian - CREATION_TZOLKIN ).count() + 13 * 360 * 400; |
||
const int32_t baktun = days_between |
const int32_t baktun = positive_modulus(days_between, 360 * 400); |
||
days_between = days_between % ( 360 * 400 ); |
days_between = days_between % ( 360 * 400 ); |
||
const int32_t katun = days_between / ( 20 * 360 ); |
const int32_t katun = days_between / ( 20 * 360 ); |