Completed
Pull Request — master (#664)
by
unknown
06:55
created

SS_Datetimezone::Format()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 7
nc 3
nop 1
1
<?php
2
/**
3
 * Class SS_Datetimezone
4
 *
5
 * Adds customisable timezones to the nice method on {@link SS_Datetime}.
6
 */
7
class SS_Datetimezone extends SS_Datetime {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
	/**
9
	* Returns the date in the raw SQL-format specific to a given timezone passed from the Member class, e.g. “2006-01-18 16:32:04”
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
10
	*/
11
	public function Format($format) {
12
		if($this->value){
13
			$date = new DateTime($this->value);
14
			//if the current user has set a timezone that is not the default then use that
15
			$member = Member::currentUser();
16
			if ($member && $member->exists() && $member->Timezone && $member->Timezone != date_default_timezone_get()) {
17
				$date->setTimezone(new DateTimeZone($member->Timezone));    
18
			}
19
			return $date->Format($format);
20
		}
21
	}
22
}