Your IP : 216.73.217.68


Current Path : /home/wuectly/www/03cbe/
Upload File :
Current File : /home/wuectly/www/03cbe/date.tar

index.html000060400000000037152456111160006537 0ustar00<!DOCTYPE html><title></title>
period.php000060400000007202152456111160006536 0ustar00<?php
/**
 *------------------------------------------------------------------------------
 *  iC Library - Library by Jooml!C, for Joomla!
 *------------------------------------------------------------------------------
 * @package     iC Library
 * @subpackage  date
 * @copyright   Copyright (c)2014-2015 Cyril Rezé, Jooml!C - All rights reserved
 *
 * @license     GNU General Public License version 3 or later; see LICENSE.txt
 * @author      Cyril Rezé (Lyr!C)
 * @link        http://www.joomlic.com
 *
 * @version     1.2.2 2015-03-06
 * @since       1.1.0
 *------------------------------------------------------------------------------
*/

// No direct access to this file
defined('_JEXEC') or die();

/**
 * class iCDate
 */
class iCDatePeriod
{
	/**
	 * Function to return all dates of a period (from ... to ...)
	 *
	 * @access	public static
	 * @param	$startdate : start datetime of the period (0000-00-00 00:00:00)
	 * 			$enddate : end datetime of the period (0000-00-00 00:00:00)
	 * 			$timezone : Time zone to be used for the date.
	 *						Special cases: boolean true for user setting, boolean false for server setting.
	 *						Default: null, no timezone.
	 * @return	array of all dates of the period
	 *
	 * @since	1.1.0
	 */
	static public function listDates($startdate, $enddate, $timezone = null)
	{
		$test_startdate	= iCDate::isDate($startdate);
		$test_enddate	= iCDate::isDate($enddate);

		$out = array();

		if ($test_startdate && $test_enddate)
		{
			$timestartdate	= date('H:i', strtotime($startdate));
			$timeenddate	= date('H:i', strtotime($enddate));

			if (class_exists('DateInterval'))
			{
				// Create array with all dates of the period - PHP 5.3+
				$start = new DateTime($startdate);

				$interval = '+1 days';
				$date_interval = DateInterval::createFromDateString($interval);

				if ($timeenddate <= $timestartdate)
				{
					$end = new DateTime("$enddate +1 days");
				}
				else
				{
					$end = new DateTime($enddate);
				}

				// Return all dates.
				$perioddates = new DatePeriod($start, $date_interval, $end);

				foreach($perioddates as $date)
				{
					$out[] = (
						$date->format('Y-m-d H:i')
					);
				}
			}
			else
			{
				// TO BE REMOVED : when Joomla 2.5 and php 5.2 support will end
				// Create array with all dates of the period - PHP 5.2
				$nodate = '0000-00-00 00:00:00';

				if (($startdate != $nodate) && ($enddate != $nodate))
				{
					$start = new DateTime($startdate);

					if ($timeenddate <= $timestartdate)
					{
						$end = new DateTime("$enddate +1 days");
					}
					else
					{
						$end = new DateTime($enddate);
					}

					while($start < $end)
					{
						$out[] = $start->format('Y-m-d H:i');
						$start->modify('+1 day');
					}
				}
			}

			return $out;
		}
		else
		{
			return array();
		}
	}

	/**
	 * Return weekdays data to array of days of the week selected
	 *
	 * @access	public static
	 * @param	$weekdays : weekdays saved in database (x,x,x)
	 * @return	array of all weekdays of the period
	 *
	 * @since	1.2.0
	 */
	static public function weekdaysToArray($i_weekdays)
	{
		$allWeekDays	= array(0,1,2,3,4,5,6);

		$weekdays		= isset($i_weekdays) ? $i_weekdays : array();
		$weekdays		= explode (',', $weekdays);

		$weekdaysarray	= array();

		foreach ($weekdays as $day)
		{
			array_push($weekdaysarray, $day);
		}

		if (in_array('', $weekdaysarray)) // Joomla 2.5 multiple select
		{
			$arrayWeekDays = $allWeekDays;
		}
		elseif ($i_weekdays)
		{
			$arrayWeekDays = $weekdaysarray;
		}
		elseif (in_array('0', $weekdaysarray)) // Sunday only selected
		{
			$arrayWeekDays = $weekdaysarray;
		}
		else
		{
			$arrayWeekDays = $allWeekDays;
		}

		return $arrayWeekDays;
	}
}
date.php000060400000004771152456111160006201 0ustar00<?php
/**
 *------------------------------------------------------------------------------
 *  iC Library - Library by Jooml!C, for Joomla!
 *------------------------------------------------------------------------------
 * @package     iC Library
 * @subpackage  date
 * @copyright   Copyright (c)2014-2015 Cyril Rezé, Jooml!C - All rights reserved
 *
 * @license     GNU General Public License version 3 or later; see LICENSE.txt
 * @author      Cyril Rezé (Lyr!C)
 * @link        http://www.joomlic.com
 *
 * @version     1.2.4 2015-05-06
 * @since       1.0.3
 *------------------------------------------------------------------------------
*/

// No direct access to this file
defined('_JEXEC') or die();

/**
 * class iCDate
 */
class iCDate
{
	/**
	 * Function to test if date is a valid Datetime
	 *
	 * @access	public static
	 * @param	$date : date to be tested (1993-04-30 14:33:00)
	 * @return	alias
	 *
	 * @since   1.1.0
	 */
	static public function isDate($date)
	{
		$stamp = strtotime($date);

		$date_numeric = iCDate::dateToNumeric($date);

		$date_valid = str_replace('0', '', $date_numeric);

		if ( ! is_numeric($stamp)
			|| ! $date_valid)
		{
			return false;
		}

		return true;
	}

	/**
	 * Function to convert datetime to numeric
	 *
	 * @access	public static
	 * @param	$date: date to convert (1993-04-30 14:33:00 -> 19930430143300)
	 * @return	alias
	 *
	 * @since   1.1.0
	 */
	static public function dateToNumeric($date)
	{
		$date = preg_replace("/[^0-9]/","", $date);

		return $date;
	}

	/**
	 * Function to convert datetime to alias
	 *
	 * @access	public static
	 * @param	$date: date to convert (1993-04-30 14:33:00 -> 1993-04-30-14-33-00)
	 * 			$format: format of the date before convertion (eg. Y-m-d if only date)
	 * 			default format: use parent format
	 * @return	alias
	 *
	 * @since   1.0.3
	 */
	static public function dateToAlias($date, $format = null)
	{
		if ($format)
		{
			$date = date($format, strtotime($date));
		}

		if (self::isDate($date))
		{
			$replace = array(' ', ':');
			$date = str_replace($replace, '-', $date);

			return $date;
		}

		return false;
	}

