Completed
Pull Request — master (#664)
by
unknown
14:19 queued 09:11
created

SS_Datetimezone   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B Nice() 0 11 5
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 Nice() {
12
		//instantiate new DateTime object based off received timestamp in the default timezone
13
		$timestamp = new DateTime($this->value, new DateTimeZone(date_default_timezone_get()));
14
		//if a user is logged in, has set a timezone that is in the allowed list and 
15
		//that timezone is NOT the default one then convert the timestamp to use the selected timezone
16
		if(Member::currentUserID() && isset(Member::CurrentUser()->Timezone) && in_array(Member::CurrentUser()->Timezone, timezone_identifiers_list()) && Member::CurrentUser()->Timezone != date_default_timezone_get()){
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 212 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...
17
			$timestamp->setTimezone(new DateTimeZone(Member::CurrentUser()->Timezone));    
18
		}
19
		//return timestamp in "Nice" format + the user's timezone
20
		return $timestamp->Format('d/m/Y g:ia');
21
	}
22
}
23