DateTime::__construct() error by set an even in calendar

Talk about anything that doesn't fit in the other catagories :) (and of course is about Group-Office)

Moderator: Developers

admin12345
Posts: 43
Joined: Sat Feb 04, 2012 9:07 am

DateTime::__construct() error by set an even in calendar

Postby admin12345 » Wed Apr 18, 2012 4:26 am

Hi
I wanted to change gregurian calendar to persian calendar in group office, every things were ok but when I wanted to set an event after press "ok" button in appointments box this error
displayed for me:

DateTime::__construct(): Failed to parse time string (@) at position 0 (@): Unexpected character

Can any one solve it?

thanks.
mschering
Site Admin
Site Admin
Posts: 8333
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: DateTime::__construct() error by set an even in calenda

Postby mschering » Wed Apr 25, 2012 7:13 am

How do you change it to persian?
Best regards,

Merijn Schering
Intermesh
admin12345
Posts: 43
Joined: Sat Feb 04, 2012 9:07 am

Re: DateTime::__construct() error by set an even in calenda

Postby admin12345 » Wed Apr 25, 2012 2:33 pm

Hi

for changing to persian I added some .js code, I put them in a folder in my root folder and call them (include them) in default.script.inc.php ,
just this.

my js codes are:
------------------------------------------------------------------------------------------------------
1-Jalali.js

/* Jalali.js Gregorian to Jalali and inverse date converter
* Copyright (C) 2001 Roozbeh Pournader <roozbeh@sharif.edu>
* Copyright (C) 2001 Mohammad Toossi <mohammad@bamdad.org>
* Copyright (C) 2003,2008 Behdad Esfahbod <js@behdad.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You can receive a copy of GNU Lesser General Public License at the
* World Wide Web address <http://www.gnu.org/licenses/lgpl.html>.
*
* For licensing issues, contact The FarsiWeb Project Group,
* Computing Center, Sharif University of Technology,
* PO Box 11365-8515, Tehran, Iran, or contact us the
* email address <FWPG@sharif.edu>.
*/

/* Changes:
* 2010-Sep-19:
* Some minor changes to names of functions for better naming conventions.
* Also redundant functions removed to prevent namespace pollution.
*
* 2008-Jul-32:
* Use a remainder() function to fix conversion of ancient dates
* (before 1600 gregorian). Reported by Shamim Rezaei.
*
* 2003-Mar-29:
* Ported to javascript by Behdad Esfahbod
*
* 2001-Sep-21:
* Fixed a bug with "30 Esfand" dates, reported by Mahmoud Ghandi
*
* 2001-Sep-20:
* First LGPL release, with both sides of conversions
*/

Date.jalaliConverter = {};

Date.jalaliConverter.gregorianDaysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
Date.jalaliConverter.jalaliDaysInMonth = new Array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);

Date.jalaliConverter.div = function (a, b) {
return Math.floor(a / b);
};

Date.jalaliConverter.remainder = function (a, b) {
return a - Math.floor(a / b) * b;
};

/**
* Converts a Gregorian date to Jalali.
* @param {Array} g An array containing Gregorian year, month and date.
* @return {Array} An array containing Jalali year, month and date.
*/
Date.jalaliConverter.gregorianToJalali = function (g) {
var gy, gm, gd;
var jy, jm, jd;
var g_day_no, j_day_no;
var j_np;

var i;

gy = g[0] - 1600;
gm = g[1] - 1;
gd = g[2] - 1;

var div = Date.jalaliConverter.div;
var remainder = Date.jalaliConverter.remainder;
var g_days_in_month = Date.jalaliConverter.gregorianDaysInMonth;
var j_days_in_month = Date.jalaliConverter.jalaliDaysInMonth;

g_day_no = 365 * gy + div((gy + 3), 4) - div((gy + 99), 100) + div((gy + 399), 400);
for (i = 0; i < gm; ++i)
g_day_no += g_days_in_month;
if (gm > 1 && ((gy % 4 == 0 && gy % 100 != 0) || (gy % 400 == 0)))
/* leap and after Feb */
++g_day_no;
g_day_no += gd;

j_day_no = g_day_no - 79;

j_np = div(j_day_no, 12053);
j_day_no = remainder(j_day_no, 12053);

jy = 979 + 33 * j_np + 4 * div(j_day_no, 1461);
j_day_no = remainder(j_day_no, 1461);

if (j_day_no >= 366) {
jy += div((j_day_no - 1), 365);
j_day_no = remainder((j_day_no - 1), 365);
}

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

return new Array(jy, jm, jd);
};

/**
* Converts a Jalali date to Gregorian.
* @param {Array} j An array containing Jalali year, month and date.
* @return {Array} An array containing Gregorian year, month and date.
*/
Date.jalaliConverter.jalaliToGregorian = function (j) {
var gy, gm, gd;
var jy, jm, jd;
var g_day_no, j_day_no;
var leap;

var i;

jy = j[0] - 979;
jm = j[1] - 1;
jd = j[2] - 1;

var div = Date.jalaliConverter.div;
var remainder = Date.jalaliConverter.remainder;
var g_days_in_month = Date.jalaliConverter.gregorianDaysInMonth;
var j_days_in_month = Date.jalaliConverter.jalaliDaysInMonth;

j_day_no = 365 * jy + div(jy, 33) * 8 + div((remainder(jy, 33) + 3), 4);
for (i = 0; i < jm; ++i)
j_day_no += j_days_in_month;

j_day_no += jd;

g_day_no = j_day_no + 79;

gy = 1600 + 400 * div(g_day_no, 146097);
/* 146097 = 365*400 + 400/4 - 400/100 + 400/400 */
g_day_no = remainder(g_day_no, 146097);

leap = 1;
if (g_day_no >= 36525) /* 36525 = 365*100 + 100/4 */
{
g_day_no--;
gy += 100 * div(g_day_no, 36524);
/* 36524 = 365*100 + 100/4 - 100/100 */
g_day_no = remainder(g_day_no, 36524);

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

gy += 4 * div(g_day_no, 1461);
/* 1461 = 365*4 + 4/4 */
g_day_no = remainder(g_day_no, 1461);

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

g_day_no--;
gy += div(g_day_no, 365);
g_day_no = remainder(g_day_no, 365);
}

for (i = 0; g_day_no >= g_days_in_month + (i == 1 && leap); i++)
g_day_no -= g_days_in_month + (i == 1 && leap);
gm = i + 1;
gd = g_day_no + 1;

return new Array(gy, gm, gd);
};

------------------------------------------------------------------------------------------------------------------------------
2-JalaliDate.js

/*
* Copyright (c) 2010 Tosan, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/**
* Instruments Date object and adds support for Jalali calendar to it.
*
* <p>Usage is very simple. Any date object is also a Jalali date. Examples:
* <pre><code>
var date;
date = new Date();
console.log(date.getJalaliFullYear()); // current year in Jalali calendar
console.log(date.getJalaliMonth()); // current month in Jalali calendar (0-based)
console.log(date.getJalaliDate()); // current date in Jalali calendar
console.log(date.isJalaliLeapYear()); // true if this is a leap year in Jalali calendar
console.log(date.addJalali(Date.MONTH, -3).format('Jalali')); // subtracts a month in Jalali calendar
console.log(date.getJalaliDaysInMonth()); // count of days in current Jalali month
console.log(date.getJalaliFirstDateOfMonth()); // date of the first day of current month in Jalali calendar
* </code></pre>
* There are some useful methods. Be sure to read the documentation.
*
* <p>Gregorian to Jalali conversion is based on algorithm provided by farsiweb.info
* (see http://www.farsiweb.info/jalali/jalali.js).
*
* @author Behrang Noroozinia
*/
Ext.apply(Date, {

/**
* Validates a Jalali date.
* @param y Year value.
* @param m Month value, 1-based.
* @param d Date value.
* @return {Boolean} True if valid, false otherwise.
*/
isJalaliValid: function (y, m, d) {
if (y > 1500 || y < 1 || m > 12 || m < 1 || d > 31 || d < 1) {
return false;
}
var g = Date.jalaliConverter.jalaliToGregorian([y, m, d]);
var j = Date.jalaliConverter.gregorianToJalali(g);
return j[0] === y && j[1] === m && j[2] === d;
},

/**
* Corrects Jalali date of month if the date is invalid for the specified month of year.
* @param {Number} year Jalali full year.
* @param {Number} month Jalali month (0-based).
* @param {Number} date Jalali date.
* @return {Number} Corrected Jalali date.
*/
correctJalaliDateOfMonth: function (year, month, date) {
if (month === 11 && date > 29) {
if (Date.isJalaliLeapYear(year)) {
return 30;
} else {
return 29;
}
} else if (month > 5 && date > 30) {
return 30;
} else {
return date;
}
},

/**
* Checks whether the specified year is a leap year in Jalali calendar.
* @param {Number} year A 4-digit year to check.
*/
isJalaliLeapYear: function (year) {
return Date.isJalaliValid(year, 12, 30);
},

/**
* Creates a new date instance based on the provided Jalali year, month (0-based) and date.
* @param {Number} year Jalali full year.
* @param {Number} month Jalali month (0-based).
* @param {Number} date Jalali date.
*/
createJalali: function (year, month, date) {
var g = Date.jalaliConverter.jalaliToGregorian([year, month + 1, date]);
return new Date(g[0], g[1] - 1, g[2]);
},

/**
* Parses a Jalali formatted date string (like "1389/06/09") and returns a Date object.
* @param {String} jalaliString Formatted string to parse.
* @param {Boolean} strict True to validate date strings after parsing which will return null when invalid
* (default is false).
* @return {Date} A Date object which is set to the Gregorian conversion of input.
*/
parseJalali: function (jalaliString, strict) {
var split = jalaliString.split('/');
var jy = parseInt(split[0], 10),
jm = parseInt(split[1], 10),
jd = parseInt(split[2], 10);
if (isNaN(jy) || isNaN(jm) || isNaN(jd) || jy > 1500 || jy < 1 || jm > 12 || jm < 1 || jd > 31 || jd < 1) {
return null;
}
var g = Date.jalaliConverter.jalaliToGregorian([jy, jm, jd]);
var d = new Date(g[0], g[1] - 1, g[2]);
if (strict &&
(!d || d.getJalaliFullYear() !== jy || d.getJalaliMonth() + 1 !== jm && d.getJalaliDate() !== jd)) {
return null;
}
return d;
},

/**
* Month names of Jalali calendar. Override this for localization.
*/
jalaliMonthNames: [
'Farvardin',
'Ordibehesht',
'Khordad',
'Tir',
'Amordad',
'Shahrivar',
'Mehr',
'Aban',
'Azar',
'Dey',
'Bahman',
'Esfand'
]
});

/**
* Jalali format codes. List of Jalali format codes:
* <pre><code>
Format Description Example returned values
------ ------------------------------------------------------------------- -----------------------
r Jalali day of the month without leading zeros 1 to 31
R Jalali day of the month, 2 digits with leading zeros 01 to 31
q Numeric representation of Jalali month without leading zeros 1 to 12
Q Numeric representation of Jalali month, 2 digits with leading zeros 01 to 12
e Full textual representation of Jalali month Farvardin to Esfand
b Short representation of Jalali year, 2 digits 89 or 60
B Full numeric representation of Jalali year, 4 digits 1389 or 1360
* </code></pre>
* Example usage:
* <pre><code>
var d = new Date();
console.log(d.format('B/Q/R')); // 1389/06/14
console.log(d.format('b/q/r')); // 89/6/14
console.log(d.format('l, r e B')); // Sunday, 14 Shahrivar 1389
* </code></pre>
*/
Ext.apply(Date.formatCodes, {
r: "this.getJalaliDate()",
R: "String.leftPad(this.getJalaliDate(), 2, '0')",
q: "(this.getJalaliMonth() + 1)",
Q: "String.leftPad(this.getJalaliMonth() + 1, 2, '0')",
e: "Date.jalaliMonthNames[this.getJalaliMonth()]",
b: "('' + this.getJalaliFullYear()).substring(2, 4)",
B: "this.getJalaliFullYear()"
});

Ext.apply(Date.formatFunctions, {
/**
* Formats date instances using Jalali format (like: "1389/06/14").
* @return {String} Textual representation of Jalali date.
*/
'Jalali': function () {
return this.getJalaliFullYear() + '/' +
String.leftPad(this.getJalaliMonth() + 1, 2, '0') + '/' +
String.leftPad(this.getJalaliDate(), 2, '0');
}
});

Ext.apply(Date.parseFunctions, {
/**
* Parses a Jalali formatted date string (like "1389/06/09") and returns a Date object.
* @param {String} jalaliString Formatted string to parse.
* @param {Boolean} strict True to validate date strings after parsing which will return null when invalid
* (default is false).
* @return {Date} A Date object which is set to the Gregorian conversion of input.
*/
'Jalali': Date.parseJalali,
'B/Q/R': Date.parseJalali,
'B/q/r': Date.parseJalali,
'b/q/r': function (value, strict) {
return Date.parseJalali('13' + value, strict);
},
'b/Q/R': function (value, strict) {
return Date.parseJalali('13' + value, strict);
},
'B': function (value, strict) {
var now = new Date();
return Date.parseJalali(value + '/' + (now.getJalaliMonth() + 1) + '/' + now.getJalaliDate(), strict);
},
'b': function (value, strict) {
var now = new Date();
return Date.parseJalali('13' + value + '/' + (now.getJalaliMonth() + 1) + '/' + now.getJalaliDate(), strict);
},
'q': function (value, strict) {
var now = new Date();
return Date.parseJalali(now.getJalaliFullYear() + '/' + value + '/' + now.getJalaliDate(), strict);
},
'Q': function (value, strict) {
var now = new Date();
return Date.parseJalali(now.getJalaliFullYear() + '/' + value + '/' + now.getJalaliDate(), strict);
},
'r': function (value, strict) {
var now = new Date();
return Date.parseJalali(now.getJalaliFullYear() + '/' + (now.getJalaliMonth() + 1) + '/' + value, strict);
},
'R': function (value, strict) {
var now = new Date();
return Date.parseJalali(now.getJalaliFullYear() + '/' + (now.getJalaliMonth() + 1) + '/' + value, strict);
},
'b/q': function (value, strict) {
var now = new Date();
return Date.parseJalali('13' + value + '/' + now.getJalaliDate(), strict);
},
'B/q': function (value, strict) {
var now = new Date();
return Date.parseJalali(value + '/' + now.getJalaliDate(), strict);
},
'B/Q': function (value, strict) {
var now = new Date();
return Date.parseJalali(value + '/' + now.getJalaliDate(), strict);
},
'b/Q': function (value, strict) {
var now = new Date();
return Date.parseJalali('13' + value + '/' + now.getJalaliDate(), strict);
},
'q/r': function (value, strict) {
var now = new Date();
return Date.parseJalali(now.getJalaliFullYear() + '/' + value, strict);
},
'Q/r': function (value, strict) {
var now = new Date();
return Date.parseJalali(now.getJalaliFullYear() + '/' + value, strict);
},
'Q/R': function (value, strict) {
var now = new Date();
return Date.parseJalali(now.getJalaliFullYear() + '/' + value, strict);
},
'q/R': function (value, strict) {
var now = new Date();
return Date.parseJalali(now.getJalaliFullYear() + '/' + value, strict);
}
});