	/**
	 * Format Month Short Core - From Joomla language file xx-XX.ini (eg. Apr)
	 *
	 * @access	public static
	 * @param	$date: date to convert (1993-04-30 14:33:00 -> Apr)
	 * @return	translation string for MONTH_SHORT
	 *
	 * @since   1.2.0
	 */
	static public function monthShortJoomla($date)
	{
		$month				= date('F', strtotime($date));
		$monthShortJoomla	= JText::_($month . '_SHORT');

		return $monthShortJoomla;
	}
}
gregorian/date-helper.js000060400000032004152456677000011260 0ustar00!(function(Date){
	'use strict';

	/****************** Gregorian dates ********************/
	/** Constants used for time computations */
	Date.SECOND = 1000 /* milliseconds */;
	Date.MINUTE = 60 * Date.SECOND;
	Date.HOUR   = 60 * Date.MINUTE;
	Date.DAY    = 24 * Date.HOUR;
	Date.WEEK   =  7 * Date.DAY;

	/** MODIFY ONLY THE MARKED PARTS OF THE METHODS **/
	/************ START *************/
	/** INTERFACE METHODS FOR THE CALENDAR PICKER **/

	/********************** *************************/
	/**************** SETTERS ***********************/
	/********************** *************************/

	/** Sets the date for the current date without h/m/s. */
	Date.prototype.setLocalDateOnly = function (dateType, date) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			var tmp = new Date(date);
			this.setDate(1);
			this.setFullYear(tmp.getFullYear());
			this.setMonth(tmp.getMonth());
			this.setDate(tmp.getDate());
		}
	};

	/** Sets the full date for the current date. */
	Date.prototype.setLocalDate = function (dateType, d) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			return this.setDate(d);
		}
	};

	/** Sets the month for the current date. */
	Date.prototype.setLocalMonth = function (dateType, m, d) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			if (d == undefined) this.getDate();
			return this.setMonth(m);
		}
	};

	/** Sets the year for the current date. */
	Date.prototype.setOtherFullYear = function(dateType, y) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			var date = new Date(this);
			date.setFullYear(y);
			if (date.getMonth() != this.getMonth()) this.setDate(28);
			return this.setUTCFullYear(y);
		}
	};

	/** Sets the year for the current date. */
	Date.prototype.setLocalFullYear = function (dateType, y) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			var date = new Date(this);
			date.setFullYear(y);
			if (date.getMonth() != this.getMonth()) this.setDate(28);
			return this.setFullYear(y);
		}
	};

	/********************** *************************/
	/**************** GETTERS ***********************/
	/********************** *************************/

	/** The number of days per week **/
	Date.prototype.getLocalWeekDays = function (dateType, y) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return 6;
		} else {
			return 6; // 7 days per week
		}
	};

	/** Returns the year for the current date. */
	Date.prototype.getOtherFullYear = function (dateType) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			return this.getFullYear();
		}
	};

	/** Returns the year for the current date. */
	Date.prototype.getLocalFullYear = function (dateType) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			return this.getFullYear();
		}
	};

	/** Returns the month the date. */
	Date.prototype.getLocalMonth = function (dateType) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			return this.getMonth();
		}
	};

	/** Returns the date. */
	Date.prototype.getLocalDate = function (dateType) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			return this.getDate();
		}
	};

	/** Returns the number of day in the year. */
	Date.prototype.getLocalDay = function(dateType) {
		if (dateType  != 'gregorian') {
			return '';
		} else {
			return this.getDay();
		}
	};

	/** Returns the number of days in the current month */
	Date.prototype.getLocalMonthDays = function(dateType, month) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			var year = this.getFullYear();
			if (typeof month == "undefined") {
				month = this.getMonth();
			}
			if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
				return 29;
			} else {
				return [31,28,31,30,31,30,31,31,30,31,30,31][month];
			}
		}
	};

	/** Returns the week number for the current date. */
	Date.prototype.getLocalWeekNumber = function(dateType) {
		if (dateType != 'gregorian') {
			/** Modify to match the current calendar when overriding **/
			return '';
		} else {
			var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
			var DoW = d.getDay();
			d.setDate(d.getDate() - (DoW + 6) % 7 + 3);                                     // Nearest Thu
			var ms = d.valueOf();                                                           // GMT
			d.setMonth(0);
			d.setDate(4);                                                                   // Thu in Week 1
			return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
		}
	};

	/** Returns the number of day in the year. */
	Date.prototype.getLocalDayOfYear = function(dateType) {
		if (dateType  != 'gregorian') {
			return '';
		} else {
			var now = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
			var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0);
			var time = now - then;
			return Math.floor(time / Date.DAY);
		}
	};

	/** Checks date and time equality */
	Date.prototype.equalsTo = function(date) {
		return ((this.getFullYear() == date.getFullYear()) &&
		(this.getMonth() == date.getMonth()) &&
		(this.getDate() == date.getDate()) &&
		(this.getHours() == date.getHours()) &&
		(this.getMinutes() == date.getMinutes()));
	};

	/** Converts foreign date to gregorian date. */
	Date.localCalToGregorian = function(y, m, d) {
		/** Modify to match the current calendar when overriding **/
		return'';
	};

	/** Converts gregorian date to foreign date. */
	Date.gregorianToLocalCal = function(y, m, d) {
		/** Modify to match the current calendar when overriding **/
		return '';
	};

	/** INTERFACE METHODS FOR THE CALENDAR PICKER **/
	/************* END **************/

	/** Method to parse a string and return a date. **/
	Date.parseFieldDate = function(str, fmt, dateType) {
		if (dateType != 'gregorian')
			str = Date.toEnglish(str);

		var today = new Date();
		var y = 0;
		var m = -1;
		var d = 0;
		var a = str.split(/\W+/);
		var b = fmt.match(/%./g);
		var i = 0, j = 0;
		var hr = 0;
		var min = 0;
		var sec = 0;
		for (i = 0; i < a.length; ++i) {
			if (!a[i])
				continue;
			switch (b[i]) {
				case "%d":
				case "%e":
					d = parseInt(a[i], 10);
					break;

				case "%m":
					m = parseInt(a[i], 10) - 1;
					break;

				case "%Y":
				case "%y":
					y = parseInt(a[i], 10);
					(y < 100) && (y += (y > 29) ? 1900 : 2000);
					break;

				case "%b":
				case "%B":
					for (j = 0; j < 12; ++j) {
						if (JoomlaCalLocale.months[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j; break; }
					}
					break;

				case "%H":
				case "%I":
				case "%k":
				case "%l":
					hr = parseInt(a[i], 10);
					break;

				case "%P":
				case "%p":
					if (/pm/i.test(a[i]) && hr < 12)
						hr += 12;
					else if (/am/i.test(a[i]) && hr >= 12)
						hr -= 12;
					break;

				case "%M":
					min = parseInt(a[i], 10);
					break;
				case "%S":
					sec = parseInt(a[i], 10);
					break;
			}
		}
		if (isNaN(y)) y = today.getFullYear();
		if (isNaN(m)) m = today.getMonth();
		if (isNaN(d)) d = today.getDate();
		if (isNaN(hr)) hr = today.getHours();
		if (isNaN(min)) min = today.getMinutes();
		if (isNaN(sec)) sec = today.getSeconds();
		if (y != 0 && m != -1 && d != 0)
			return new Date(y, m, d, hr, min, sec);
		y = 0; m = -1; d = 0;
		for (i = 0; i < a.length; ++i) {
			if (a[i].search(/[a-zA-Z]+/) != -1) {
				var t = -1;
				for (j = 0; j < 12; ++j) {
					if (JoomlaCalLocale.months[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { t = j; break; }
				}
				if (t != -1) {
					if (m != -1) {
						d = m+1;
					}
					m = t;
				}
			} else if (parseInt(a[i], 10) <= 12 && m == -1) {
				m = a[i]-1;
			} else if (parseInt(a[i], 10) > 31 && y == 0) {
				y = parseInt(a[i], 10);
				(y < 100) && (y += (y > 29) ? 1900 : 2000);
			} else if (d == 0) {
				d = a[i];
			}
		}
		if (y == 0)
			y = today.getFullYear();
		if (m != -1 && d != 0)
			return new Date(y, m, d, hr, min, sec);
		return today;
	};

	/** Prints the date in a string according to the given format. */
	Date.prototype.print = function (str, dateType, translate) {
		/** Handle calendar type **/
		if (typeof dateType !== 'string') str = '';
		if (!dateType) dateType = 'gregorian';

		/** Handle wrong format **/
		if (typeof str !== 'string') str = '';
		if (!str) return '';

		if (this.getLocalDate(dateType) == 'NaN' || !this.getLocalDate(dateType)) return '';
		var m = this.getLocalMonth(dateType);
		var d = this.getLocalDate(dateType);
		var y = this.getLocalFullYear(dateType);
		var wn = this.getLocalWeekNumber(dateType);
		var w = this.getDay();
		var s = {};
		var hr = this.getHours();
		var pm = (hr >= 12);
		var ir = (pm) ? (hr - 12) : hr;
		var dy = this.getLocalDayOfYear(dateType);
		if (ir == 0)
			ir = 12;
		var min = this.getMinutes();
		var sec = this.getSeconds();
		s["%a"] = JoomlaCalLocale.shortDays[w];                                                     // abbreviated weekday name
		s["%A"] = JoomlaCalLocale.days[w];                                                          // full weekday name
		s["%b"] = JoomlaCalLocale.shortMonths[m];                                                   // abbreviated month name
		s["%B"] = JoomlaCalLocale.months[m];                                                        // full month name
		// FIXME: %c : preferred date and time representation for the current locale
		s["%C"] = 1 + Math.floor(y / 100);                                                          // the century number
		s["%d"] = (d < 10) ? ("0" + d) : d;                                                         // the day of the month (range 01 to 31)
		s["%e"] = d;                                                                                // the day of the month (range 1 to 31)
		// FIXME: %D : american date style: %m/%d/%y
		// FIXME: %E, %F, %G, %g, %h (man strftime)
		s["%H"] = (hr < 10) ? ("0" + hr) : hr;                                                      // hour, range 00 to 23 (24h format)
		s["%I"] = (ir < 10) ? ("0" + ir) : ir;                                                      // hour, range 01 to 12 (12h format)
		s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy;                         // day of the year (range 001 to 366)
		s["%k"] = hr;                                                                               // hour, range 0 to 23 (24h format)
		s["%l"] = ir;                                                                               // hour, range 1 to 12 (12h format)
		s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m);                                                  // month, range 01 to 12
		s["%M"] = (min < 10) ? ("0" + min) : min;                                                   // minute, range 00 to 59
		s["%n"] = "\n";                                                                             // a newline character
		s["%p"] = pm ? JoomlaCalLocale.PM : JoomlaCalLocale.AM;
		s["%P"] = pm ? JoomlaCalLocale.pm : JoomlaCalLocale.am;
		// FIXME: %r : the time in am/pm notation %I:%M:%S %p
		// FIXME: %R : the time in 24-hour notation %H:%M
		s["%s"] = Math.floor(this.getTime() / 1000);
		s["%S"] = (sec < 10) ? ("0" + sec) : sec;                                                   // seconds, range 00 to 59
		s["%t"] = "\t";                                                                             // a tab character
		// FIXME: %T : the time in 24-hour notation (%H:%M:%S)
		s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn;
		s["%u"] = w + 1;                                                                            // the day of the week (range 1 to 7, 1 = MON)
		s["%w"] = w;                                                                                // the day of the week (range 0 to 6, 0 = SUN)
		// FIXME: %x : preferred date representation for the current locale without the time
		// FIXME: %X : preferred time representation for the current locale without the date
		s["%y"] = ('' + y).substr(2, 2);                                                            // year without the century (range 00 to 99)
		s["%Y"] = y;                                                                                // year with the century
		s["%%"] = "%";                                                                              // a literal '%' character

		var re = /%./g;

		var tmpDate = str.replace(re, function (par) { return s[par] || par; });
		if (Object.prototype.toString.call(JoomlaCalLocale.localLangNumbers) === '[object Array]' && dateType != 'gregorian' && translate)
			tmpDate = Date.convertNumbers(tmpDate);

		return tmpDate;
	};
})(Date);
gregorian/date-helper.min.js000060400000011434152456677000012046 0ustar00!function(t){"use strict";t.SECOND=1e3,t.MINUTE=60*t.SECOND,t.HOUR=60*t.MINUTE,t.DAY=24*t.HOUR,t.WEEK=7*t.DAY,t.prototype.setLocalDateOnly=function(e,a){if("gregorian"!=e)return"";var r=new t(a);this.setDate(1),this.setFullYear(r.getFullYear()),this.setMonth(r.getMonth()),this.setDate(r.getDate())},t.prototype.setLocalDate=function(t,e){return"gregorian"!=t?"":this.setDate(e)},t.prototype.setLocalMonth=function(t,e,a){return"gregorian"!=t?"":(void 0==a&&this.getDate(),this.setMonth(e))},t.prototype.setOtherFullYear=function(e,a){if("gregorian"!=e)return"";var r=new t(this);return r.setFullYear(a),r.getMonth()!=this.getMonth()&&this.setDate(28),this.setUTCFullYear(a)},t.prototype.setLocalFullYear=function(e,a){if("gregorian"!=e)return"";var r=new t(this);return r.setFullYear(a),r.getMonth()!=this.getMonth()&&this.setDate(28),this.setFullYear(a)},t.prototype.getLocalWeekDays=function(t,e){return 6},t.prototype.getOtherFullYear=function(t){return"gregorian"!=t?"":this.getFullYear()},t.prototype.getLocalFullYear=function(t){return"gregorian"!=t?"":this.getFullYear()},t.prototype.getLocalMonth=function(t){return"gregorian"!=t?"":this.getMonth()},t.prototype.getLocalDate=function(t){return"gregorian"!=t?"":this.getDate()},t.prototype.getLocalDay=function(t){return"gregorian"!=t?"":this.getDay()},t.prototype.getLocalMonthDays=function(t,e){if("gregorian"!=t)return"";var a=this.getFullYear();return void 0===e&&(e=this.getMonth()),0!=a%4||0==a%100&&0!=a%400||1!=e?[31,28,31,30,31,30,31,31,30,31,30,31][e]:29},t.prototype.getLocalWeekNumber=function(e){if("gregorian"!=e)return"";var a=new t(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0),r=a.getDay();a.setDate(a.getDate()-(r+6)%7+3);var o=a.valueOf();return a.setMonth(0),a.setDate(4),Math.round((o-a.valueOf())/6048e5)+1},t.prototype.getLocalDayOfYear=function(e){if("gregorian"!=e)return"";var a=new t(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0)-new t(this.getFullYear(),0,0,0,0,0);return Math.floor(a/t.DAY)},t.prototype.equalsTo=function(t){return this.getFullYear()==t.getFullYear()&&this.getMonth()==t.getMonth()&&this.getDate()==t.getDate()&&this.getHours()==t.getHours()&&this.getMinutes()==t.getMinutes()},t.localCalToGregorian=function(t,e,a){return""},t.gregorianToLocalCal=function(t,e,a){return""},t.parseFieldDate=function(e,a,r){"gregorian"!=r&&(e=t.toEnglish(e));var o=new t,n=0,s=-1,i=0,l=e.split(/\W+/),g=a.match(/%./g),u=0,h=0,c=0,p=0,f=0;for(u=0;u<l.length;++u)if(l[u])switch(g[u]){case"%d":case"%e":i=parseInt(l[u],10);break;case"%m":s=parseInt(l[u],10)-1;break;case"%Y":case"%y":(n=parseInt(l[u],10))<100&&(n+=n>29?1900:2e3);break;case"%b":case"%B":for(h=0;h<12;++h)if(JoomlaCalLocale.months[h].substr(0,l[u].length).toLowerCase()==l[u].toLowerCase()){s=h;break}break;case"%H":case"%I":case"%k":case"%l":c=parseInt(l[u],10);break;case"%P":case"%p":/pm/i.test(l[u])&&c<12?c+=12:/am/i.test(l[u])&&c>=12&&(c-=12);break;case"%M":p=parseInt(l[u],10);break;case"%S":f=parseInt(l[u],10)}if(isNaN(n)&&(n=o.getFullYear()),isNaN(s)&&(s=o.getMonth()),isNaN(i)&&(i=o.getDate()),isNaN(c)&&(c=o.getHours()),isNaN(p)&&(p=o.getMinutes()),isNaN(f)&&(f=o.getSeconds()),0!=n&&-1!=s&&0!=i)return new t(n,s,i,c,p,f);for(n=0,s=-1,i=0,u=0;u<l.length;++u)if(-1!=l[u].search(/[a-zA-Z]+/)){var D=-1;for(h=0;h<12;++h)if(JoomlaCalLocale.months[h].substr(0,l[u].length).toLowerCase()==l[u].toLowerCase()){D=h;break}-1!=D&&(-1!=s&&(i=s+1),s=D)}else parseInt(l[u],10)<=12&&-1==s?s=l[u]-1:parseInt(l[u],10)>31&&0==n?(n=parseInt(l[u],10))<100&&(n+=n>29?1900:2e3):0==i&&(i=l[u]);return 0==n&&(n=o.getFullYear()),-1!=s&&0!=i?new t(n,s,i,c,p,f):o},t.prototype.print=function(e,a,r){if("string"!=typeof a&&(e=""),a||(a="gregorian"),"string"!=typeof e&&(e=""),!e)return"";if("NaN"==this.getLocalDate(a)||!this.getLocalDate(a))return"";var o=this.getLocalMonth(a),n=this.getLocalDate(a),s=this.getLocalFullYear(a),i=this.getLocalWeekNumber(a),l=this.getDay(),g={},u=this.getHours(),h=u>=12,c=h?u-12:u,p=this.getLocalDayOfYear(a);0==c&&(c=12);var f=this.getMinutes(),D=this.getSeconds();g["%a"]=JoomlaCalLocale.shortDays[l],g["%A"]=JoomlaCalLocale.days[l],g["%b"]=JoomlaCalLocale.shortMonths[o],g["%B"]=JoomlaCalLocale.months[o],g["%C"]=1+Math.floor(s/100),g["%d"]=n<10?"0"+n:n,g["%e"]=n,g["%H"]=u<10?"0"+u:u,g["%I"]=c<10?"0"+c:c,g["%j"]=p<100?p<10?"00"+p:"0"+p:p,g["%k"]=u,g["%l"]=c,g["%m"]=o<9?"0"+(1+o):1+o,g["%M"]=f<10?"0"+f:f,g["%n"]="\n",g["%p"]=h?JoomlaCalLocale.PM:JoomlaCalLocale.AM,g["%P"]=h?JoomlaCalLocale.pm:JoomlaCalLocale.am,g["%s"]=Math.floor(this.getTime()/1e3),g["%S"]=D<10?"0"+D:D,g["%t"]="\t",g["%U"]=g["%W"]=g["%V"]=i<10?"0"+i:i,g["%u"]=l+1,g["%w"]=l,g["%y"]=(""+s).substr(2,2),g["%Y"]=s,g["%%"]="%";var L=/%./g,M=e.replace(L,function(t){return g[t]||t});return"[object Array]"===Object.prototype.toString.call(JoomlaCalLocale.localLangNumbers)&&"gregorian"!=a&&r&&(M=t.convertNumbers(M)),M}}(Date);
jalali/date-helper.min.js000060400000022101152456677000011316 0ustar00Date.gregorian_MD=[31,28,31,30,31,30,31,31,30,31,30,31],Date.local_MD=[31,31,31,31,31,31,30,30,30,30,30,29],Date.SECOND=1e3,Date.MINUTE=60*Date.SECOND,Date.HOUR=60*Date.MINUTE,Date.DAY=24*Date.HOUR,Date.WEEK=7*Date.DAY,Date.prototype.setLocalDateOnly=function(t,e){if("gregorian"!=t)return"";var a=new Date(e);this.setDate(1),this.setFullYear(a.getFullYear()),this.setMonth(a.getMonth()),this.setDate(a.getDate())},Date.prototype.setLocalDate=function(t,e){return"gregorian"!=t?this.setJalaliDate(e):this.setDate(e)},Date.prototype.setLocalMonth=function(t,e,a){return"gregorian"!=t?this.setJalaliMonth(e,a):(null==a&&this.getDate(),this.setMonth(e))},Date.prototype.setOtherFullYear=function(t,e){var a;return"gregorian"!=t?((a=new Date(this)).setLocalFullYear(e),a.getLocalMonth("jalali")!=this.getLocalMonth("jalali")&&this.setLocalDate("jalali",29),this.setLocalFullYear("jalali",e)):((a=new Date(this)).setFullYear(e),a.getMonth()!=this.getMonth()&&this.setDate(28),this.setUTCFullYear(e))},Date.prototype.setLocalFullYear=function(t,e){if("gregorian"!=t)return this.setJalaliFullYear(e);var a=new Date(this);return a.setFullYear(e),a.getMonth()!=this.getMonth()&&this.setDate(28),this.setFullYear(e)},Date.prototype.getLocalWeekDays=function(t,e){return 6},Date.prototype.getOtherFullYear=function(t){return"gregorian"!=t?this.getJalaliFullYear():this.getFullYear()},Date.prototype.getLocalFullYear=function(t){return"gregorian"!=t?this.getJalaliFullYear():this.getFullYear()},Date.prototype.getLocalMonth=function(t){return"gregorian"!=t?this.getJalaliMonth():this.getMonth()},Date.prototype.getLocalDate=function(t){return"gregorian"!=t?this.getJalaliDate():this.getDate()},Date.prototype.getLocalDay=function(t){return"gregorian"!=t?this.getJalaliDay():this.getDay()},Date.prototype.getLocalMonthDays=function(t,e){if("gregorian"!=t){var a=this.getLocalFullYear("jalali");return void 0===e&&(e=this.getLocalMonth("jalali")),0!=a%4||0==a%100&&0!=a%400||1!=e?Date.local_MD[e]:29}a=this.getFullYear();return void 0===e&&(e=this.getMonth()),0!=a%4||0==a%100&&0!=a%400||1!=e?Date.gregorian_MD[e]:29},Date.prototype.getLocalWeekNumber=function(t){if("gregorian"!=t){var e=(r=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0)).getDay();r.setDate(r.getDate()-(e+6)%7+3);var a=r.valueOf();return r.setMonth(0),r.setDate(4),Math.round((a-r.valueOf())/6048e5)+1}var r;e=(r=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0)).getDay();r.setDate(r.getDate()-(e+6)%7+3);a=r.valueOf();return r.setMonth(0),r.setDate(4),Math.round((a-r.valueOf())/6048e5)+1},Date.prototype.getLocalDayOfYear=function(t){if("gregorian"!=t){var e=new Date(this.getOtherFullYear(t),this.getLocalMonth(t),this.getLocalDate(t),0,0,0)-new Date(this.getOtherFullYear(t),0,0,0,0,0);return Math.floor(e/Date.DAY)}e=new Date(this.getFullYear(),this.getMonth(),this.getDate(),0,0,0)-new Date(this.getFullYear(),0,0,0,0,0);return Math.floor(e/Date.DAY)},Date.prototype.getMonthDays=function(t){var e=this.getFullYear();return void 0===t&&(t=this.getMonth()),0!=e%4||0==e%100&&0!=e%400||1!=t?"gregorian"!=Date.dateType?Date.local_MD[t]:Date.gregorian_MD[t]:29},Date.prototype.equalsTo=function(t){return this.getFullYear()==t.getFullYear()&&this.getMonth()==t.getMonth()&&this.getDate()==t.getDate()&&this.getHours()==t.getHours()&&this.getMinutes()==t.getMinutes()},Date.localCalToGregorian=function(t,e,a){return JalaliDate.jalaliToGregorian(t,e,a)},Date.gregorianToLocalCal=function(t,e,a){return JalaliDate.gregorianToJalali(t,e,a)},Date.numbersToIso=function(t){var e,a=[0,1,2,3,4,5,6,7,8,9];if(t=t.toString(),"[object Array]"===Object.prototype.toString.call(JoomlaCalLocale.localLangNumbers))for(e=0;e<a.length;e++)t=t.replace(new RegExp(JoomlaCalLocale.localLangNumbers[e],"g"),a[e]);return t},Date.prototype.print=function(t,e,a){if("string"!=typeof e&&(t=""),e||(e="gregorian"),"string"!=typeof t&&(t=""),!t)return"";if("NaN"==this.getLocalDate(e)||!this.getLocalDate(e))return"";var r=this.getLocalMonth(e),o=this.getLocalDate(e),l=this.getLocalFullYear(e),n=this.getLocalWeekNumber(e),i=this.getLocalDay(e),s={},g=this.getHours(),h=g>=12,D=h?g-12:g,u=this.getLocalDayOfYear(e);0==D&&(D=12);var c=this.getMinutes(),p=this.getSeconds();s["%a"]=JoomlaCalLocale.shortDays[i],s["%A"]=JoomlaCalLocale.days[i],s["%b"]=JoomlaCalLocale.shortMonths[r],s["%B"]=JoomlaCalLocale.months[r],s["%C"]=1+Math.floor(l/100),s["%d"]=o<10?"0"+o:o,s["%e"]=o,s["%H"]=g<10?"0"+g:g,s["%I"]=D<10?"0"+D:D,s["%j"]=u<100?u<10?"00"+u:"0"+u:u,s["%k"]=g,s["%l"]=D,s["%m"]=r<9?"0"+(1+r):1+r,s["%M"]=c<10?"0"+c:c,s["%n"]="\n",s["%p"]=h?JoomlaCalLocale.PM:JoomlaCalLocale.AM,s["%P"]=h?JoomlaCalLocale.pm:JoomlaCalLocale.am,s["%s"]=Math.floor(this.getTime()/1e3),s["%S"]=p<10?"0"+p:p,s["%t"]="\t",s["%U"]=s["%W"]=s["%V"]=n<10?"0"+n:n,s["%u"]=i+1,s["%w"]=i,s["%y"]=(""+l).substr(2,2),s["%Y"]=l,s["%%"]="%";var f=t.replace(/%./g,function(t){return s[t]||t});return"[object Array]"===Object.prototype.toString.call(JoomlaCalLocale.localLangNumbers)&&a&&(f=Date.convertNumbers(f)),f},Date.parseFieldDate=function(t,e,a){t=Date.numbersToIso(t);var r=new Date,o=0,l=-1,n=0,i=t.split(/\W+/),s=e.match(/%./g),g=0,h=0,D=0,u=0;for(g=0;g<i.length;++g)if(i[g])switch(s[g]){case"%d":case"%e":n=parseInt(i[g],10);break;case"%m":l=parseInt(i[g],10)-1;break;case"%Y":case"%y":(o=parseInt(i[g],10))<100&&(o+=o>29?1900:2e3);break;case"%b":case"%B":for(h=0;h<12;++h)if("gregorian"!=a){if(JoomlaCalLocale.months[h].substr(0,i[g].length).toLowerCase()==i[g].toLowerCase()){l=h;break}}else if(JoomlaCalLocale.months[h].substr(0,i[g].length).toLowerCase()==i[g].toLowerCase()){l=h;break}break;case"%H":case"%I":case"%k":case"%l":D=parseInt(i[g],10);break;case"%P":case"%p":/pm/i.test(i[g])&&D<12?D+=12:/am/i.test(i[g])&&D>=12&&(D-=12);break;case"%M":u=parseInt(i[g],10);break;case"%S":sec=parseInt(i[g],10)}if(isNaN(o)&&(o=r.getFullYear()),isNaN(l)&&(l=r.getMonth()),isNaN(n)&&(n=r.getDate()),isNaN(D)&&(D=r.getHours()),isNaN(u)&&(u=r.getMinutes()),0!=o&&-1!=l&&0!=n)return new Date(o,l,n,D,u,0);for(o=0,l=-1,n=0,g=0;g<i.length;++g)if(-1!=i[g].search(/[a-zA-Z]+/)){var c=-1;for(h=0;h<12;++h)if("gregorian"!=a){if(JoomlaCalLocale.months[h].substr(0,i[g].length).toLowerCase()==i[g].toLowerCase()){c=h;break}}else if(JoomlaCalLocale.months[h].substr(0,i[g].length).toLowerCase()==i[g].toLowerCase()){c=h;break}-1!=c&&(-1!=l&&(n=l+1),l=c)}else parseInt(i[g],10)<=12&&-1==l?l=i[g]-1:parseInt(i[g],10)>31&&0==o?(o=parseInt(i[g],10))<100&&(o+=o>29?1900:2e3):0==n&&(n=i[g]);return 0==o&&(o=r.getFullYear()),-1!=l&&0!=n?new Date(o,l,n,D,u,0):r},JalaliDate={g_days_in_month:[31,28,31,30,31,30,31,31,30,31,30,31],j_days_in_month:[31,31,31,31,31,31,30,30,30,30,30,29]},JalaliDate.jalaliToGregorian=function(t,e,a){for(var r=(t=parseInt(t))-979,o=(e=parseInt(e))-1,l=(a=parseInt(a))-1,n=365*r+8*parseInt(r/33)+parseInt((r%33+3)/4),i=0;i<o;++i)n+=JalaliDate.j_days_in_month[i];var s=(n+=l)+79,g=1600+400*parseInt(s/146097),h=!0;(s%=146097)>=36525&&(s--,g+=100*parseInt(s/36524),(s%=36524)>=365?s++:h=!1),g+=4*parseInt(s/1461),(s%=1461)>=366&&(h=!1,s--,g+=parseInt(s/365),s%=365);for(i=0;s>=JalaliDate.g_days_in_month[i]+(1==i&&h);i++)s-=JalaliDate.g_days_in_month[i]+(1==i&&h);return[g,i+1,s+1]},JalaliDate.checkDate=function(t,e,a){return!(t<0||t>32767||e<1||e>12||a<1||a>JalaliDate.j_days_in_month[e-1]+(12==e&&!((t-979)%33%4)))},JalaliDate.gregorianToJalali=function(t,e,a){for(var r=(t=parseInt(t))-1600,o=(e=parseInt(e))-1,l=(a=parseInt(a))-1,n=365*r+parseInt((r+3)/4)-parseInt((r+99)/100)+parseInt((r+399)/400),i=0;i<o;++i)n+=JalaliDate.g_days_in_month[i];o>1&&(r%4==0&&r%100!=0||r%400==0)&&++n;var s=(n+=l)-79,g=parseInt(s/12053);s%=12053;var h=979+33*g+4*parseInt(s/1461);(s%=1461)>=366&&(h+=parseInt((s-1)/365),s=(s-1)%365);for(i=0;i<11&&s>=JalaliDate.j_days_in_month[i];++i)s-=JalaliDate.j_days_in_month[i];return[h,i+1,s+1]},Date.prototype.setJalaliFullYear=function(t,e,a){var r=this.getDate(),o=this.getMonth(),l=this.getFullYear(),n=JalaliDate.gregorianToJalali(l,o+1,r);t<100&&(t+=1300),n[0]=t,null!=e&&(e>11&&(n[0]+=Math.floor(e/12),e%=12),n[1]=e+1),null!=a&&(n[2]=a);var i=JalaliDate.jalaliToGregorian(n[0],n[1],n[2]);return this.setFullYear(i[0],i[1]-1,i[2])},Date.prototype.setJalaliMonth=function(t,e){var a=this.getDate(),r=this.getMonth(),o=this.getFullYear(),l=JalaliDate.gregorianToJalali(o,r+1,a);t>11&&(l[0]+=Math.floor(t/12),t%=12),l[1]=t+1,null!=e&&(l[2]=e);var n=JalaliDate.jalaliToGregorian(l[0],l[1],l[2]);return this.setFullYear(n[0],n[1]-1,n[2])},Date.prototype.setJalaliDate=function(t){var e=this.getDate(),a=this.getMonth(),r=this.getFullYear(),o=JalaliDate.gregorianToJalali(r,a+1,e);o[2]=t;var l=JalaliDate.jalaliToGregorian(o[0],o[1],o[2]);return this.setFullYear(l[0],l[1]-1,l[2])},Date.prototype.getJalaliFullYear=function(){var t=this.getDate(),e=this.getMonth(),a=this.getFullYear();return JalaliDate.gregorianToJalali(a,e+1,t)[0]},Date.prototype.getJalaliMonth=function(){var t=this.getDate(),e=this.getMonth(),a=this.getFullYear();return JalaliDate.gregorianToJalali(a,e+1,t)[1]-1},Date.prototype.getJalaliDate=function(){var t=this.getDate(),e=this.getMonth(),a=this.getFullYear();return JalaliDate.gregorianToJalali(a,e+1,t)[2]},Date.prototype.getJalaliDay=function(){var t=this.getDay();return t%=7};jalali/date-helper.js000060400000047103152456677000010545 0ustar00/** BEGIN: DATE OBJECT PATCHES **/
/** Adds the number of days array to the Date object. */
Date.gregorian_MD = [31,28,31,30,31,30,31,31,30,31,30,31];
Date.local_MD     = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29];

