There have been periodic requests to add support for non-Gregorian dates and calendars to Drupal. (See http://drupal.org/node/242965 and http://drupal.org/node/166234, for example) I've been doing a bit of thinking about this and have concluded that it could be possible but would require a big effort. The basic approach I'm thinking of now would be to create a wrapper class for date and calendar handling that will default to use Gregorian dates but would make it possible to plug in others. We could also look at ways to use the Drupal hook system, but in this case a wrapper class might work better.
So this wiki page is a place where anyone interested can start to post ideas and code. We need:
Aspects of other calendars that might be different
- The number of days in a month
- The number of months in a year??
- The number of days in a year
- The number of days in a week??
- Day names -- can we use translation system if the number of days in a week is always 7??
- Month names -- can we use translation system if the number of months in a year is always 12??
- First day of week
- First day of year
- Uses daylight savings time?
- Has timezones and needs timezone conversions?
- Has leap year, leap month, leap day, etc.
- Date formats, alternative ways to display a given date
- Abbreviations for day and month names (hard to do with current translation system)
- Date storage -- store as timestamp? store as datetime? other? How big does the field need to be?
List of Calendars
List of some of the calendars that are important to people now using Drupal who can make some kind of contribution to this effort.
How to Integrate
My initial thought is that we have a subdirectory called "calendars" under the module's directory, with several .inc files in it, one for each type of calendar, e.g. hijri.inc, chinese.inc, ...etc. Of course, all this needs to be done for dates (list all calendars, enable selected calendards only, convert dates between calendars, ...etc.). [Kahlid - 2bits]
[sinasalek] : I'm Agree with Khalid opinion, all of the calendar systems have simple text representation which means that there shouldn't be major problem with representing date in different calendar systems, and also think that calendar module should be responsible for creating date widget for forms. storing date as SQL standard calendar (Gregorian) or as timestamp in database would be good idea for preventing incompatibility with other tools and modules.
Implementing different calendar systems in my opinion has four parts :
- Display simple
- Display advanced (generic API for other visual tools)
- Date Entry (Converting , validation , widgets, etc)
- Storing in storage (database usually)
The first three parts are not easy to implement but it can be done without too much problems. i managed to implement them partially in calendar_systems module.
But the last part is complex, it requires some serious research and thinking. Since few or no Database Engines support date calculations for non Gregorian calendar systems.
lets see few examples of this complexity:
- Explode all parts of the calendar into separate fields , to become able to do calculations.
- The first problem with this approach is it's not possible to do certain calculations only using pure math (like datediff , because each year and month have different number of days).
- The second problem is when content requires more then 2 date field. in this case we may end up with 30 or even more fields just for date.
- The third one is very long SQL queries :) even for a simple filter by date query.
- Using the advanced features like stored procedures to implement date functions for other calendar systems.
- The first problem with this approach is performance,
- The second is a separated code in database.
- The third is lack of support for advanced features on some db back-ends
There is a module started by sinasalek to accommodate different calendar systems. Check the calendar systems project. This module currently supports Gregorian and Iranian calendars for Drupal 5 and 6
Code snippets that will do conversions for various calendars
Islamic (Hijri) - http://drupal.org/node/242965
Iranian (Shamsi) - http://salek.ws/projects/drupal/datetime.class.inc.php.txt
List of popular calendar systems
According to Wikipedia (http://en.wikipedia.org/wiki/Calendar) the most popular calendar systems currently are Gregorian , Iranian (Persian) , Islamic (Arabic), Chinese, Hebrew, Hindu and Julian calendar system...
Links to resources on this subject
- A discussion with useful links - http://drupal.org/node/205500
- PHP Multi calendar systems object (Good for inspiration) - at Codeigniter
- Software implementation of almost all of the popular calendar systems (Good for demonstration and test) - at PCWorld.
- Some background informations on Calendars - at Web Exhibits
- codeigniter Calendar Module
- PHP 5 Date Handling and the Date API