⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Date & Time Formats



rafael84
  • profile picture
  • Member

Posted 26 December 2011 - 01:20 AM

While I'm learning how to work with Grocery CRUD, new ideas arise to make it even better.

So here's my suggestion regarding the date & time formats used in the listings.

I started by adding two new configuration items.
File: application/config/grocery_crud.php

$config['grocery_crud_default_date_format'] = 'd M Y';
$config['grocery_crud_default_datetime_format'] = 'd M Y - H:i';


Then we just need to use those formats in the grocery CRUD library file.
File: application/libraries/grocery_crud.php (around line #233)

case 'date':
if(!empty($value) && $value != '0000-00-00')
{
$ci = &get_instance();
$format = $ci->config->item('grocery_crud_default_date_format');
list($year,$month,$day) = explode("-",$value);
$value = date ($format, mktime (0,0,0,(int)$month , (int)$day , (int)$year));
}
else
{
$value = '';
}
break;
case 'datetime':
if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00')
{
$ci = &get_instance();
$format = $ci->config->item('grocery_crud_default_datetime_format');
list($year,$month,$day) = explode("-",$value);
list($hours,$minutes) = explode(":",substr($value,11));
$value = date ($format, mktime ( (int)$hours , (int)$minutes ,0, (int)$month , (int)$day ,(int)$year));
}
else
{
$value = '';
}
break;


And that's it. Now users can customize date / datetime formats.

What do you think about it, Johnny?

-Rafael

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 26 December 2011 - 19:16 PM

[quote name='rafael84' timestamp='1324862450' post='173']
While I'm learning how to work with Grocery CRUD, new ideas arise to make it even better.

So here's my suggestion regarding the date & time formats used in the listings.

I started by adding two new configuration items.
File: application/config/grocery_crud.php

$config['grocery_crud_default_date_format'] = 'd M Y';
$config['grocery_crud_default_datetime_format'] = 'd M Y - H:i';


Then we just need to use those formats in the grocery CRUD library file.
File: application/libraries/grocery_crud.php (around line #233)

case 'date':
if(!empty($value) && $value != '0000-00-00')
{
$ci = &get_instance();
$format = $ci->config->item('grocery_crud_default_date_format');
list($year,$month,$day) = explode("-",$value);
$value = date ($format, mktime (0,0,0,(int)$month , (int)$day , (int)$year));
}
else
{
$value = '';
}
break;
case 'datetime':
if(!empty($value) && $value != '0000-00-00 00:00:00' && $value != '1970-01-01 00:00:00')
{
$ci = &get_instance();
$format = $ci->config->item('grocery_crud_default_datetime_format');
list($year,$month,$day) = explode("-",$value);
list($hours,$minutes) = explode(":",substr($value,11));
$value = date ($format, mktime ( (int)$hours , (int)$minutes ,0, (int)$month , (int)$day ,(int)$year));
}
else
{
$value = '';
}
break;


And that's it. Now users can customize date / datetime formats.

What do you think about it, Johnny?

-Rafael
[/quote]
Hello Rafael

Actually the idea is great and I have it in mind to have something like that on future version. The config idea also is the way to do it. Actually the main problem that I had it was with javascript and not with php. The datetime plugin is old and not updated and I already have make changes to the plugin to make it work correctly. I will try to have something like that at next version but I am not promising anything because I have lot of things in mind to do for the next version, such as callback_before_upload, changing the uploader, upload images e.t.c.
Perhaps someone can use your code, as a patch to grocery CRUD. Thanks for the idea.

colegatron
  • profile picture
  • Member

Posted 27 December 2011 - 09:13 AM

In my honest opinion to have a way to config the date and date time format is very important (more than some callbacks), because it opens groceryCRUD to so many other countries users.
And to have to patch the app is a problem it self while upgrading.

Since are few lines of code, my opinion is to include it asap :-)

rafael84
  • profile picture
  • Member

Posted 27 December 2011 - 14:07 PM

I think that way too. :-)

amityweb
  • profile picture
  • Member

Posted 25 January 2012 - 17:01 PM

My customer has asked to change date format yet I really do not want to start hacking the core due to updates. So this would be great. I will convince them to hold off. I think its only in the field, the list view shows it fine.

amityweb
  • profile picture
  • Member

Posted 07 February 2012 - 11:21 AM

The new update has the config to change date now which is great, thanks a lot. Although when you click the date, the box still reverts back to the old format, it shows the new format when you first go into edit a field. But I dont think its a huge issue.
Thanks

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 07 February 2012 - 18:58 PM

Are you sure? I just checked it and it works fine. Make sure that you have clear the cache of the css and js files and it will work for sure.

amityweb
  • profile picture
  • Member

Posted 08 February 2012 - 12:06 PM

You are right, it is working OK now. Strange, it was sort of half fixed. When I edit a field is shows UK date format, but when changing or adding a date it showed the old format. I always refresh changes so must have.

OH I tell you what.... I may not have updated flexigrid at the time. I customised this before so copied that over, but in your update you updated some flexigrid stuff I needed, so decided not to use a custom flexigrid, so copied that over later. Maybe that was the issue.

Either way its working fine which is brilliant. Thanks a lot, its much easier to read dates now.

bluepicaso
  • profile picture
  • Member

Posted 14 January 2013 - 16:34 PM

nice solution