/** Constants used for time computations */
Date.SECOND = 1000 /* milliseconds */;
Date.MINUTE = 60 * Date.SECOND;
Date.HOUR   = 60 * Date.MINUTE;
Date.DAY    = 24 * Date.HOUR;
Date.WEEK   =  7 * Date.DAY;

/** MODIFY ONLY THE MARKED PARTS OF THE METHODS **/
/************ START *************/
/** INTERFACE METHODS FOR THE CALENDAR PICKER **/

/********************** *************************/
/**************** SETTERS ***********************/
/********************** *************************/

/** Sets the date for the current date without h/m/s. */
Date.prototype.setLocalDateOnly = function (dateType, date) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		return '';
	} else {
		var tmp = new Date(date);
		this.setDate(1);
		this.setFullYear(tmp.getFullYear());
		this.setMonth(tmp.getMonth());
		this.setDate(tmp.getDate());
	}
};

/** Sets the full date for the current date. */
Date.prototype.setLocalDate = function (dateType, d) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		return this.setJalaliDate(d);
	} else {
		return this.setDate(d);
	}
};

/** Sets the month for the current date. */
Date.prototype.setLocalMonth = function (dateType, m, d) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		return this.setJalaliMonth(m, d);
	} else {
		if (d == undefined) this.getDate();
		return this.setMonth(m);
	}
};

