Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 151... Línea 151...
151
            return $tz;
151
            return $tz;
152
        }
152
        }
Línea 153... Línea 153...
153
 
153
 
154
        // Is server timezone usable?
154
        // Is server timezone usable?
155
        if (isset($CFG->timezone) and !is_numeric($CFG->timezone)) {
155
        if (isset($CFG->timezone) and !is_numeric($CFG->timezone)) {
156
            $result = @timezone_open($CFG->timezone); // Hide notices if invalid.
156
            $result = timezone_open($CFG->timezone); // Hide notices if invalid.
157
            if ($result !== false) {
157
            if ($result !== false) {
158
                return $result->getName();
158
                return $result->getName();
159
            }
159
            }
Línea 317... Línea 317...
317
     */
317
     */
318
    public static function phpunit_override_default_php_timezone($tz) {
318
    public static function phpunit_override_default_php_timezone($tz) {
319
        if (!defined('PHPUNIT_TEST')) {
319
        if (!defined('PHPUNIT_TEST')) {
320
            throw new coding_exception('core_date::phpunit_override_default_php_timezone() must be used only from unit tests');
320
            throw new coding_exception('core_date::phpunit_override_default_php_timezone() must be used only from unit tests');
321
        }
321
        }
322
        $result = timezone_open($tz ?? ''); // This triggers error if $tz invalid.
322
        $result = @timezone_open($tz ?? ''); // This triggers error if $tz invalid.
323
        if ($result !== false) {
323
        if ($result !== false) {
324
            self::$defaultphptimezone = $tz;
324
            self::$defaultphptimezone = $tz;
325
        } else {
325
        } else {
326
            self::$defaultphptimezone = 'Australia/Perth';
326
            self::$defaultphptimezone = 'Australia/Perth';
327
        }
327
        }
Línea 739... Línea 739...
739
        $locale = preg_replace('/[^\w-].*$/', '', $locale);
739
        $locale = preg_replace('/[^\w-].*$/', '', $locale);
Línea 740... Línea 740...
740
 
740
 
741
        $intl_formats = [
741
        $intl_formats = [
742
          '%a' => 'EEE',	// An abbreviated textual representation of the day	Sun through Sat
742
          '%a' => 'EEE',	// An abbreviated textual representation of the day	Sun through Sat
743
          '%A' => 'EEEE',	// A full textual representation of the day	Sunday through Saturday
-
 
744
          '%b' => 'MMM',	// Abbreviated month name, based on the locale	Jan through Dec
-
 
745
          '%B' => 'MMMM',	// Full month name, based on the locale	January through December
-
 
746
          '%h' => 'MMM',	// Abbreviated month name, based on the locale (an alias of %b)	Jan through Dec
743
          '%A' => 'EEEE',	// A full textual representation of the day	Sunday through Saturday
Línea -... Línea 744...
-
 
744
        ];
747
        ];
745
 
-
 
746
        $originalformat = $format;
-
 
747
        $intl_formatter = function (DateTimeInterface $timestamp, string $format) use (
-
 
748
            $intl_formats,
748
 
749
            $locale,
749
        $intl_formatter = function (DateTimeInterface $timestamp, string $format) use ($intl_formats, $locale) {
750
            $originalformat,
750
 
751
        ) {
751
          // Map IANA timezone DB names (used by PHP) to those used internally by the "intl" extension. The extension uses its
752
          // Map IANA timezone DB names (used by PHP) to those used internally by the "intl" extension. The extension uses its
752
          // own data based on ICU timezones, which may not necessarily be in-sync with IANA depending on the version installed
753
          // own data based on ICU timezones, which may not necessarily be in-sync with IANA depending on the version installed
753
          // on the local system. See: https://unicode-org.github.io/icu/userguide/datetime/timezone/#updating-the-time-zone-data
754
          // on the local system. See: https://unicode-org.github.io/icu/userguide/datetime/timezone/#updating-the-time-zone-data
754
          $tz = $timestamp->getTimezone();
755
          $tz = $timestamp->getTimezone();
755
          $intltz = IntlTimeZone::fromDateTimeZone($tz);
756
          $intltz = IntlTimeZone::fromDateTimeZone($tz);
756
          if ($intltz === null) {
757
          if ($intltz === null) {
-
 
758
              // Where intl doesn't know about a recent timezone, map it to an equivalent existing zone.
757
              // Where intl doesn't know about a recent timezone, map it to an equivalent existing zone.
759
              $intltzname = strtr($tz->getName(), [
758
              $intltzname = strtr($tz->getName(), [
760
                  'America/Coyhaique' => 'America/Santiago',
759
                  'America/Ciudad_Juarez' => 'America/Denver',
761
                  'America/Ciudad_Juarez' => 'America/Denver',
760
                  'America/Nuuk' => 'America/Godthab',
762
                  'America/Nuuk' => 'America/Godthab',
761
                  'Europe/Kyiv' => 'Europe/Kiev',
763
                  'Europe/Kyiv' => 'Europe/Kiev',
Línea 787... Línea 789...
787
            case '%X':
789
            case '%X':
788
              $date_type = IntlDateFormatter::NONE;
790
              $date_type = IntlDateFormatter::NONE;
789
              $time_type = IntlDateFormatter::MEDIUM;
791
              $time_type = IntlDateFormatter::MEDIUM;
790
              break;
792
              break;
Línea -... Línea 793...
-
 
793
 
-
 
794
            case "%B":
-
 
795
            case "%b":
-
 
796
            case "%h":
-
 
797
                // Check for any day (%d, or %e) in the string.
-
 
798
                if (preg_match('/%[de]/', $originalformat)) {
-
 
799
                    // The day is present so use the standard format.
-
 
800
                    $pattern = $format === '%B' ? 'MMMM' : 'MMM';
-
 
801
                } else {
-
 
802
                    // The day is not present so use the stand-alone format.
-
 
803
                    $pattern = $format === '%B' ? 'LLLL' : 'LLL';
-
 
804
                }
-
 
805
                break;
791
 
806
 
792
            default:
807
            default:
793
              $pattern = $intl_formats[$format];
808
              $pattern = $intl_formats[$format];
Línea 794... Línea 809...
794
          }
809
          }
Línea 802... Línea 817...
802
          //  in formatted strings.
817
          //  in formatted strings.
803
          // To adjust for this, a custom calendar can be supplied with a cutover date arbitrarily far in the past.
818
          // To adjust for this, a custom calendar can be supplied with a cutover date arbitrarily far in the past.
804
          $calendar = IntlGregorianCalendar::createInstance($intltz);
819
          $calendar = IntlGregorianCalendar::createInstance($intltz);
805
          $calendar->setGregorianChange(PHP_INT_MIN);
820
          $calendar->setGregorianChange(PHP_INT_MIN);
Línea -... Línea 821...
-
 
821
 
-
 
822
          // We need to account for invalid locales here in recent PHP versions, and ensure we catch errors and switch
-
 
823
          // back to a default value where an invalid locale is provided.
806
 
824
          try {
-
 
825
              $formatter = new IntlDateFormatter($locale, $date_type, $time_type, $intltz, $calendar, $pattern);
-
 
826
              $result = $formatter->format($timestamp);
-
 
827
          } catch (Error $e) {
-
 
828
              $formatter = new IntlDateFormatter(null, $date_type, $time_type, $intltz, $calendar, $pattern);
-
 
829
              $result = $formatter->format($timestamp);
-
 
830
          }
-
 
831
 
807
          return (new IntlDateFormatter($locale, $date_type, $time_type, $intltz, $calendar, $pattern))->format($timestamp);
832
          return $result;
Línea 808... Línea 833...
808
        };
833
        };
809
 
834
 
810
        // Same order as https://www.php.net/manual/en/function.strftime.php
835
        // Same order as https://www.php.net/manual/en/function.strftime.php