Jump to content


Date & Time Formats

suggestion

  • Please log in to reply
8 replies to this topic

#1 rafael84

rafael84

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationRio de Janeiro, Brazil

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

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,151 posts
  • LocationLondon

Posted 26 December 2011 - 07:16 PM

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

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.
Posted Image

#3 colegatron

colegatron

    Newbie

  • Members
  • Pip
  • 2 posts

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 :-)

#4 rafael84

rafael84

    Member

  • Members
  • PipPip
  • 10 posts
  • LocationRio de Janeiro, Brazil

Posted 27 December 2011 - 02:07 PM

I think that way too. :-)

#5 amityweb

amityweb

    Advanced Member

  • Members
  • PipPipPip
  • 35 posts

Posted 25 January 2012 - 05: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.

#6 amityweb

amityweb

    Advanced Member

  • Members
  • PipPipPip
  • 35 posts

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

#7 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,151 posts
  • LocationLondon

Posted 07 February 2012 - 06: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.
Posted Image

#8 amityweb

amityweb

    Advanced Member

  • Members
  • PipPipPip
  • 35 posts

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.

#9 bluepicaso

bluepicaso

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationIndia

Posted 14 January 2013 - 04:34 PM

nice solution

Harpreet Singh Bhatia
[web developer, programmer, entrepreneur]
Portfolio: TheCodingBox


Follow Me: facebook.png twitter.png googleplus.pngskype.png






Also tagged with one or more of these keywords: suggestion

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users