/** Sets the year for the current date. */
Date.prototype.setOtherFullYear = function(dateType, y) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		var date = new Date(this);
		date.setLocalFullYear(y);
		if (date.getLocalMonth('jalali') != this.getLocalMonth('jalali')) this.setLocalDate('jalali', 29);
		return this.setLocalFullYear('jalali', y);
	} else {
		var date = new Date(this);
		date.setFullYear(y);
		if (date.getMonth() != this.getMonth()) this.setDate(28);
		return this.setUTCFullYear(y);
	}
};

/** Sets the year for the current date. */
Date.prototype.setLocalFullYear = function (dateType, y) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		return this.setJalaliFullYear(y);
	} else {
		var date = new Date(this);
		date.setFullYear(y);
		if (date.getMonth() != this.getMonth()) this.setDate(28);
		return this.setFullYear(y);
	}
};

/********************** *************************/
/**************** GETTERS ***********************/
/********************** *************************/

/** The number of days per week **/
Date.prototype.getLocalWeekDays = function (dateType, y) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		return 6;
	} else {
		return 6; // 7 days per week
	}
};

/** Returns the year for the current date. */
Date.prototype.getOtherFullYear = function (dateType) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		return this.getJalaliFullYear();
	} else {
		return this.getFullYear();
	}
};

