TimeFormatViewHelper
Eigener ViewHelper für Ausgabe einer Zeitspanne
Formatiert eine Zeitspanne in lesbaren Text. Allerdings wird nur eine Einheit gewählt, also nicht 1 Std 30 Minuten 10 Sekunden.
Aufruf
<rsys:timeFormat amount="{project.workedTime}" />
Texte
Resources/Private/Language/locallang.xml
<!-- VIEWHELPERS: TIME UNITS -->
<label index="ViewHelper_Unit_Hours">hours</label>
<label index="ViewHelper_Unit_Minutes">minutes</label>
<label index="ViewHelper_Unit_Days">days</label>
<label index="ViewHelper_Unit_Seconds">seconds</label>
Listing
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Erwin Knoll <typo3coding@rootsystem.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
*
* Rootsystem SVN
* @version $Revision: 766 $
* @lastrevision $Date: 2012-06-15 18:49:17 +0200 (Fr, 15 Jun 2012) $
* @modifiedby $LastChangedBy: erwin $
* @lastmodified $LastChangedDate: 2012-06-15 18:49:17 +0200 (Fr, 15 Jun 2012) $
* @filesource $URL: localhost/svn/typo3/rsysextbase/trunk/Classes/ViewHelpers/TimeFormatViewHelper.php $
***************************************************************/
/**
*
* A ViewHelper for formatting time amounts. In dependence of the time amount, the
* time amount if formatted with a different unit (seconds, minutes, hours, days).
*
* @copyright 2010 rootsystem
* @author 2010 Erwin Knoll <typo3coding@rootsystem.de>
* @package Rsysextbase
* @subpackage ViewHelpers
* @version $Id: TimeFormatViewHelper.php 766 2012-06-15 16:49:17Z erwin $
* @license GNU Public License, version 2
* opensource.org/licenses/gpl-license.php
*
*/
Class Tx_Rsysextbase_ViewHelpers_TimeFormatViewHelper Extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
/**
*
* Renders the time amount.
*
* @param int $amount The time amount in seconds
* @return string The formatted output
*
*/
Public Function render($amount) {
$unit = 'Seconds';
If($amount == 0) {
$unit = 'Hours';
} ElseIf($amount >= 604800) {
$unit = 'Days';
$amount /= 86400.00;
} ElseIf($amount >= 3600) {
$unit = 'Hours';
$amount /= 3600;
} ElseIf($amount >= 60) {
$unit = 'Minutes';
$amount /= 60.00;
}
Return number_format($amount, 2, ',', '').' '.Tx_Extbase_Utility_Localization::translate('ViewHelper_Unit_'.$unit, 'Rsysextbase');
}
}
?>