Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 59... Línea 59...
59
    {
59
    {
60
        // Only consider formats with leading brackets as valid duration formats (e.g. "[hh]:mm", "[mm]:ss", etc.):
60
        // Only consider formats with leading brackets as valid duration formats (e.g. "[hh]:mm", "[mm]:ss", etc.):
61
        return 1 === preg_match('/^(\[hh?](:mm(:ss)?)?|\[mm?](:ss)?|\[ss?])$/', $excelFormat);
61
        return 1 === preg_match('/^(\[hh?](:mm(:ss)?)?|\[mm?](:ss)?|\[ss?])$/', $excelFormat);
62
    }
62
    }
Línea 63... Línea 63...
63
 
63
 
64
    public static function toPHPDateIntervalFormat(string $excelDateFormat, ?string &$startUnit = null): string
64
    public static function toPHPDateIntervalFormat(string $excelDateFormat, string &$startUnit): string
65
    {
65
    {
66
        $startUnit = null;
66
        $startUnitStarted = false;
67
        $phpFormatParts = [];
67
        $phpFormatParts = [];
68
        $formatParts = explode(':', str_replace(['[', ']'], '', $excelDateFormat));
68
        $formatParts = explode(':', str_replace(['[', ']'], '', $excelDateFormat));
-
 
69
        foreach ($formatParts as $formatPart) {
69
        foreach ($formatParts as $formatPart) {
70
            if (false === $startUnitStarted) {
-
 
71
                $startUnit = $formatPart;
-
 
72
                $startUnitStarted = true;
70
            $startUnit ??= $formatPart;
73
            }
71
            $phpFormatParts[] = self::dateIntervalFormats[$formatPart];
74
            $phpFormatParts[] = self::dateIntervalFormats[$formatPart];
Línea 72... Línea 75...
72
        }
75
        }
73
 
76
 
74
        // Add the minus sign for potential negative durations:
77
        // Add the minus sign for potential negative durations:
Línea 75... Línea 78...
75
        return '%r'.implode(':', $phpFormatParts);
78
        return '%r'.implode(':', $phpFormatParts);
76
    }
79
    }
-
 
80
 
77
 
81
    public static function formatDateInterval(DateInterval $dateInterval, string $excelDateFormat): string
Línea 78... Línea 82...
78
    public static function formatDateInterval(DateInterval $dateInterval, string $excelDateFormat): string
82
    {
79
    {
83
        $startUnit = '';
80
        $phpFormat = self::toPHPDateIntervalFormat($excelDateFormat, $startUnit);
84
        $phpFormat = self::toPHPDateIntervalFormat($excelDateFormat, $startUnit);