<commit_before><?php

/**
 * @file src/Util/Temporal.php
 */

namespace Friendica\Util;

use DateTime;
use DateTimeZone;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;

require_once 'boot.php';
require_once 'include/text.php';

/**
 * @brief Temporal class
 */
class Temporal
{
	/**
	 * @brief Two-level sort for timezones.
	 *
	 * @param string $a
	 * @param string $b
	 * @return int
	 */
	private static function timezoneCompareCallback($a, $b)
	{
		if (strstr($a, '/') && strstr($b, '/')) {
			if (L10n::t($a) == L10n::t($b)) {
				return 0;
			}
			return (L10n::t($a) < L10n::t($b)) ? -1 : 1;
		}

		if (strstr($a, '/')) {
			return -1;
		} elseif (strstr($b, '/')) {
			return 1;
		} elseif (L10n::t($a) == L10n::t($b)) {
			return 0;
		}

		return (L10n::t($a) < L10n::t($b)) ? -1 : 1;
	}

	/**
	 * @brief Emit a timezone selector grouped (primarily) by continent
	 *
	 * @param string $current Timezone
	 * @return string Parsed HTML output
	 */
	public static function getTimezoneSelect($current = 'America/Los_Angeles')
	{
		$timezone_identifiers = DateTimeZone::listIdentifiers();

		$o = '<select id="timezone_select" name="timezone">';

		usort($timezone_identifiers, [self, 'timezoneCompareCallback']);
		$continent = '';
		foreach ($timezone_identifiers as $value) {
			$ex = explode("/", $value);
			if (count($ex) > 1) {
				if ($ex[0] != $continent) {
					if ($continent != '') {
						$o .= '</optgroup>';
					}
					$continent = $ex[0];
					$o .= '<optgroup label="' . L10n::t($continent) . '">';
				}
				if (count($ex) > 2) {
					$city = substr($value, strpos($value, '/') + 1);
				} else {
					$city = $ex[1];
				}
			} else {
				$city = $ex[0];
				if ($continent != L10n::t('Miscellaneous')) {
					$o .= '</optgroup>';
					$continent = L10n::t('Miscellaneous');
					$o .= '<optgroup label="' . L10n::t($continent) . '">';
				}
			}<commit_msg>Fix self warning in Util\Temporal<commit_after><?php

/**
 * @file src/Util/Temporal.php
 */

namespace Friendica\Util;

use DateTime;
use DateTimeZone;
use Friendica\Core\Config;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;

require_once 'boot.php';
require_once 'include/text.php';

/**
 * @brief Temporal class
 */
class Temporal
{
	/**
	 * @brief Two-level sort for timezones.
	 *
	 * @param string $a
	 * @param string $b
	 * @return int
	 */
	private static function timezoneCompareCallback($a, $b)
	{
		if (strstr($a, '/') && strstr($b, '/')) {
			if (L10n::t($a) == L10n::t($b)) {
				return 0;
			}
			return (L10n::t($a) < L10n::t($b)) ? -1 : 1;
		}

		if (strstr($a, '/')) {
			return -1;
		} elseif (strstr($b, '/')) {
			return 1;
		} elseif (L10n::t($a) == L10n::t($b)) {
			return 0;
		}

		return (L10n::t($a) < L10n::t($b)) ? -1 : 1;
	}

	/**
	 * @brief Emit a timezone selector grouped (primarily) by continent
	 *
	 * @param string $current Timezone
	 * @return string Parsed HTML output
	 */
	public static function getTimezoneSelect($current = 'America/Los_Angeles')
	{
		$timezone_identifiers = DateTimeZone::listIdentifiers();

		$o = '<select id="timezone_select" name="timezone">';

		usort($timezone_identifiers, [__CLASS__, 'timezoneCompareCallback']);
		$continent = '';
		foreach ($timezone_identifiers as $value) {
			$ex = explode("/", $value);
			if (count($ex) > 1) {
				if ($ex[0] != $continent) {
					if ($continent != '') {
						$o .= '</optgroup>';
					}
					$continent = $ex[0];
					$o .= '<optgroup label="' . L10n::t($continent) . '">';
				}
				if (count($ex) > 2) {
					$city = substr($value, strpos($value, '/') + 1);
				} else {
					$city = $ex[1];
				}
			} else {
				$city = $ex[0];
				if ($continent != L10n::t('Miscellaneous')) {
					$o .= '</optgroup>';
					$continent = L10n::t('Miscellaneous');
					$o .= '<optgroup label="' . L10n::t($continent) . '">';
				}
			}
{'fraction_non_alphanumeric': 0.2119325551232166, 'fraction_numerical': 0.021271076523994813, 'mean_word_length': 3.0847457627118646, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4473481', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1457, 'n_words': 310}