/** Returns the year for the current date. */
Date.prototype.getLocalFullYear = function (dateType) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		return this.getJalaliFullYear();
	} else {
		return this.getFullYear();
	}
};

/** Returns the month the date. */
Date.prototype.getLocalMonth = function (dateType) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		return this.getJalaliMonth();
	} else {
		return this.getMonth();
	}
};

/** Returns the date. */
Date.prototype.getLocalDate = function (dateType) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		return this.getJalaliDate();
	} else {
		return this.getDate();
	}
};

/** Returns the number of day in the year. */
Date.prototype.getLocalDay = function(dateType) {
	if (dateType  != 'gregorian') {
		return this.getJalaliDay();
	} else {
		return this.getDay();
	}
};

/** Returns the number of days in the current month */
Date.prototype.getLocalMonthDays = function(dateType, month) {
	if (dateType != 'gregorian') {
		/** Modify to match the current calendar when overriding **/
		var year = this.getLocalFullYear('jalali');
		if (typeof month == "undefined") {
			month = this.getLocalMonth('jalali');
		}
		if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
			return 29;
		} else {
			return Date.local_MD[month];
		}
	} else {
		var year = this.getFullYear();
		if (typeof month == "undefined") {
			month = this.getMonth();
		}
		if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
			return 29;
		} else {
			return Date.gregorian_MD[month];
		}
	}
};

