-
Date algoritm
maybe this isn't the right forum for this, but it's my favourite forum so i decided to post here :)
I need an algoritm to express a date format stored as a 32bit integer. In fact i need to express a date according to any planet with or without at least one moon. If there's no moons, month is omited and year and day is expressed. The time for the 32 bit integer is absolute. Currently i only know how to get year:
year= Time/Sunrot;Time%=Sunrot;
day=Time/Planetrot;
here's where i get stuck, the Planet rotates absolute to Time, but since the first day has to start with the first whole day I don't know where the day changes as original Time is erased. That would be nothing compared to the next problem, how do i put in the days on leapyears and how should i put in or remove extra leapyears?
Another qwestion, is there a reason to why each month is different length (on earth)?
-
It's because the gregorian calender is screwed big time.
Actually, it wouldnt fit with only 30 day months and only 31 day months so they decided on a mixture of the two (that and 28 day months, 29 if leap year)
A year is 365.25 (approx.) days.
-
thanks, i was expecting something like that, but i still need a screwed up model of counting months, based on days, shouldn't be a problem except very annoying.
Anyway i worked out the leapyear problem by drawing some diagrams and banging my head against the wall a couple of times.
Code:
Year=Time/Sun;
X=Time%Planet; //Time Since Midnight
Day=((Time%=Sun)+Planet-X)/Planet; //Time gets relative to NewYear, Convert to day after adding the rest of the day.
if (!Day){ //Day belongs to last year
Day=Sun/Planet+((X-Time)<(Sun%Planet)); //Last day of last year + possible leapyear, which happens when the gap between
Year--; //Last day and current year is smaller than the gap between first year's last day
} //and Second year.
the whole thing got clear when i realized the first gap on a year shouldn't be smaller than the gap for the absolute year and last day. I'm still wondering if i should have Years starting at 0 or 1 since Day starts on 1.
-
BTW
How many times (exactly) does the moon rotate around earth per year? that is how long does it take for moon to make a revolution around earth. If it's not 1/12 a year then what?
In case moons don't have a tendency to make integer amount of revolutions per year (pardon my ignorance in astronomy) i'm running into another problem, should i include an option for having month relative to year as day is and then have day relative to month? (i want to be a bit realistic extrapolating alien intelligence)
-
-
Thanks, hmm 13.36 months i didn't know that :p
-
Hum, the way I'd do it would be to simply get the total number of days, and then divide it by 12 to get the number of days in each month... the number of months would be always 12 to keep it simple (dunno any other way to get another number of months :) ). You could also just make it like 30 or 31 days in a random pattern so you have 365 days at the end :)
-
Not too hard to simulate a screwed up calendar, but i'm also planning on serious ones :)