traditionally when you are talking about a time stamp, you are talking about an amount of time from a given date. For example here are few of the systems currently in use.
UNIX Timestamp: seconds since Jan 1 1970 ex. Jan 1 1970 1:00am = 3600 or 60*60 (Min *Sec)
Mac Timestamp: seconds since Jan 1 1904 es Jan 1 1904 2.00am = 7200 or 120*60 ( (min*Sec)
both of thies are stright forward where the time stamp is an unsinged intenger of the number of seconds from the given date. .
here is the Mircrosoft time stamp.
Microsoft Timestamp: days since Dec 31 1899
note: mircrosoft does not use the number of seconde from the given date. Instead it it the number of days. inorder to get an acurate time they use a double pricesion float, where the mumber of days is represented by whole numbers and the time during the day is representsd the fraction of the number. so:
January 1, 1900 12:00Pm would have a time stamp of 0.5 or half after december 31 1989.
January 2, 1900 6:00Pm would have a time stamp of 1.75 or 1 and three quraters of a day after december 31 1989.
The time stamp you are devloping is doing basicly the same thing, you just have not added a way for a starting date that is higher then jan 1 year 0. but I have not really answered you question yet.
to simplify it a little lets just look at a stamp for nwn that would be the number of days and we will still use year 0 for simplisity. So we would have.
//multiplyers:
int nmlDay = 1; //there is 1 day per day.
int nmlMonth = 28; //There are 28 days per month.
int nmlyear =436 // there are 336 days per year.
// now lets create a time stamp with this without using the -1's that I included. lets take:
year 0.
month 12
day 28
Our time stamp is : 12 * 28 + 28 = 364
now lets try and get our number of years, months and days back out of the stamp.
lets see if we devide our number by the number of years we should get our year.
364 / 336 = 1 with a remainde of 28. so we have 1 year.
now if we take the remainder and devide it by the number of days per month we should get the month. with the remainder being the number of days.
28/28 = 1 remainder 0
so pulling our date back out of the stamp we get
year 1
month 1
day 0
Hmm it does really what we where looking for. The problem is that we are using a day of 1 to 28 in our equasions where 28 is also 1 month. and using 1-12 months where 12 months is also 1 year. So that is how they are returned to us. not to mention that our numbering system is somehow missing the fact that I can be one be 28 day away from my start date.
Again for simplicity lets look a a different date to find the problem. lets say:
year 0
month 1
day 1
hour 12:00pm // yea I know I gave it a time.
with the date given above what shoud our time stamp be if it is the number of days form year 0.
well it is still in the first day. If we had decimal places it would be 0.5, half a day. The fact is that on day 1 month 1 a day has not yet passed and a month surly has not yet passed. To simplify getting the same date out of a time stamp that we put into the time stamp we change the way the months and days are numbered from days: 1-28 to days 0 -27. or just day-1
and for months from 1- 12 to 0-11
notice that 1-12 and 0 -11 still has the same nunber of members in the set. { 1,2,3,4,5,6,7,8,9,10,11,12] and [0,1,2,3,4,5,6,7,8,9,10,11] both sets have 12 members. the 0-11 is the preferred usage because it is 0 based making it so the upper limit does not (11) does not get confused with a full year like the upper limit of the other set (12) would.
so lets look back at our orginal try that returned the wrong date when we tryed to convert it back from the stamp.
year 0.
month 12
day 28
if we are in month 12 , 12 months have not yet passed . 11 months have passed putting us in the 12 month.
on day 28 only 27 days have fully passed.
so we now have
(12-1) *28 + (28-1) = 335 days since year 0
ok let convert it nack to a year/ month/day
stamp / the number days in a year should give us the number of years with a remainder of days into the year.
335/ 336 = 0 remainder of 336.
ok so far so goor we get year 0.
now when we divide the 'days into the year' by the number of days in a month we should get the number of month that have passed. with a remander of days that have passed into the month.
335/28 = 11 with a remainder of 27
now that is not quite the number we started with. Just keep in mind what the 11 and 27 are. they are the munber months and days that have passed. if 11 months have already passed we are not in month 11, we are in month 12. So the month we are in will always be "the months that have passed +1" same thing with the days.
so we now have
(335/28) +1 = our month.
our day is the remainder (27 +1) = day 28.
now let me try and work in the modulo '%" operator.
the only thing the modulo does is return the remainder of the division.
so in our last division there where we had the nimber of days into the year. 335 of them
335 / 28 = 11
now if we need to find the remainder for our number of days wy can either muntiply 28 by 11 and then subtract it from our original 335
335 - (28*11) = 27
or we can just use the modulo to give us the remainder.
335 % 28 = 27
I hope that explains everything.
L8