Ext.override(Date, {

/**
* Calculates current Jalali date and caches the result. Methods that change this instance's state,
* should invalidate cache.
*/
convertToJalali: function () {
if (!this.jalaliConverted) {
var j = Date.jalaliConverter.gregorianToJalali([this.getFullYear(), this.getMonth() + 1, this.getDate()]);
this.jalaliYear = j[0];
this.jalaliMonth = j[1] - 1;
this.jalaliDate = j[2];
this.jalaliConverted = true;
}
},

/**
* Calculates current Gregorian date.
*/
convertFromJalali: function () {
var g = Date.jalaliConverter.jalaliToGregorian([this.jalaliYear, this.jalaliMonth + 1, this.jalaliDate]);
this.setFullYear(g[0]);
this.setMonth(g[1] - 1);
this.setDate(g[2]);
this.jalaliConverted = false;
this.convertToJalali();
},

/**
* Invalidates cache of Jalali conversion, so convertToJalali() will recalculate Jalali values the next time.
*/
invalidateJalaliConversion: function () {
this.jalaliConverted = false;
},

/**
* Returns Jalali full year.
* @return {Number} Jalali year.
*/
getJalaliFullYear: function () {
this.convertToJalali();
return this.jalaliYear;
},

/**
* Returns Jalali month. Month is 0-based.
* @return {Number} Jalali month of year (0-based).
*/
getJalaliMonth: function () {
this.convertToJalali();
return this.jalaliMonth;
},

/**
* Returns Jalali date of month.
* @return {Number} Jalali date of month.
*/
getJalaliDate: function () {
this.convertToJalali();
return this.jalaliDate;
},

/**
* Checks if the current date falls within a Jalali leap year.
* @return {Boolean} True if the current date falls within a Jalali leap year, false otherwise.
*/
isJalaliLeapYear: function () {
this.convertToJalali();
return Date.isJalaliLeapYear(this.jalaliYear);
},

/**
* Provides a convenient method for performing basic Jalali date arithmetic. This method
* does not modify the Date instance being called - it creates and returns
* a new Date instance containing the resulting date value.
* @param {String} interval A valid date interval enum value.
* @param {Number} value The amount to add to the current date.
* @return {Date} The new Date instance.
*/
addJalali: function (interval, value) {
var d = this.clone();
if (!interval || value === 0) {
return d;
}

d.convertToJalali();

switch (interval.toLowerCase()) {
case Date.DAY:
d.jalaliDate += value;
d.convertFromJalali();
break;
case Date.MONTH:
d.jalaliMonth += value;
d.jalaliYear += Math.floor(d.jalaliMonth / 12);
d.jalaliMonth %= 12;
if (d.jalaliMonth < 0) {
d.jalaliMonth += 12;
}
d.jalaliDate = Date.correctJalaliDateOfMonth(d.jalaliYear, d.jalaliMonth, d.jalaliDate);
d.convertFromJalali();
break;
case Date.YEAR:
d.jalaliYear += value;
d.jalaliDate = Date.correctJalaliDateOfMonth(d.jalaliYear, d.jalaliMonth, d.jalaliDate);
d.convertFromJalali();
break;
}
return d;
},

/**
* Returns the number of days in the current Jalali month, adjusted for leap year.
* @return {Number} The number of days in the current Jalali month.
*/
getJalaliDaysInMonth: function () {
this.convertToJalali();
if (this.jalaliMonth < 6) {
return 31;
} else if (this.jalaliMonth < 11) {
return 30;
} else if (this.isJalaliLeapYear()) {
return 30;
} else {
return 29;
}
},

/**
* Returns the date of the first day of the Jalali month.
* @return {Date} The date of the first day of the Jalali month.
*/
getJalaliFirstDateOfMonth: function () {
this.convertToJalali();
return Date.createJalali(this.jalaliYear, this.jalaliMonth, 1);
}
});

// Invalidates Jalali conversion cache
Ext.override(Date, {
clearTime: Date.prototype.clearTime.createSequence(Date.prototype.invalidateJalaliConversion),
setYear: Date.prototype.setYear.createSequence(Date.prototype.invalidateJalaliConversion),
setMonth: Date.prototype.setMonth.createSequence(Date.prototype.invalidateJalaliConversion),
setDate: Date.prototype.setDate.createSequence(Date.prototype.invalidateJalaliConversion),
add: Date.prototype.add.createSequence(Date.prototype.invalidateJalaliConversion)
});
------------------------------------------------------------------------------------------------------------------
3-JalaliDatePlugin.js

/*
* Copyright (c) 2010 Tosan, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/**
* @class Ext.ux.JalaliDatePlugin
*
* <p>A plugin for Ext date components. Just add this object as a plugin to date components
* (e.g. Ext.DatePicker, Ext.menu.DateMenu or Ext.form.DateField) and it will be converted to Jalali.
*
* @author Behrang Noroozinia
*/
Ext.ns("Ext.ux");
Ext.ux.JalaliDatePlugin = {

/**
* Initializes this plugin. Some methods in the main class are instrumented, others are replaced.
* @param {Ext.Component} component Component that should be instrumented.
*/
init: function (component) {
if (component instanceof Ext.DatePicker) { // for both Ext.DatePicker & Ext.menu.DateMenu
component.monthNames = Date.jalaliMonthNames;
component.createMonthPicker = component.createMonthPicker.createSequence(this.afterCreateMonthPicker);
component.showMonthPicker = component.showMonthPicker.createSequence(this.afterShowMonthPicker);
component.onMonthClick = component.onMonthClick.createInterceptor(this.beforeOnMonthClick);
component.onMonthDblClick = this.onMonthDblClick;
component.showPrevMonth = this.showPrevMonth;
component.showNextMonth = this.showNextMonth;
component.showPrevYear = this.showPrevYear;
component.showNextYear = this.showNextYear;
component.update = this.update;
} else if (component instanceof Ext.form.DateField) { // for Ext.form.DateField
component.onTriggerClick = component.onTriggerClick.createInterceptor(this.beforeOnTriggerClick);
component.safeParse = this.safeParse;
}
},

/**
* Replaces DateField.parseDate method. Since that method adds an hour field to format,
* the parse functions in Date.parseFunctions are not used. Here we skip the hour conversion part.
* It may produce errors when using different time zones.
* @param {String} value The string containing a formatted date.
* @param {String} format The format of the value to parse.
*/
safeParse: function (value, format) {
var parsedDate = Date.parseDate(value, format);
if (parsedDate) {
return parsedDate.clearTime();
}
},

/**
* Intercepts onTriggerClick method in date fields and adds this plugin to date menu.
*/
beforeOnTriggerClick: function () {
if (this.menu == null) {
this.menu = new Ext.menu.DateMenu({
hideOnClick: false,
focusOnSelect: false,
plugins: [Ext.ux.JalaliDatePlugin]
})
}
return true;
},

/**
* Replaces Gregorian month names with Jalali names.
*/
afterCreateMonthPicker: function () {
if (this.mpMonthsInstrumented) {
return;
}
this.mpMonthsInstrumented = true;
var monthNames = this.monthNames;
this.mpMonths.each(function (m) {
m.child('a').update(monthNames[m.dom.xmonth]);
});
},

/**
* Corrects month picker's selected month and year.
*/
afterShowMonthPicker: function () {
if (!this.disabled) {
this.mpSelMonth = (this.activeDate || this.value).getJalaliMonth();
this.updateMPMonth(this.mpSelMonth);
this.mpSelYear = (this.activeDate || this.value).getJalaliFullYear();
this.updateMPYear(this.mpSelYear);
}
},

/**
* Selects correct month and year when OK button is selected.
*/
beforeOnMonthClick: function (e, t) {
var el = new Ext.Element(t);
if (el.is('button.x-date-mp-ok')) {
e.stopEvent();
this.update(Ext.ux.JalaliDatePlugin.prepareDate(
this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getJalaliDate()));
this.hideMonthPicker();
return false;
}
return true;
},

/**
* Handles double clicking in month picker.
*/
onMonthDblClick : function(e, t){
e.stopEvent();
var el = new Ext.Element(t), pn;
if((pn = el.up('td.x-date-mp-month', 2))){
this.update(Ext.ux.JalaliDatePlugin.prepareDate(
this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getJalaliDate()));
this.hideMonthPicker();
}
else if((pn = el.up('td.x-date-mp-year', 2))){
this.update(Ext.ux.JalaliDatePlugin.prepareDate(
pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getJalaliDate()));
this.hideMonthPicker();
}
},

// private
prepareDate: function (year, month, date) {
var d = Date.correctJalaliDateOfMonth(year, month, date);
return Date.createJalali(year, month, d);
},

/**
* Handles showing previous month.
*/
showPrevMonth: function () {
this.update(this.activeDate.addJalali(Date.MONTH, -1));
},

/**
* Handles showing next month.
*/
showNextMonth: function () {
this.update(this.activeDate.addJalali(Date.MONTH, 1));
},

/**
* Handles showing previous year.
*/
showPrevYear: function () {
this.update(this.activeDate.addJalali(Date.YEAR, -1));
},

/**
* Handles showing next year.
*/
showNextYear: function () {
this.update(this.activeDate.addJalali(Date.YEAR, 1));
},

/**
* Overridden update method of DatePicker. A few lines changed, so it can show Jalali dates.
* @param {Date} date The date that should be selected.
* @param {Boolean} forceRefresh Force refresh current month display.
*/
update : function(date, forceRefresh){
if(this.rendered){
var vd = this.activeDate, vis = this.isVisible();
this.activeDate = date;
if(!forceRefresh && vd && this.el){
var t = date.getTime();
if(vd.getJalaliMonth() == date.getJalaliMonth() && vd.getJalaliFullYear() == date.getJalaliFullYear()){
this.cells.removeClass('x-date-selected');
this.cells.each(function(c){
if(c.dom.firstChild.dateValue == t){
c.addClass('x-date-selected');
if(vis && !this.cancelFocus){
Ext.fly(c.dom.firstChild).focus(50);
}
return false;
}
}, this);
return;
}
}
var days = date.getJalaliDaysInMonth(),
firstOfMonth = date.getJalaliFirstDateOfMonth(),
startingPos = firstOfMonth.getDay()-this.startDay;

if(startingPos < 0){
startingPos += 7;
}
days += startingPos;

var pm = date.addJalali(Date.MONTH, -1),
prevStart = pm.getJalaliDaysInMonth()-startingPos,
cells = this.cells.elements,
textEls = this.textNodes,
// convert everything to numbers so it's fast
d = Date.createJalali(pm.getJalaliFullYear(), pm.getJalaliMonth(), prevStart),
today = new Date().clearTime().getTime(),
sel = date.clearTime(true).getTime(),
min = this.minDate ? this.minDate.clearTime(true) : Number.NEGATIVE_INFINITY,
max = this.maxDate ? this.maxDate.clearTime(true) : Number.POSITIVE_INFINITY,
ddMatch = this.disabledDatesRE,
ddText = this.disabledDatesText,
ddays = this.disabledDays ? this.disabledDays.join('') : false,
ddaysText = this.disabledDaysText,
format = this.format;
d.setHours(this.initHour);

if(this.showToday){
var td = new Date().clearTime(),
disable = (td < min || td > max ||
(ddMatch && format && ddMatch.test(td.dateFormat(format))) ||
(ddays && ddays.indexOf(td.getDay()) != -1));

if(!this.disabled){
this.todayBtn.setDisabled(disable);
this.todayKeyListener[disable ? 'disable' : 'enable']();
}
}

var setCellClass = function(cal, cell){
cell.title = '';
var t = d.clearTime(true).getTime();
cell.firstChild.dateValue = t;
if(t == today){
cell.className += ' x-date-today';
cell.title = cal.todayText;
}
if(t == sel){
cell.className += ' x-date-selected';
if(vis){
Ext.fly(cell.firstChild).focus(50);
}
}
// disabling
if(t < min) {
cell.className = ' x-date-disabled';
cell.title = cal.minText;
return;
}
if(t > max) {
cell.className = ' x-date-disabled';
cell.title = cal.maxText;
return;
}
if(ddays){
if(ddays.indexOf(d.getDay()) != -1){
cell.title = ddaysText;
cell.className = ' x-date-disabled';
}
}
if(ddMatch && format){
var fvalue = d.dateFormat(format);
if(ddMatch.test(fvalue)){
cell.title = ddText.replace('%0', fvalue);
cell.className = ' x-date-disabled';
}
}
};

var i = 0;
for(; i < startingPos; i++) {
textEls.innerHTML = (++prevStart);
d.setDate(d.getDate()+1);
cells.className = 'x-date-prevday';
setCellClass(this, cells);
}
for(; i < days; i++){
var intDay = i - startingPos + 1;
textEls.innerHTML = (intDay);
d.setDate(d.getDate()+1);
cells[i].className = 'x-date-active';
setCellClass(this, cells[i]);
}
var extraDays = 0;
for(; i < 42; i++) {
textEls[i].innerHTML = (++extraDays);
d.setDate(d.getDate()+1);
cells[i].className = 'x-date-nextday';
setCellClass(this, cells[i]);
}

this.mbtn.setText(this.monthNames[date.getJalaliMonth()] + ' ' + date.getJalaliFullYear());

if(!this.internalRender){
var main = this.el.dom.firstChild,
w = main.offsetWidth;
this.el.setWidth(w + this.el.getBorderWidth('lr'));
Ext.fly(main).setWidth(w);
this.internalRender = true;
// opera does not respect the auto grow header center column
// then, after it gets a width opera refuses to recalculate
// without a second pass
if(Ext.isOpera && !this.secondPass){
main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + 'px';
this.secondPass = true;
this.update.defer(10, this, [date]);
}
}
}
}
};

------------------------------------------------------------------------------------------------------------------------------
4-JalaliDatePlugin-fa_IR.js
/*
* Copyright (c) 2010 Tosan, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/**
* Persian localization for Jalali date.
*
* @author Behrang Noroozinia
*/
Ext.apply(Date, {
jalaliMonthNames: [
'فروردین',
'اردیبهشت',
'خرداد',
'تیر',
'امرداد',
'شهریور',
'مهر',
'آبان',
'آذر',
'دی',
'بهمن',
'اسفند'
],

dayNames: [
'یکشنبه',
'دوشنبه',
'سه‌شنبه',
'چهارشنبه',
'پنج‌شنبه',
'آدینه',
'شنبه'
]
});

Ext.override(Ext.DatePicker, {
dayNames: Date.dayNames,
format: 'B/Q/R',
todayText: 'امروز',
okText: 'ادامه',
cancelText: 'برگشت',
todayTip: '{0} (جای خالی)',
minText: 'این تاریخ پیش از نخستین ناریخ است',
maxText: 'این تاریخ پس از آخرین تاریخ است',
disabledDaysText: 'غیرفعال',
disabledDatesText: 'غیرفعال',
nextText: 'ماه پسین (مهار+راست)',
prevText: 'ماه پیشین (مهار+چپ)',
monthYearText: 'ماه را انتخاب کنید (جابجایی سال با مهار+بالا/پایین)',
startDay: 6
});

Ext.override(Ext.form.DateField, {
format: 'B/Q/R',
altFormats: 'B/Q/R|B/q/r|b/q/r|b/Q/R|q/r|Q/R|Q/r|q/R|r|R',
todayText: 'امروز',
okText: 'ادامه',
cancelText: 'برگشت',
todayTip: '{0} (جای خالی)',
minText: 'باید تاریخ‌های پس از {0} را برگزینید',
maxText: 'باید تاریخ‌های پیش از {0} را برگزینید',
invalidText: '{0} تاریخ درستی نیست، باید در قالب «سال/ماه/روز» باشد',
disabledDaysText: 'غیرفعال',
disabledDatesText: 'غیرفعال'
});

----------------------------------------------------------------------------------------------------------------------------------------------
also based on these codes I add this line ""plugins: [Ext.ux.JalaliDatePlugin],""
in modules/calendar/EventDialog.js instead of format for startdate and enddate.

Can you say to me this solution is correct or not?????/

thank you indeed.

Who is online

Users browsing this forum: No registered users and 1 guest