[CLOSED]Proposal for a FormatDate function

Locked
User avatar
hsm
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 225
Joined: Thu Sep 14, 2006 11:41 am
Location: Berlin

[CLOSED]Proposal for a FormatDate function

Post by hsm » Thu Jan 03, 2008 11:22 pm

Hi,

it is too difficult to format a time from mysql for users with JDate if you want use timezones ...

I propose to include a function like this to include in framework:

$dateMySQL is a MySQL-datetime field with UTC
$format is a format like this used with JDate::toFormat()

Code: Select all

	function sqlToFormat ( $dateMySQL, $format=null )
	{
		static $offset = false;
		static $nullDate = '';
		
		if ( $offset === false ) {
			jimport('joomla.utilities.date');
			$config =& JFactory::getConfig();
			$user =& JFactory::getUser();
			$offset = $user->getParam( 'timezone', $config->getValue('config.offset' ));

			$db =& JFactory::getDBO();
			$nullDate = $db->getNullDate();
		}
		
		if ( $dateMySQL == $nullDate || empty( $dateMySQL )) {
			$sDate = '???';
		} else {
			$date = new JDate( $dateMySQL ); 
			$date->setOffset( $offset );
			$sDate = ( $format == null ) ? $date->toFormat() : $date->toFormat( JText::_( $format ));
		}
		return $sDate;
	}
hsm

 
User avatar
Hackwar
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3788
Joined: Fri Sep 16, 2005 8:41 pm
Location: NRW - Germany
Contact:

Re: Proposal for a FormatDate function

Post by Hackwar » Sat Jan 05, 2008 8:12 pm

Why not use the ->toFormat(JText::_('DATE_FORMAT_LC2'))? Works fine on my end. ;) Closing report.
god doesn't play dice with the universe. not after that drunken night with the devil where he lost classical mechanics in a game of craps.

Since the creation of the Internet, the Earth's rotation has been fueled, primarily, by the collective spinning of English teachers in their graves.

User avatar
mcsmom
Joomla! Exemplar
Joomla! Exemplar
Posts: 7985
Joined: Thu Aug 18, 2005 8:43 pm
Location: New York
Contact:

Re: [CLOSED]Proposal for a FormatDate function

Post by mcsmom » Mon Jan 07, 2008 12:17 pm

Hannes,

since the dates are far from working fine, why don't you move this back so people can actually try to  be helpful.

Please also remember that people are trying to help here. Given the gravity of the situation, and dismissive comments to people who are contributing are not helpful.
So we must fix our vision not merely on the negative expulsion of war, but upon the positive affirmation of peace. MLK 1964.
http://officialjoomlabook.com Get it at http://www.joomla.org/joomla-press-official-books.html Buy a book, support Joomla!.

User avatar
Hackwar
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3788
Joined: Fri Sep 16, 2005 8:41 pm
Location: NRW - Germany
Contact:

Re: [CLOSED]Proposal for a FormatDate function

Post by Hackwar » Mon Jan 07, 2008 3:51 pm

Besides the formentioned function, we also have JHTML::_('date',... which does exactly what hsm is asking for. :)
god doesn't play dice with the universe. not after that drunken night with the devil where he lost classical mechanics in a game of craps.

Since the creation of the Internet, the Earth's rotation has been fueled, primarily, by the collective spinning of English teachers in their graves.

 

Locked

Return to “Q&T 1.5.x Resolved”