Talk:Village/@comment-24142133-20131107184753/@comment-9531161-20131109002028

Hmm, maybe I'm just a Google master or something:

http://alcor.concordia.ca/~gpkatch/gdate-algorithm.html

http://c2.com/cgi/wiki?PerpetualCalendarAlgorithm

In that second link, just remove the last %7 and you'll get a representation of the days since year 0 (just as in the first link). However, due to the limited range of numbers in Petit Computer (and to make the GRP saving easier), I would subtract exactly 2000 from the year when computing the offset or storing the year in the GRP. For instance:

DTREAD(DATE$), YEAR, MONTH, DAY YEAR=YEAR-2000 GPSET 0,0,YEAR GPSET 1,0,MONTH GPSET 2,0,DAY

Now let's say we want to load up the date from the save file and compute the days. What we're basically going to do is convert the date in the save file into a single "Days since year 2000" variable, do the same thing for the current date, then subtract the two numbers to get the day difference. This looks like:

OLDYEAR=GSPOIT(0,0) OLDMONTH=GSPOIT(1,0) OLDDAY=GSPOIT(2,0) 'This is a variation on the first algorithm posted. 'Feel free to just copy it OLDMONTH=(OLDMONTH+9)%12 OLDYEAR=OLDYEAR-(OLDMONTH>=10) OLDDAYNUM=365*OLDYEAR + FLOOR(OLDYEAR/4) - FLOOR(OLDYEAR/100) + FLOOR((OLDMONTH*306 + 5)/10) + ( OLDDAY - 1 ) 'Now do the same thing for the current date DTREAD(DATE$), YEAR, MONTH, DAY MONTH=(MONTH+9)%12 YEAR=YEAR-(MONTH>=10) DAYNUM=365*YEAR + FLOOR(YEAR/4) - FLOOR(YEAR/100) + FLOOR((MONTH*306 + 5)/10) + ( DAY - 1 )

'Finally, just get the day difference to know how many days have passed DAYSPASSED=DAYNUM-OLDDAYNUM