So I have an assignment where I’m supposed to code a Mayan calendar in C++, in such a manner that the calendar has these functions:
argv[1] | argv[2] | argv[3] | output
m+d | Mayan date | number of days | Mayan date
m-d | Mayan date | number of days | Mayan date
m-m | Mayan date | Mayan date | number of days
g= | Gregorian date | | Mayan date
m= | Mayan date | | Gregorian date
The first operation m+d takes a Mayan date and a number of days. The
operation adds the number of days to the Mayan date to produce a Mayan
date as output. The second operation m-d subtracts the number of days
from the Mayan date to produce a Mayan date as output. The third
operation m-m calculates the number of days between two Mayan dates.
The fourth operation g= converts a Gregorian date to a Mayan date.
The final operation m= converts a Mayan date to a Gregorian date.
The mayan calendar units are set up in such a manner that:
Days Long Count period Long Count unit
1 1 Kin
20 20 Kin 1 Uinal
360 18 Uinal 1 Tun
7,200 20 Tun 1 Ka'tun
144,000 20 Ka'tun 1 Bak'tun
2,880,000 20 Bak'tun 1 Pictun
57,600,000 20 Pictun 1 Kalabtun
1,152,000,000 20 Kalabtun 1 K'inchiltun
23,040,000,000 20 K'inchiltun 1 Alautun
I’m having trouble initializing the Mayan calendar object. Here is what I have so far:
class MayanDate {
// Bak'tun, Ka'tun, etc stuff ...
unsigned int Kin = 1;
unsigned int Uinal = 20;
unsigned int Tun = 360;
unsigned int Katun = 7200;
unsigned int Baktun = 144000;
unsigned int Pictun = 2880000;
unsigned int Kalabtun = 57600000;
unsigned long Kinchiltun = 1152000000;
unsigned long Alautun = 23040000000;
public:
MayanDate();
MayanDate( unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
void set( unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
MayanDate &operator++();
int operator-( const MayanDate &) const;
MayanDate operator+( unsigned int ) const;
MayanDate operator-( unsigned int) const;
bool operator==( const MayanDate & ) const;
bool operator!=(const MayanDate & m ) const;
void get_string( char*, unsigned int) const;
};
I want to be able to set the units to equal the number of days they represent when I initialize the class, so it’ll be easier to work with them.
The code I have above isn’t compiling, and I can’t figure out why. Any pointers towards what I’m doing wrong would be extremely helpful.
I think you should hold data in your class in Mayan style. You must have an ability to convert days from start of Maya epoch to it, like that:
And back conversion is simple:
kin + 20 * (unial + 18 * (tun + 20 * (...)))Next, you should to know how calculate count of days in Gregorian calendar from some date to another. You can look at java’s Date class sources ( http://www.docjar.com/html/api/java/util/Date.java.html ) for example.
And the last – you must know any Mayan date in Gregorian form to calculate differecne in days between calendars. Convert one date to days, subtract(or add) difference and then convert to other.