/** Returns the week number for the current date. */
Date.prototype.getLocalWeekNumber = function(dateType) {
	if (dateType != 'gregorian') {
		var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
		var DoW = d.getDay();
		d.setDate(d.getDate() - (DoW + 6) % 7 + 3);                                     // Nearest Thu
		var ms = d.valueOf();                                                           // GMT
		d.setMonth(0);
		d.setDate(4);                                                                   // Thu in Week 1
		return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
	} else {
		var d = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
		var DoW = d.getDay();
		d.setDate(d.getDate() - (DoW + 6) % 7 + 3);                                     // Nearest Thu
		var ms = d.valueOf();                                                           // GMT
		d.setMonth(0);
		d.setDate(4);                                                                   // Thu in Week 1
		return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
	}
};

/** Returns the number of day in the year. */
Date.prototype.getLocalDayOfYear = function(dateType) {
	if (dateType  != 'gregorian') {
		var now = new Date(this.getOtherFullYear(dateType), this.getLocalMonth(dateType), this.getLocalDate(dateType), 0, 0, 0);
		var then = new Date(this.getOtherFullYear(dateType), 0, 0, 0, 0, 0);
		var time = now - then;
		return Math.floor(time / Date.DAY);
	} else {
		var now = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
		var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0);
		var time = now - then;
		return Math.floor(time / Date.DAY);
	}
};

/** Returns the number of days in the current month */
Date.prototype.getMonthDays = function(month) {
	var year = this.getFullYear();
	if (typeof month == "undefined") {
		month = this.getMonth();
	}
	if (((0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))) && month == 1) {
		return 29;
	} else {
		if (Date.dateType != 'gregorian') {
			return Date.local_MD[month];
		} else {
			return Date.gregorian_MD[month];
		}
	}
};

/** Checks date and time equality */
Date.prototype.equalsTo = function(date) {
	return ((this.getFullYear() == date.getFullYear()) &&
	(this.getMonth() == date.getMonth()) &&
	(this.getDate() == date.getDate()) &&
	(this.getHours() == date.getHours()) &&
	(this.getMinutes() == date.getMinutes()));
};

/** Converts foreign date to gregorian date. */
Date.localCalToGregorian = function(y, m, d) {
	/** Modify to match the current calendar when overriding **/
	return JalaliDate.jalaliToGregorian(y, m, d);
};

/** Converts gregorian date to foreign date. */
Date.gregorianToLocalCal = function(y, m, d) {
	/** Modify to match the current calendar when overriding **/
	return JalaliDate.gregorianToJalali(y, m, d);
};

/** Method to convert numbers from local symbols to English numbers. */
Date.numbersToIso = function(str) {
	var i, nums =[0,1,2,3,4,5,6,7,8,9];
	str = str.toString();

	if (Object.prototype.toString.call(JoomlaCalLocale.localLangNumbers) === '[object Array]') {
		for (i = 0; i < nums.length; i++) {
			str = str.replace(new RegExp(JoomlaCalLocale.localLangNumbers[i], 'g'), nums[i]);
		}
	}
	return str;
};
/** INTERFACE METHODS FOR THE CALENDAR PICKER **/
/************* END **************/

/** Prints the date in a string according to the given format. */
Date.prototype.print = function (str, dateType, translate) {
	/** Handle calendar type **/
	if (typeof dateType !== 'string') str = '';
	if (!dateType) dateType = 'gregorian';

	/** Handle wrong format **/
	if (typeof str !== 'string') str = '';
	if (!str) return '';


	if (this.getLocalDate(dateType) == 'NaN' || !this.getLocalDate(dateType)) return '';
	var m = this.getLocalMonth(dateType);
	var d = this.getLocalDate(dateType);
	var y = this.getLocalFullYear(dateType);
	var wn = this.getLocalWeekNumber(dateType);
	var w = this.getLocalDay(dateType);
	var s = {};
	var hr = this.getHours();
	var pm = (hr >= 12);
	var ir = (pm) ? (hr - 12) : hr;
	var dy = this.getLocalDayOfYear(dateType);
	if (ir == 0)
		ir = 12;
	var min = this.getMinutes();
	var sec = this.getSeconds();
	s["%a"] = JoomlaCalLocale.shortDays[w];                                                     // abbreviated weekday name
	s["%A"] = JoomlaCalLocale.days[w];                                                          // full weekday name
	s["%b"] = JoomlaCalLocale.shortMonths[m];                                                   // abbreviated month name
	s["%B"] = JoomlaCalLocale.months[m];                                                        // full month name
	// FIXME: %c : preferred date and time representation for the current locale
	s["%C"] = 1 + Math.floor(y / 100);                                                          // the century number
	s["%d"] = (d < 10) ? ("0" + d) : d;                                                         // the day of the month (range 01 to 31)
	s["%e"] = d;                                                                                // the day of the month (range 1 to 31)
	// FIXME: %D : american date style: %m/%d/%y
	// FIXME: %E, %F, %G, %g, %h (man strftime)
	s["%H"] = (hr < 10) ? ("0" + hr) : hr;                                                      // hour, range 00 to 23 (24h format)
	s["%I"] = (ir < 10) ? ("0" + ir) : ir;                                                      // hour, range 01 to 12 (12h format)
	s["%j"] = (dy < 100) ? ((dy < 10) ? ("00" + dy) : ("0" + dy)) : dy;                         // day of the year (range 001 to 366)
	s["%k"] = hr;                                                                               // hour, range 0 to 23 (24h format)
	s["%l"] = ir;                                                                               // hour, range 1 to 12 (12h format)
	s["%m"] = (m < 9) ? ("0" + (1+m)) : (1+m);                                                  // month, range 01 to 12
	s["%M"] = (min < 10) ? ("0" + min) : min;                                                   // minute, range 00 to 59
	s["%n"] = "\n";                                                                             // a newline character
	s["%p"] = pm ? JoomlaCalLocale.PM : JoomlaCalLocale.AM;
	s["%P"] = pm ? JoomlaCalLocale.pm : JoomlaCalLocale.am;
	// FIXME: %r : the time in am/pm notation %I:%M:%S %p
	// FIXME: %R : the time in 24-hour notation %H:%M
	s["%s"] = Math.floor(this.getTime() / 1000);
	s["%S"] = (sec < 10) ? ("0" + sec) : sec;                                                   // seconds, range 00 to 59
	s["%t"] = "\t";                                                                             // a tab character
	// FIXME: %T : the time in 24-hour notation (%H:%M:%S)
	s["%U"] = s["%W"] = s["%V"] = (wn < 10) ? ("0" + wn) : wn;
	s["%u"] = w + 1;                                                                            // the day of the week (range 1 to 7, 1 = MON)
	s["%w"] = w;                                                                                // the day of the week (range 0 to 6, 0 = SUN)
	// FIXME: %x : preferred date representation for the current locale without the time
	// FIXME: %X : preferred time representation for the current locale without the date
	s["%y"] = ('' + y).substr(2, 2);                                                            // year without the century (range 00 to 99)
	s["%Y"] = y;                                                                                // year with the century
	s["%%"] = "%";                                                                              // a literal '%' character

	var re = /%./g;

	var tmpDate = str.replace(re, function (par) { return s[par] || par; });
	if (Object.prototype.toString.call(JoomlaCalLocale.localLangNumbers) === '[object Array]' && translate)
		tmpDate = Date.convertNumbers(tmpDate);

	return tmpDate;
};

