Passed
Push — develop ( b405cd...984b92 )
by Remco
05:42
created

DateTimeZone::get_default()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Date time zone
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 zone
17
 *
18
 * @author Remco Tolsma
19
 * @version 1.0
20
 */
21
class DateTimeZone extends \DateTimeZone {
22
	/**
23
	 * Get default timezone.
24
	 *
25
	 * @see https://github.com/Rarst/wpdatetime/blob/0.3/src/WpDateTimeZone.php
26
	 * @see https://github.com/WordPress/WordPress/blob/4.9.4/wp-includes/functions.php#L72-L151
27
	 *
28
	 * @return DateTimeZone
29
	 */
30
	public static function get_default() {
31
		$timezone_string = get_option( 'timezone_string' );
32
33
		if ( ! empty( $timezone_string ) ) {
34
			return new DateTimeZone( $timezone_string );
35
		}
36
37
		$offset  = get_option( 'gmt_offset' );
38
		$hours   = (int) $offset;
39
		$minutes = abs( ( $offset - (int) $offset ) * 60 );
40
		$offset  = sprintf( '%+03d:%02d', $hours, $minutes );
41
42
		return new DateTimeZone( $offset );
43
	}
44
}
45