Passed
Push — develop ( c8a590...2ec740 )
by Remco
09:16
created

DateTime   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A format_i18n() 0 10 2
1
<?php
2
/**
3
 * Date time
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2018 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay
9
 * @see       https://github.com/woocommerce/woocommerce/blob/3.3.4/includes/class-wc-datetime.php
10
 * @see       https://github.com/Rarst/wpdatetime/
11
 */
12
13
namespace Pronamic\WordPress\Pay;
14
15
/**
16
 * Date time
17
 *
18
 * @author Remco Tolsma
19
 * @version 1.0
20
 */
21
class DateTime extends \DateTime {
22
	/**
23
	 * MySQL datetime foramt.
24
	 *
25
	 * @see https://dev.mysql.com/doc/en/datetime.html
26
	 * @see https://github.com/Rarst/wpdatetime/blob/0.3/src/WpDateTime.php#L10
27
	 *
28
	 * @var string
29
	 */
30
	const MYSQL = 'Y-m-d H:i:s';
31
32
	/**
33
	 * Format I18N.
34
	 *
35
	 * @see https://github.com/Rarst/wpdatetime/blob/0.3/src/WpDateTimeTrait.php#L79-L104
36
	 * @see https://github.com/WordPress/WordPress/blob/4.9.4/wp-includes/functions.php#L72-L151
37
	 *
38
	 * @param string|null $format Format.
39
	 *
40
	 * @return string
41
	 */
42
	public function format_i18n( $format = null ) {
43
		$format = ( null === $format ) ? __( 'D j M Y \a\t H:i', 'pronamic_ideal' ) : $format;
44
45
		$date = clone $this;
46
47
		$date->setTimezone( DateTimeZone::get_default() );
48
49
		$result = date_i18n( $format, $date->getTimestamp() + $date->getOffset(), true );
50
51
		return $result;
52
	}
53
}
54