Date.parseFieldDate = function(str, fmt, dateType) {
	str = Date.numbersToIso(str);

	var today = new Date();
	var y = 0;
	var m = -1;
	var d = 0;
	var a = str.split(/\W+/);
	var b = fmt.match(/%./g);
	var i = 0, j = 0;
	var hr = 0;
	var min = 0;
	for (i = 0; i < a.length; ++i) {
		if (!a[i])
			continue;
		switch (b[i]) {
			case "%d":
			case "%e":
				d = parseInt(a[i], 10);
				break;

			case "%m":
				m = parseInt(a[i], 10) - 1;
				break;

			case "%Y":
			case "%y":
				y = parseInt(a[i], 10);
				(y < 100) && (y += (y > 29) ? 1900 : 2000);
				break;

			case "%b":
			case "%B":
				for (j = 0; j < 12; ++j) {
					if (dateType != 'gregorian') {
						if (JoomlaCalLocale.months[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j; break; }
					} else {
						if (JoomlaCalLocale.months[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { m = j; break; }
					}
				}
				break;

			case "%H":
			case "%I":
			case "%k":
			case "%l":
				hr = parseInt(a[i], 10);
				break;

			case "%P":
			case "%p":
				if (/pm/i.test(a[i]) && hr < 12)
					hr += 12;
				else if (/am/i.test(a[i]) && hr >= 12)
					hr -= 12;
				break;

			case "%M":
				min = parseInt(a[i], 10);
				break;
			case "%S":
				sec = parseInt(a[i], 10);
				break;
		}
	}
	if (isNaN(y)) y = today.getFullYear();
	if (isNaN(m)) m = today.getMonth();
	if (isNaN(d)) d = today.getDate();
	if (isNaN(hr)) hr = today.getHours();
	if (isNaN(min)) min = today.getMinutes();
	if (y != 0 && m != -1 && d != 0)
		return new Date(y, m, d, hr, min, 0);
	y = 0; m = -1; d = 0;
	for (i = 0; i < a.length; ++i) {
		if (a[i].search(/[a-zA-Z]+/) != -1) {
			var t = -1;
			for (j = 0; j < 12; ++j) {
				if (dateType != 'gregorian') {
					if (JoomlaCalLocale.months[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { t = j; break; }
				} else {
					if (JoomlaCalLocale.months[j].substr(0, a[i].length).toLowerCase() == a[i].toLowerCase()) { t = j; break; }
				}
			}
			if (t != -1) {
				if (m != -1) {
					d = m+1;
				}
				m = t;
			}
		} else if (parseInt(a[i], 10) <= 12 && m == -1) {
			m = a[i]-1;
		} else if (parseInt(a[i], 10) > 31 && y == 0) {
			y = parseInt(a[i], 10);
			(y < 100) && (y += (y > 29) ? 1900 : 2000);
		} else if (d == 0) {
			d = a[i];
		}
	}
	if (y == 0)
		y = today.getFullYear();
	if (m != -1 && d != 0)
		return new Date(y, m, d, hr, min, 0);
	return today;
};

/*
 * JalaliJSCalendar - Jalali Extension for Date Object
 * Copyright (c) 2008 Ali Farhadi (http://farhadi.ir/)
 * Released under the terms of the GNU General Public License.
 * See the GPL for details (http://www.gnu.org/licenses/gpl.html).
 *
 * Based on code from http://farsiweb.info
 */

JalaliDate = {
	g_days_in_month: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
	j_days_in_month: [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29]
};

JalaliDate.jalaliToGregorian = function(j_y, j_m, j_d)
{
	j_y = parseInt(j_y);
	j_m = parseInt(j_m);
	j_d = parseInt(j_d);
	var jy = j_y-979;
	var jm = j_m-1;
	var jd = j_d-1;

	var j_day_no = 365*jy + parseInt(jy / 33)*8 + parseInt((jy%33+3) / 4);
	for (var i=0; i < jm; ++i) j_day_no += JalaliDate.j_days_in_month[i];

	j_day_no += jd;

	var g_day_no = j_day_no+79;

	var gy = 1600 + 400 * parseInt(g_day_no / 146097); /* 146097 = 365*400 + 400/4 - 400/100 + 400/400 */
	g_day_no = g_day_no % 146097;

	var leap = true;
	if (g_day_no >= 36525) /* 36525 = 365*100 + 100/4 */
	{
		g_day_no--;
		gy += 100*parseInt(g_day_no/  36524); /* 36524 = 365*100 + 100/4 - 100/100 */
		g_day_no = g_day_no % 36524;

		if (g_day_no >= 365)
			g_day_no++;
		else
			leap = false;
	}

	gy += 4*parseInt(g_day_no/ 1461); /* 1461 = 365*4 + 4/4 */
	g_day_no %= 1461;

	if (g_day_no >= 366) {
		leap = false;

		g_day_no--;
		gy += parseInt(g_day_no/ 365);
		g_day_no = g_day_no % 365;
	}

	for (var i = 0; g_day_no >= JalaliDate.g_days_in_month[i] + (i == 1 && leap); i++)
		g_day_no -= JalaliDate.g_days_in_month[i] + (i == 1 && leap);
	var gm = i+1;
	var gd = g_day_no+1;

	return [gy, gm, gd];
};

JalaliDate.checkDate = function(j_y, j_m, j_d)
{
	return !(j_y < 0 || j_y > 32767 || j_m < 1 || j_m > 12 || j_d < 1 || j_d >
	(JalaliDate.j_days_in_month[j_m-1] + (j_m == 12 && !((j_y-979)%33%4))));
};

JalaliDate.gregorianToJalali = function(g_y, g_m, g_d)
{
	g_y = parseInt(g_y);
	g_m = parseInt(g_m);
	g_d = parseInt(g_d);
	var gy = g_y-1600;
	var gm = g_m-1;
	var gd = g_d-1;

	var g_day_no = 365*gy+parseInt((gy+3) / 4)-parseInt((gy+99)/100)+parseInt((gy+399)/400);

	for (var i=0; i < gm; ++i)
		g_day_no += JalaliDate.g_days_in_month[i];
	if (gm>1 && ((gy%4==0 && gy%100!=0) || (gy%400==0)))
	/* leap and after Feb */
		++g_day_no;
	g_day_no += gd;

	var j_day_no = g_day_no-79;

	var j_np = parseInt(j_day_no/ 12053);
	j_day_no %= 12053;

	var jy = 979+33*j_np+4*parseInt(j_day_no/1461);

	j_day_no %= 1461;

	if (j_day_no >= 366) {
		jy += parseInt((j_day_no-1)/ 365);
		j_day_no = (j_day_no-1)%365;
	}

	for (var i = 0; i < 11 && j_day_no >= JalaliDate.j_days_in_month[i]; ++i) {
		j_day_no -= JalaliDate.j_days_in_month[i];
	}
	var jm = i+1;
	var jd = j_day_no+1;


	return [jy, jm, jd];
};

Date.prototype.setJalaliFullYear = function(y, m, d) {
	var gd = this.getDate();
	var gm = this.getMonth();
	var gy = this.getFullYear();
	var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
	if (y < 100) y += 1300;
	j[0] = y;
	if (m != undefined) {
		if (m > 11) {
			j[0] += Math.floor(m / 12);
			m = m % 12;
		}
		j[1] = m + 1;
	}
	if (d != undefined) j[2] = d;
	var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
	return this.setFullYear(g[0], g[1]-1, g[2]);
};

Date.prototype.setJalaliMonth = function(m, d) {
	var gd = this.getDate();
	var gm = this.getMonth();
	var gy = this.getFullYear();
	var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
	if (m > 11) {
		j[0] += Math.floor(m / 12);
		m = m % 12;
	}
	j[1] = m+1;
	if (d != undefined) j[2] = d;
	var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
	return this.setFullYear(g[0], g[1]-1, g[2]);
};

Date.prototype.setJalaliDate = function(d) {
	var gd = this.getDate();
	var gm = this.getMonth();
	var gy = this.getFullYear();
	var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
	j[2] = d;
	var g = JalaliDate.jalaliToGregorian(j[0], j[1], j[2]);
	return this.setFullYear(g[0], g[1]-1, g[2]);
};

Date.prototype.getJalaliFullYear = function() {
	var gd = this.getDate();
	var gm = this.getMonth();
	var gy = this.getFullYear();
	var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
	return j[0];
};

Date.prototype.getJalaliMonth = function() {
	var gd = this.getDate();
	var gm = this.getMonth();
	var gy = this.getFullYear();
	var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
	return j[1]-1;
};

Date.prototype.getJalaliDate = function() {
	var gd = this.getDate();
	var gm = this.getMonth();
	var gy = this.getFullYear();
	var j = JalaliDate.gregorianToJalali(gy, gm+1, gd);
	return j[2];
};

Date.prototype.getJalaliDay = function() {
	var day = this.getDay();
	day = (day) % 7;
	return day;
};