Completed
Pull Request — master (#664)
by
unknown
10:16 queued 05:06
created

SS_Datetimezone::Nice()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 5
nc 2
nop 0
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