- Posts: 2
- Thank you received: 0
Jalali date (Persian) for simple date picker
- mahdi.manian
-
Topic Author
- Offline
Less
More
10 years 2 months ago #244810
by mahdi.manian
Jalali date (Persian) for simple date picker was created by mahdi.manian
Hi.
I have a problem with simple date picker custom field (Address). My website language is Persian and i use jalali date in simple date picker, but when i save the address date don't save correctly and when i want to edit this address, date show incorrect.
Please see this pictures:
the problem is jalali date saved to database but this is mistake and jalali date should be convert to original date and then saved to database. and when i edit the address, original date should be convert to jalali and show to me.
Please help me. Thanks you.
I have a problem with simple date picker custom field (Address). My website language is Persian and i use jalali date in simple date picker, but when i save the address date don't save correctly and when i want to edit this address, date show incorrect.
Please see this pictures:
the problem is jalali date saved to database but this is mistake and jalali date should be convert to original date and then saved to database. and when i edit the address, original date should be convert to jalali and show to me.
Please help me. Thanks you.
Please Log in or Create an account to join the conversation.
10 years 2 months ago #244836
by nicolas
Replied by nicolas on topic Jalali date (Persian) for simple date picker
Hi,
Try to add that code:
before the code:
in the file administrator/components/com_hikashop/classes/field.php
Try to add that code:
Code:
function check(&$field,&$value,$oldvalue){
$value = JFactory::getDate()->format($value);
return true;
}
Code:
function showfield($viewObj, $namekey, $row) {
if( isset( $row->$namekey)) {
$date_format = !empty( $this->field_options['format']) ? $this->field_options['format'] : '%Y-%m-%d %H:%M:%S';
return hikashop_getDate( $row->$namekey, $date_format);
}
return '';
}
The following user(s) said Thank You: mahdi.manian
Please Log in or Create an account to join the conversation.
- mahdi.manian
-
Topic Author
- Offline
Less
More
- Posts: 2
- Thank you received: 0
10 years 2 months ago #244914
by mahdi.manian
Replied by mahdi.manian on topic Jalali date (Persian) for simple date picker
Thanks but the problem is not resolved!
I added your code in that file, but i don't need call check function in here or another place? Where this function should be called?
I want convert my date to Gregorian date before storing in database. now Jalali date stored in database that this mistake and Gregorian date should be stored in database.
please help me. thank you.
I added your code in that file, but i don't need call check function in here or another place? Where this function should be called?
I want convert my date to Gregorian date before storing in database. now Jalali date stored in database that this mistake and Gregorian date should be stored in database.
please help me. thank you.
Please Log in or Create an account to join the conversation.
10 years 2 months ago #245873
by nicolas
Replied by nicolas on topic Jalali date (Persian) for simple date picker
Hi,
That's what this function is supposed to do.
The check function is called automatically by the system before storing the value of a custom field of that type so that it can verify the validity of the value.
Then try adding this code instead:
That's what this function is supposed to do.
The check function is called automatically by the system before storing the value of a custom field of that type so that it can verify the validity of the value.
Then try adding this code instead:
Code:
function check(&$field,&$value,$oldvalue){
$date = explode('/',$value);
$value = implode('/',$this->gregorian_to_jalali($date[0],$date[1],$date[2]));
return true;
}
function div($a,$b) {
return (int) ($a / $b);
}
function gregorian_to_jalali ($g_y, $g_m, $g_d,$str=false)
{
$g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
$gy = $g_y-1600;
$gm = $g_m-1;
$gd = $g_d-1;
$g_day_no = 365*$gy+$this->div($gy+3,4)-$this->div($gy+99,100)+$this->div($gy+399,400);
for ($i=0; $i < $gm; ++$i)
$g_day_no += $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;
$j_day_no = $g_day_no-79;
$j_np = $this->div($j_day_no, 12053); /* 12053 = 365*33 + 32/4 */
$j_day_no = $j_day_no % 12053;
$jy = 979+33*$j_np+4*$this->div($j_day_no,1461); /* 1461 = 365*4 + 4/4 */
$j_day_no %= 1461;
if ($j_day_no >= 366) {
$jy += $this->div($j_day_no-1, 365);
$j_day_no = ($j_day_no-1)%365;
}
for ($i = 0; $i < 11 && $j_day_no >= $j_days_in_month[$i]; ++$i)
$j_day_no -= $j_days_in_month[$i];
$jm = $i+1;
$jd = $j_day_no+1;
if($str) return $jy.'/'.$jm.'/'.$jd ;
return array($jy, $jm, $jd);
}
Please Log in or Create an account to join the conversation.
Time to create page: 0.188 seconds