question on date calcaulation

This is the development of a 2nd Edition of Enders' RATS Programming Manual.

Moderator: TomDoan

hardmann
Posts: 247
Joined: Sat Feb 26, 2011 9:49 pm

question on date calcaulation

Unread post by hardmann »

Dear Tom:

Congratulations on releasing the updated version of WinRats.
I plan to estimate the calendar effect in month series, so I deal with the variable of date. For example, numbers of days in different month for mobile holiday. Especially, the spring festive in China is mobile between January and February. In fact, I have implemented coding in Python. Then, Winrats frequently read the xlsx file containing dummy variable series generated by python. If paraments of mobile holiday changes the xlsx file changes. In other word, I want to construct the spring festive function alike %EASTER(Y). This goal, if achieved, I can flexible estimate all in WinRats. I can configure the different the paraments of mobile holiday, then can compare and select optimal paraments in Loop procedure.
Since Winrates does not have an explicit date variable, calendar (7) is used to define the starting point of the day's count. How to define date variables and calculate the difference between two date variables. I do not know date calculating in detail in Winrats. If possible, could you supply inner detail of %EASTER(Y).

Best regard
Hardmann
TomDoan
Posts: 7774
Joined: Wed Nov 01, 2006 4:36 pm

Re: question on date calcaulation

Unread post by TomDoan »

This is the C++ code for the date of Easter. There is nothing about it that couldn't be done in any programming language. (It's all integer arithmetic, so all divides are integer divides). Easter is determined by a combination of lunar (moon phase) and solar (equinox) events translated onto the secular calendar.

Code: Select all

YMDTYPE DATEINFO::
EasterDate(const YMDTYPE year)
//
//  Uses Carter's algorithm for computing the date of
//  Easter. It returns the number of days from March 23
//
{
    YMDTYPE yo,b,d,e;
    yo = (year < 100) ? year + 1900 : year;
    b  = 204 - 11 * (yo - yo/19 * 19);
    d  = b - 30 * (b / 30) + 21;
    if (d > 48) d = d - 1;
    e  = yo + yo/4 + d + 1;
    e  = e - e/7 * 7;
    return d - e - 15;
}
The %JULIAN... functions are used if you need to do "date arithmetic". %julian(2024,5,12)-%julian(1900,1,1) will give you the number of days between 1 Jan 1900 and 5 May 2024.
Post Reply