PlanetSquires Forums

Support Forums => General Board => Topic started by: Richard Kelly on January 17, 2011, 09:16:58 AM

Title: Date Calculations
Post by: Richard Kelly on January 17, 2011, 09:16:58 AM
Recently, I pulled together the Gregorian/Julian/Easter date routines I use most frequently into one include file for my FF projects. Although I have code for other calendars such as Coptic, Ethiopic, ISO, Hebrew, Hindu, Mayan, Balinese Pawukon, Persian, Bahai, French Revolutionary, Chinese (with Vietnamese, Korean, Japanese variants) and Tibetan, I left these out to keep code bloat out of my projects although with PB10 that may not be an issue. The basic calendrical unit is an integer representing the number of days since Jan 1, 1 which is day 1 and a Monday and calculations are done within this unit. There are rules based routines to handle holidays and other non-business days with supporting calculation routines for Gregorian and Christian/Orthodox Easter.

I've worked diligently to validate everything, and if a problem is found, please post back here for everybody's benefit.

Enjoy!

Rick
Title: Re: Date Calculations
Post by: Richard Kelly on January 24, 2011, 12:49:59 AM
Chinese and Persian calendars added. Now that we have some basic astronomical routines that are required for the Chinese calendar, we also have some derivative functions such as sunrise, sunset and lunar phases and illumination. All calendars added are supported when it comes to performing date calculations related to business days calculations. I think it might be time to move on to some real work.... ;)

The astronomical version of the Persian calendar is what I used. When this calendar was adopted in 1925, the authorities at that time claimed that the year begins on the day when the vernal equinox (Spring..around March 20th) occurs before true Noon (midday) in Tehran and is postponed to the next day if the equinox is on or after true noon. There are purely arithmatical versions and when comparing the two for Gregorian years 1637 - 2417 there are 28 years where there is a disagreement. However, the two are in agreement for the Gregorian years 1865 - 2024. This is mainly due to the Persian calendar using 365.24242424242 as their approximation for the mean tropical year vs 365.2425 for the Gregorian and the author of Astronomical Algorithms Jean Meeus provides 365.2421896698 as a base.

Afghanistan adopted the Persian calendar in 1957 with different month names.
Title: Re: Date Calculations
Post by: Richard Kelly on January 26, 2011, 04:52:28 AM
Hindu Solar and Hindu Lunar calendars added. For the curious few, we are now in the world where a calendar can have missing months and missing days within months. Expunged is the word I've seen used.

Now the struggle begins with the Islamic calendar. While I have the routines that do a good job of calculating when there is a crescent moon, crescent moon sightings also depend of all kinds of atmospheric conditions that are both unpredictable and virtually impossible to express algorithmically. It means that a date I've calculated will, on occasion, be off by one day from official sightings. I've also read some papers outlining a global Islamic calendar. The major premise is that a new moon calculated on the international date line at UTC time, if it occurs before noon, that a crescent moon must be viewable somewhere in the world during the day. I guess I'll whip up the global version and then check it against the past 20 years and see how I do.

This really is a fun little project for me... 8)

Rick

Any Islamic scholars out there with advice?
Title: Re: Date Calculations
Post by: Rolf Brandt on January 26, 2011, 06:30:45 AM
Quite an extensive project.

Would you in time also provide a litte example program to show the use of these routines, what you can accomplish with them?
Title: Re: Date Calculations
Post by: Richard Kelly on January 26, 2011, 07:29:42 AM
I'm putting together a FF3 demo project with a SQLITE3 database. The main form is a listview of what definitions are in the database with a details form and a wizard for adding new stuff. It's only time... :o
Title: Re: Date Calculations
Post by: Rolf Brandt on January 26, 2011, 07:30:38 AM
Great - I am looking forward to it.
Title: Re: Date Calculations
Post by: Richard Kelly on January 27, 2011, 07:26:14 AM
Islamic calendar added. I use the global concept as outlined at:

http://moonsighting.com/calendar.html (http://moonsighting.com/calendar.html)

The results seem reasonable, at least as good as doing all the extra work to calculate a time for a crescent moon for some locale. Time to move on and whip up a demo to show what you can do with all this. ;D
Title: Re: Date Calculations
Post by: Richard Kelly on January 31, 2011, 12:09:48 AM
While I was pulling the pieces together for a demo, I noticed that I had all the supporting routines for moonrise/set...so I added that capability as well.
Title: Re: Date Calculations
Post by: Richard Kelly on February 03, 2011, 04:50:36 AM
Here is a quick FF3 demo for date and time calculations. Functional but not bullet proof and pretty... ::)

P.S. I didn't have time to do a SQLITE3 version Rolf... :P
Title: Re: Date Calculations
Post by: Rolf Brandt on February 03, 2011, 06:39:03 AM
Very impressive demo...
Title: Re: Date Calculations
Post by: Richard Kelly on February 04, 2011, 12:56:50 AM
Thank you for your kind words Rolf. Some other function/subs that I have yet to build into this are:

Get days remaining in Fiscal Gregorian year

Calculate the Gregorian ordinal day of the fiscal year (1-365 or 366 if a fiscal leap year)

Given a calendar month, return the fiscal month

Given a calendar month, return the fiscal quarter it belongs to

Given a month and year, return the fiscal year

A whole series of function/subs that handle calculations/maintenance for 13 month rolling histories

...and the usual bevy of other calendars. I'm also in the middle of building Olson Timezone support into the middle of things and crafting a date calc holiday wizard that will walk you through the maze of options possible. I know this collection is not an easy one for everyone to follow. I have the advantage of experimenting with date/time things for over 30 years now and I'm sure there is much more to learn. If only one person uses any of this, I will be be satisfied and perhaps some things can be found useful for FF4 and give it and us some competitive advantages.

Rick
Title: Re: Date Calculations
Post by: Richard Kelly on February 08, 2011, 04:31:33 AM
Fiscal period routines added

Rolling 13 month history summary routines added

Coptic/Ethiopic calendars added

Month/Weekday names from windows locale added

Support for Unix/Excel timestamps added.

Previous message attachments updated.


Rick