Hi Shamim,
nice functionality (and patch) ! B-)
IMO is a good idea to move all the calendar/dates thing to one OOP like that, 100%. More with potential changes coming in Moodle 2.0 related with switching from our "custom" timezones support to the "native" one offered by PHP since some time ago. Doing that under one OOP umbrella will enable to do it easier, sure!
In the other side, I think we cannot include that in the middle of one stable release (1.9.x) because changes of functionality like that aren't normally accepted in stable versions.
So, perhaps, the way to handle this could be:
1) Keep it as a patch for Moodle 1.9.x, ppl needing it will be able to do it.
2) Apply it to HEAD (perhaps something will change in the final OOP implementation, but the goal of supporting multiple calendar systems will remain).
3) Add a new set of PHP5-time-zoned calendars as alternative to the "custom-time-zoned" ones
4) Decide if we keep both sets of calendars or we migrate to PHP5 ones or we keep using current ones.
That way we'll end in Moodle 2.0 with multiple-calendars support available and with various problems sorted in the timezones stuff out too. And, at the same time, all the date/time/calendar stuff will be OOP, allowing new calendars to come and so on...
In any case, very interesting stuff, thanks!
Ciao 
0. This SQL command should be executed first:
ALTER TABLE `mdl_user` ADD COLUMN `calendar_system` VARCHAR(20) DEFAULT NULL AFTER `lang`;
1. The calendar system directory (can be found in the attached archived file) should be copied to the Moodle root directory. In this directory there is a file named calendar_system.class.php. This file contains the definition of calendar_system_base abstract class (interface) and also a factory function named calendar_system_factory which is used to "manufacture" an instance of desired calendar system. New Calendar systems are located in a sub-directory in the mentioned directory. They have to implement the mentioned base class. I implemented and included Gregorian and Persian calendar systems.
2. In /lib/moodlelib.php:
2.1. The functions make_timestamp( ), userdate( ), and usergetdate( ) should be renamed to make_timestamp_old( ), userdate_old( ), and usergetdate_old( ) respectively. New implementations for the above functions are presented.
2.2. All calls to mktime( ) function should be replaced with $CALENDAR_SYSTEM->mktime( )
2.3. In some places the numbers 1971 and 2035 are used as the minimum and maximum year. They should be replaced with $CALENDAR_SYSTEM->get_min_year( ) and $CALENDAR_SYSTEM->get_max_year()
2.4. New implementation are presented for days_in_month( ) and dayofweek( ), dayofweek( ) functions.
3. /lib/setup.php should be slightly changed.
2.1. $CALENDAR_SYSTEM should be defined as a global object somewhere at the beginning of the file.
2.2. /calendar_system/calendar_system.class.php should be included
2.3. the following snippet should be inserted at the and of the file:
if (empty($USER->calendar_system)) { $USER->calendar_system = ''; }
$CALENDAR_SYSTEM = calendar_system_factory::factory($USER->calendar_system);
4. The following line should be added to /config.php (I do confirm that it would be nice to have a global setting in the moodle interface to change the above config through it):
$CFG->calendar_system = 'gregorian';
5. In the file /lib/weblib.php, the implementation of print_date_selector( ) should be slightly changed.
6. I stop describing changes more since they can be found in the patch file.
Here is the list of modified files:
-
- It just specifies the default calendar system. Each user can override it. **
5. In the file /lib/weblib.php, the implementation of print_date_selector( ) should be slightly changed. 6. I stop describing changes more since they can be found in the patch file. Here is the list of modified files: