Completed
Push — 2016.04 ( 690368...e61816 )
by Aimeos
04:37
created

T3Datetime   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A translate() 0 4 2
A reverse() 0 4 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2014
7
 * @package MShop
8
 * @subpackage Common
9
 */
10
11
12
namespace Aimeos\MW\Criteria\Plugin;
13
14
15
/**
16
 * Criteria plugin for TYPO3 date/time values.
17
 *
18
 * @package MW
19
 * @subpackage Common
20
 */
21
class T3Datetime implements \Aimeos\MW\Criteria\Plugin\Iface
22
{
23
	/**
24
	 * Translates ISO dates into seconds relative to the epoch.
25
	 *
26
	 * @param string $value ISO date string (YYYY-MM-DD HH:mm:ss)
27
	 * @return integer Seconds relative to the epoch
28
	 */
29
	public function translate( $value )
30
	{
31
		return ( $value != null ? strtotime( $value ) : 0 );
32
	}
33
34
35
	/**
36
	 * Reverses the translation from seconds relative to the epoch to the ISO date string (YYYY-MM-DD HH:mm:ss).
37
	 *
38
	 * @param integer $value Seconds relative to the epoch
39
	 * @return string ISO date string (YYYY-MM-DD HH:mm:ss)
40
	 */
41
	public function reverse( $value )
42
	{
43
		return ( $value != 0 ? date( 'Y-m-d H:i:s', $value ) : null );
44
	}
45
}
46