calendar format in non Gregorian countries #135

Closed
opened 2017-10-08 13:32:34 +00:00 by sepehr09 · 2 comments
sepehr09 commented 2017-10-08 13:32:34 +00:00 (Migrated from github.com)

hello,
i think every calendar fields should use :
<?php echo JHtml::_('date', $this->escape($item->somefield), 'Y/m/d') ; ?>
instead of :
<?php echo $this->escape($item->somefield); ?>

and "Y/m/d" should get from field format :

image

in admin list view (views->someview->tmpl->default_body)

that's because in some regions the official calendar isn't Gregorian. and that is using default calendar format used in joomla.

for example, the com_content in joomla use this :
<?php $date = $item->{$orderingColumn}; echo $date > 0 ? JHtml::_('date', $date, JText::_('DATE_FORMAT_LC4')) : '-'; ?>

image

if i can know where default admin list view generated in compiler, i can fix it & if you think this is ok i will fix & pull request for that in github.
best regards.

hello, i think every calendar fields should use : `<?php echo JHtml::_('date', $this->escape($item->somefield), 'Y/m/d') ; ?>` instead of : `<?php echo $this->escape($item->somefield); ?>` and "Y/m/d" should get from field format : ![image](https://user-images.githubusercontent.com/11753906/31317289-0001a686-ac4b-11e7-8988-2c3e8ae1261a.png) in admin list view (views->someview->tmpl->default_body) that's because in some regions the official calendar isn't Gregorian. and that is using default calendar format used in joomla. for example, the com_content in joomla use this : `<?php $date = $item->{$orderingColumn}; echo $date > 0 ? JHtml::_('date', $date, JText::_('DATE_FORMAT_LC4')) : '-'; ?> ` ![image](https://user-images.githubusercontent.com/11753906/31317243-4c9f5dae-ac4a-11e7-9892-d8661d6ea2e5.png) if i can know where default admin list view generated in compiler, i can fix it & if you think this is ok i will fix & pull request for that in github. best regards.

There is a way to deal with this... let me explain.

The escape of the fields are done by default to all fields... but it can be turned off. This will then allow you to in the model fix the date display to work in any way you would like it to display.

You only add the the xml value:
escape="false";
image

Then in the model you can do something like this:

// set the timers
if (isset($item->created) && $item->created != '0000-00-00 00:00:00')
{
	$item->created = strtotime($item->created);
	// check date
	if ($item->created < $danger)
	{
		// set danger
		$item->created = '<span class="vdm-badge vdm-danger">' . JobtrackingHelper::fancyDate($item->created) . '</span>';
	}
	elseif ($item->created < $warning)
	{
		// set warning
		$item->created = '<span class="vdm-badge vdm-warning">' . JobtrackingHelper::fancyDate($item->created) . '</span>';
	}
	else
	{
		// set okay
		$item->created = '<span class="vdm-badge vdm-success">' . JobtrackingHelper::fancyDate($item->created) . '</span>';
	}
}
else
{
	$item->created = '';
}

The helper class can look something like this:

/**
 *	Change to nice fancy date
 */
public static function fancyDate($date)
{
	if (!self::isValidTimeStamp($date))
	{
		$date = strtotime($date);
	}
	return date('jS \o\f F Y',$date);
}

/**
 *	Change to nice fancy day time and date
 */
public static function fancyDayTimeDate($time)
{
	if (!self::isValidTimeStamp($time))
	{
		$time = strtotime($time);
	}
	return date('D ga jS \o\f F Y',$time);
}

/**
 *	Change to nice fancy time and date
 */
public static function fancyDateTime($time)
{
	if (!self::isValidTimeStamp($time))
	{
		$time = strtotime($time);
	}
	return date('(G:i) jS \o\f F Y',$time);
}

This way you have full control and the behavior is not hard coded into JCB, let me know if you still think we should change the compiler, or if this will resolve your issue.

There is a way to deal with this... let me explain. The escape of the fields are done by default to all fields... but it can be turned off. This will then allow you to in the model fix the date display to work in any way you would like it to display. You only add the the xml value: `escape="false";` ![image](https://user-images.githubusercontent.com/5607939/31318965-2eb341a0-ac5b-11e7-80dc-85861411f063.png) Then in the model you can do something like this: ``` // set the timers if (isset($item->created) && $item->created != '0000-00-00 00:00:00') { $item->created = strtotime($item->created); // check date if ($item->created < $danger) { // set danger $item->created = '<span class="vdm-badge vdm-danger">' . JobtrackingHelper::fancyDate($item->created) . '</span>'; } elseif ($item->created < $warning) { // set warning $item->created = '<span class="vdm-badge vdm-warning">' . JobtrackingHelper::fancyDate($item->created) . '</span>'; } else { // set okay $item->created = '<span class="vdm-badge vdm-success">' . JobtrackingHelper::fancyDate($item->created) . '</span>'; } } else { $item->created = ''; } ``` The helper class can look something like this: ``` /** * Change to nice fancy date */ public static function fancyDate($date) { if (!self::isValidTimeStamp($date)) { $date = strtotime($date); } return date('jS \o\f F Y',$date); } /** * Change to nice fancy day time and date */ public static function fancyDayTimeDate($time) { if (!self::isValidTimeStamp($time)) { $time = strtotime($time); } return date('D ga jS \o\f F Y',$time); } /** * Change to nice fancy time and date */ public static function fancyDateTime($time) { if (!self::isValidTimeStamp($time)) { $time = strtotime($time); } return date('(G:i) jS \o\f F Y',$time); } ``` This way you have full control and the behavior is not hard coded into JCB, let me know if you still think we should change the compiler, or if this will resolve your issue.
sepehr09 commented 2017-10-08 18:07:02 +00:00 (Migrated from github.com)

thank you very much for your help, yes that's fix the problem.
for anyone have same problem, i add this code & now that's working!

add :

	if ([[[Component]]]Helper::checkArray($items))
	{
		foreach ($items as $nr => &$item)
		{
			if (!isset($_export) || !$_export)
			{
				if (isset($item->created) && $item->created != '0000-00-00 00:00:00'){		
					$item->created =  JHtml::_('date', $item->created, 'Y/m/d');
				}
			}
		}
	}	

to :
Add PHP (getItems Method - before translation fix & decryption)

result :
image

(actually that's working without adding escape="false"; to XML ! )

thank you very much for your help, yes that's fix the problem. for anyone have same problem, i add this code & now that's working! add : ``` if ([[[Component]]]Helper::checkArray($items)) { foreach ($items as $nr => &$item) { if (!isset($_export) || !$_export) { if (isset($item->created) && $item->created != '0000-00-00 00:00:00'){ $item->created = JHtml::_('date', $item->created, 'Y/m/d'); } } } } ``` to : `Add PHP (getItems Method - before translation fix & decryption) ` result : ![image](https://user-images.githubusercontent.com/11753906/31319472-c165303e-ac70-11e7-953d-70bd1734277c.png) (actually that's working without adding `escape="false";` to XML ! )
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#135
No description provided.