Last active
March 10, 2024 02:40
-
-
Save kenreilly/4a33ba7205ba33522d108d1c17a23b45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Represents a date on the MLC calendar in format x.x.x.x.x | |
class MayaLongDate { | |
// Number of days in each position | |
static const List<int> moduli = [ 144000, 7200, 360, 20, 1 ]; | |
// Nunber of ms since 12/21/2012 | |
static DateTime MLC_EPOCH_13_START = DateTime.parse('2012-12-21T00:00:00+00:00'); | |
// Current date in MLC format - initialized to Baktun 13 | |
static List<int> mlc_date = [ 13, 0, 0, 0, 0 ]; | |
// Original DateTime object | |
DateTime dt; | |
MayaLongDate(this.dt) { | |
DateTime normalized = DateTime(dt.year, dt.month, dt.day); | |
Duration diff = normalized.difference(MLC_EPOCH_13_START); | |
int days = diff.inDays; | |
for (var i = 0; i != moduli.length; ++i) { | |
if (days <= moduli[i]) continue; | |
mlc_date[i] += (days / moduli[i]).floor(); | |
days %= moduli[i]; | |
} | |
} | |
@override // Returns date in X.X.X.X.X format | |
String toString() { return mlc_date.join('.'); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment