Code Duplication    Length = 22-22 lines in 2 locations

api/src/DateTime.php 2 locations

@@ 402-423 (lines=22) @@
399
	 * @param string $type =null type or return-value, default (null) same as $time
400
	 * @return int|string|array|datetime null if time could not be parsed
401
	 */
402
	public static function server2user($time,$type=null)
403
	{
404
		$typeof='DateTime';
405
		if (!($time instanceof DateTime))
406
		{
407
			try
408
			{
409
				$time = new DateTime($time, self::$server_timezone, $typeof);
410
			}
411
			catch(Exception $e)
412
			{
413
				unset($e);
414
				return null;	// time could not be parsed
415
			}
416
		}
417
		$time->setUser();
418
419
		if (is_null($type)) $type = $typeof;
420
421
		//echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n";
422
		return $time->format($type);
423
	}
424
425
	/**
426
	 * Convert a user time into a server time
@@ 432-453 (lines=22) @@
429
	 * @param string $type =null type or return-value, default (null) same as $time
430
	 * @return int|string|array|datetime null if time could not be parsed
431
	 */
432
	public static function user2server($time,$type=null)
433
	{
434
		$typeof='DateTime';
435
		if (!($time instanceof DateTime))
436
		{
437
			try
438
			{
439
				$time = new DateTime($time,self::$user_timezone,$typeof);
440
			}
441
			catch(Exception $e)
442
			{
443
				unset($e);
444
				return null;	// time could not be parsed
445
			}
446
		}
447
		$time->setServer();
448
449
		if (is_null($type)) $type = $typeof;
450
451
		//echo "<p>".__METHOD__."($time,$type) = ".print_r($format->format($type),true)."</p>\n";
452
		return $time->format($type);
453
	}
454
455
	/**
456
	 * Convert time to a specific format or string, static version of DateTime::format()