Completed
Push — master ( a907f1...ea97af )
by
unknown
36s queued 25s
created

Date   F

Complexity

Total Complexity 83

Size/Duplication

Total Lines 544
Duplicated Lines 0 %

Test Coverage

Coverage 99.48%

Importance

Changes 0
Metric Value
wmc 83
eloc 203
dl 0
loc 544
ccs 192
cts 193
cp 0.9948
rs 2
c 0
b 0
f 0

23 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultOrLocalTimezone() 0 3 1
A validateTimeZone() 0 10 4
A setDefaultTimezone() 0 11 2
A getDefaultTimezone() 0 3 1
A setExcelCalendar() 0 12 3
A getExcelCalendar() 0 3 1
A getDefaultTimezoneOrNull() 0 3 1
A isDateTimeFormat() 0 3 1
A formattedPHPToExcel() 0 33 5
A stringToExcel() 0 24 6
A roundMicroseconds() 0 7 3
A dateTimeToExcel() 0 11 1
A dayStringToNumber() 0 8 2
A convertIsoDate() 0 20 6
A formattedDateTimeFromTimestamp() 0 5 1
B isDateTime() 0 30 7
C isDateTimeFormatCode() 0 52 14
A excelToTimestamp() 0 6 1
A monthStringToNumber() 0 11 4
A timestampToExcel() 0 7 2
B excelToDateTimeObject() 0 44 10
A PHPToExcel() 0 11 5
A dateTimeFromTimestamp() 0 6 2

How to fix   Complexity   

Complex Class

Complex classes like Date often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Date, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Shared;
4
5
use DateTime;
6
use DateTimeInterface;
7
use DateTimeZone;
8
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
9
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
10
use PhpOffice\PhpSpreadsheet\Cell\Cell;
11
use PhpOffice\PhpSpreadsheet\Exception;
12
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
13
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
14
15
class Date
16
{
17
    /** constants */
18
    const CALENDAR_WINDOWS_1900 = 1900; //    Base date of 1st Jan 1900 = 1.0
19
    const CALENDAR_MAC_1904 = 1904; //    Base date of 2nd Jan 1904 = 1.0
20
21
    /**
22
     * Names of the months of the year, indexed by shortname
23
     * Planned usage for locale settings.
24
     *
25
     * @var string[]
26
     */
27
    public static array $monthNames = [
28
        'Jan' => 'January',
29
        'Feb' => 'February',
30
        'Mar' => 'March',
31
        'Apr' => 'April',
32
        'May' => 'May',
33
        'Jun' => 'June',
34
        'Jul' => 'July',
35
        'Aug' => 'August',
36
        'Sep' => 'September',
37
        'Oct' => 'October',
38
        'Nov' => 'November',
39
        'Dec' => 'December',
40
    ];
41
42
    /**
43
     * @var string[]
44
     */
45
    public static array $numberSuffixes = [
46
        'st',
47
        'nd',
48
        'rd',
49
        'th',
50
    ];
51
52
    /**
53
     * Base calendar year to use for calculations
54
     * Value is either CALENDAR_WINDOWS_1900 (1900) or CALENDAR_MAC_1904 (1904).
55
     */
56
    protected static int $excelCalendar = self::CALENDAR_WINDOWS_1900;
57
58
    /**
59
     * Default timezone to use for DateTime objects.
60
     */
61
    protected static ?DateTimeZone $defaultTimeZone = null;
62
63
    /**
64
     * Set the Excel calendar (Windows 1900 or Mac 1904).
65
     *
66
     * @param ?int $baseYear Excel base date (1900 or 1904)
67
     *
68
     * @return bool Success or failure
69
     */
70 9690
    public static function setExcelCalendar(?int $baseYear): bool
71
    {
72
        if (
73 9690
            ($baseYear === self::CALENDAR_WINDOWS_1900)
74 9690
            || ($baseYear === self::CALENDAR_MAC_1904)
75
        ) {
76 9690
            self::$excelCalendar = $baseYear;
77
78 9690
            return true;
79
        }
80
81 1
        return false;
82
    }
83
84
    /**
85
     * Return the Excel calendar (Windows 1900 or Mac 1904).
86
     *
87
     * @return int Excel base date (1900 or 1904)
88
     */
89 10167
    public static function getExcelCalendar(): int
90
    {
91 10167
        return self::$excelCalendar;
92
    }
93
94
    /**
95
     * Set the Default timezone to use for dates.
96
     *
97
     * @param null|DateTimeZone|string $timeZone The timezone to set for all Excel datetimestamp to PHP DateTime Object conversions
98
     *
99
     * @return bool Success or failure
100
     */
101 147
    public static function setDefaultTimezone($timeZone): bool
102
    {
103
        try {
104 147
            $timeZone = self::validateTimeZone($timeZone);
105 147
            self::$defaultTimeZone = $timeZone;
106 147
            $retval = true;
107 1
        } catch (PhpSpreadsheetException) {
108 1
            $retval = false;
109
        }
110
111 147
        return $retval;
112
    }
113
114
    /**
115
     * Return the Default timezone, or UTC if default not set.
116
     */
117 2341
    public static function getDefaultTimezone(): DateTimeZone
118
    {
119 2341
        return self::$defaultTimeZone ?? new DateTimeZone('UTC');
120
    }
121
122
    /**
123
     * Return the Default timezone, or local timezone if default is not set.
124
     */
125 1042
    public static function getDefaultOrLocalTimezone(): DateTimeZone
126
    {
127 1042
        return self::$defaultTimeZone ?? new DateTimeZone(date_default_timezone_get());
128
    }
129
130
    /**
131
     * Return the Default timezone even if null.
132
     */
133 147
    public static function getDefaultTimezoneOrNull(): ?DateTimeZone
134
    {
135 147
        return self::$defaultTimeZone;
136
    }
137
138
    /**
139
     * Validate a timezone.
140
     *
141
     * @param null|DateTimeZone|string $timeZone The timezone to validate, either as a timezone string or object
142
     *
143
     * @return ?DateTimeZone The timezone as a timezone object
144
     */
145 165
    private static function validateTimeZone($timeZone): ?DateTimeZone
146
    {
147 165
        if ($timeZone instanceof DateTimeZone || $timeZone === null) {
148 165
            return $timeZone;
149
        }
150 26
        if (in_array($timeZone, DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC))) {
151 25
            return new DateTimeZone($timeZone);
152
        }
153
154 1
        throw new PhpSpreadsheetException('Invalid timezone');
155
    }
156
157
    /**
158
     * @param mixed $value Converts a date/time in ISO-8601 standard format date string to an Excel
159
     *                         serialized timestamp.
160
     *                     See https://en.wikipedia.org/wiki/ISO_8601 for details of the ISO-8601 standard format.
161
     */
162 22
    public static function convertIsoDate(mixed $value): float|int
163
    {
164 22
        if (!is_string($value)) {
165 1
            throw new Exception('Non-string value supplied for Iso Date conversion');
166
        }
167
168 21
        $date = new DateTime($value);
169 21
        $dateErrors = DateTime::getLastErrors();
170
171 21
        if (is_array($dateErrors) && ($dateErrors['warning_count'] > 0 || $dateErrors['error_count'] > 0)) {
172 1
            throw new Exception("Invalid string $value supplied for datatype Date");
173
        }
174
175 20
        $newValue = self::dateTimeToExcel($date);
176 20
177
        if (preg_match('/^\s*\d?\d:\d\d(:\d\d([.]\d+)?)?\s*(am|pm)?\s*$/i', $value) == 1) {
178
            $newValue = fmod($newValue, 1.0);
179
        }
180 20
181 4
        return $newValue;
182
    }
183
184 20
    /**
185
     * Convert a MS serialized datetime value from Excel to a PHP Date/Time object.
186
     *
187
     * @param float|int $excelTimestamp MS Excel serialized date/time value
188
     * @param null|DateTimeZone|string $timeZone The timezone to assume for the Excel timestamp,
189
     *                                           if you don't want to treat it as a UTC value
190
     *                                           Use the default (UTC) unless you absolutely need a conversion
191
     *
192
     * @return DateTime PHP date/time object
193
     */
194
    public static function excelToDateTimeObject(float|int $excelTimestamp, null|DateTimeZone|string $timeZone = null): DateTime
195
    {
196
        $timeZone = ($timeZone === null) ? self::getDefaultTimezone() : self::validateTimeZone($timeZone);
197 2378
        if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_EXCEL) {
198
            if ($excelTimestamp < 1 && self::$excelCalendar === self::CALENDAR_WINDOWS_1900) {
199 2378
                // Unix timestamp base date
200 2378
                $baseDate = new DateTime('1970-01-01', $timeZone);
201 2355
            } else {
202
                // MS Excel calendar base dates
203 188
                if (self::$excelCalendar == self::CALENDAR_WINDOWS_1900) {
204
                    // Allow adjustment for 1900 Leap Year in MS Excel
205
                    $baseDate = ($excelTimestamp < 60) ? new DateTime('1899-12-31', $timeZone) : new DateTime('1899-12-30', $timeZone);
206 2178
                } else {
207
                    $baseDate = new DateTime('1904-01-01', $timeZone);
208 2082
                }
209
            }
210 98
        } else {
211
            $baseDate = new DateTime('1899-12-30', $timeZone);
212
        }
213
214 23
        if (is_int($excelTimestamp)) {
215
            if ($excelTimestamp >= 0) {
216
                return $baseDate->modify("+ $excelTimestamp days");
217 2378
            }
218 106
219 106
            return $baseDate->modify("$excelTimestamp days");
220
        }
221
        $days = floor($excelTimestamp);
222 1
        $partDay = $excelTimestamp - $days;
223
        $hms = 86400 * $partDay;
224 2300
        $microseconds = (int) round(fmod($hms, 1) * 1000000);
225 2300
        $hms = (int) floor($hms);
226 2300
        $hours = intdiv($hms, 3600);
227 2300
        $hms -= $hours * 3600;
228 2300
        $minutes = intdiv($hms, 60);
229 2300
        $seconds = $hms % 60;
230 2300
231 2300
        if ($days >= 0) {
232 2300
            $days = '+' . $days;
233
        }
234 2300
        $interval = $days . ' days';
235 2295
236
        return $baseDate->modify($interval)
237 2300
            ->setTime($hours, $minutes, $seconds, $microseconds);
238
    }
239 2300
240 2300
    /**
241
     * Convert a MS serialized datetime value from Excel to a unix timestamp.
242
     * The use of Unix timestamps, and therefore this function, is discouraged.
243
     * They are not Y2038-safe on a 32-bit system, and have no timezone info.
244
     *
245
     * @param float|int $excelTimestamp MS Excel serialized date/time value
246
     * @param null|DateTimeZone|string $timeZone The timezone to assume for the Excel timestamp,
247
     *                                               if you don't want to treat it as a UTC value
248
     *                                               Use the default (UTC) unless you absolutely need a conversion
249
     *
250
     * @return int Unix timetamp for this date/time
251
     */
252
    public static function excelToTimestamp($excelTimestamp, $timeZone = null): int
253
    {
254
        $dto = self::excelToDateTimeObject($excelTimestamp, $timeZone);
255 55
        self::roundMicroseconds($dto);
256
257 55
        return (int) $dto->format('U');
258 55
    }
259
260 55
    /**
261
     * Convert a date from PHP to an MS Excel serialized date/time value.
262
     *
263
     * @param mixed $dateValue PHP DateTime object or a string - Unix timestamp is also permitted, but discouraged;
264
     *    not Y2038-safe on a 32-bit system, and no timezone info
265
     *
266
     * @return false|float Excel date/time value
267
     *                                  or boolean FALSE on failure
268
     */
269
    public static function PHPToExcel(mixed $dateValue)
270
    {
271
        if ((is_object($dateValue)) && ($dateValue instanceof DateTimeInterface)) {
272 296
            return self::dateTimeToExcel($dateValue);
273
        } elseif (is_numeric($dateValue)) {
274 296
            return self::timestampToExcel($dateValue);
275 291
        } elseif (is_string($dateValue)) {
276 11
            return self::stringToExcel($dateValue);
277 10
        }
278 7
279 1
        return false;
280
    }
281
282 6
    /**
283
     * Convert a PHP DateTime object to an MS Excel serialized date/time value.
284
     *
285
     * @param DateTimeInterface $dateValue PHP DateTime object
286
     *
287
     * @return float MS Excel serialized date/time value
288
     */
289
    public static function dateTimeToExcel(DateTimeInterface $dateValue): float
290
    {
291
        $seconds = (float) sprintf('%d.%06d', $dateValue->format('s'), $dateValue->format('u'));
292 348
293
        return self::formattedPHPToExcel(
294 348
            (int) $dateValue->format('Y'),
295
            (int) $dateValue->format('m'),
296 348
            (int) $dateValue->format('d'),
297 348
            (int) $dateValue->format('H'),
298 348
            (int) $dateValue->format('i'),
299 348
            $seconds
300 348
        );
301 348
    }
302 348
303 348
    /**
304
     * Convert a Unix timestamp to an MS Excel serialized date/time value.
305
     * The use of Unix timestamps, and therefore this function, is discouraged.
306
     * They are not Y2038-safe on a 32-bit system, and have no timezone info.
307
     *
308
     * @param float|int|string $unixTimestamp Unix Timestamp
309
     *
310
     * @return false|float MS Excel serialized date/time value
311
     */
312
    public static function timestampToExcel($unixTimestamp): bool|float
313
    {
314
        if (!is_numeric($unixTimestamp)) {
315 28
            return false;
316
        }
317 28
318 1
        return self::dateTimeToExcel(new DateTime('@' . $unixTimestamp));
319
    }
320
321 27
    /**
322
     * formattedPHPToExcel.
323
     *
324
     * @return float Excel date/time value
325
     */
326
    public static function formattedPHPToExcel(int $year, int $month, int $day, int $hours = 0, int $minutes = 0, float|int $seconds = 0): float
327
    {
328
        if (self::$excelCalendar == self::CALENDAR_WINDOWS_1900) {
329 2771
            //
330
            //    Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel
331 2771
            //    This affects every date following 28th February 1900
332
            //
333
            $excel1900isLeapYear = true;
334
            if (($year == 1900) && ($month <= 2)) {
335
                $excel1900isLeapYear = false;
336 2702
            }
337 2702
            $myexcelBaseDate = 2415020;
338 244
        } else {
339
            $myexcelBaseDate = 2416481;
340 2702
            $excel1900isLeapYear = false;
341
        }
342 71
343 71
        //    Julian base date Adjustment
344
        if ($month > 2) {
345
            $month -= 3;
346
        } else {
347 2771
            $month += 9;
348 1835
            --$year;
349
        }
350 1754
351 1754
        //    Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
352
        $century = (int) substr((string) $year, 0, 2);
353
        $decade = (int) substr((string) $year, 2, 2);
354
        $excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myexcelBaseDate + $excel1900isLeapYear;
355 2771
356 2771
        $excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
357 2771
358
        return (float) $excelDate + $excelTime;
359 2771
    }
360
361 2771
    /**
362
     * Is a given cell a date/time?
363
     */
364
    public static function isDateTime(Cell $cell, mixed $value = null, bool $dateWithoutTimeOkay = true): bool
365
    {
366
        $result = false;
367 9
        $worksheet = $cell->getWorksheetOrNull();
368
        $spreadsheet = ($worksheet === null) ? null : $worksheet->getParent();
369 9
        if ($worksheet !== null && $spreadsheet !== null) {
370 9
            $index = $spreadsheet->getActiveSheetIndex();
371 9
            $selected = $worksheet->getSelectedCells();
372 9
373 9
            try {
374 9
                if ($value === null) {
375
                    $value = Functions::flattenSingleValue(
376
                        $cell->getCalculatedValue()
377 9
                    );
378 9
                }
379 9
                $result = is_numeric($value)
380 9
                    && self::isDateTimeFormat(
381 9
                        $worksheet->getStyle(
382 9
                            $cell->getCoordinate()
383 9
                        )->getNumberFormat(),
384 1
                        $dateWithoutTimeOkay
385
                    );
386
            } catch (Exception) {
387 9
                // Result is already false, so no need to actually do anything here
388 9
            }
389
            $worksheet->setSelectedCells($selected);
390
            $spreadsheet->setActiveSheetIndex($index);
391 9
        }
392
393
        return $result;
394
    }
395
396
    /**
397 9
     * Is a given NumberFormat code a date/time format code?
398
     */
399 9
    public static function isDateTimeFormat(NumberFormat $excelFormatCode, bool $dateWithoutTimeOkay = true): bool
400
    {
401
        return self::isDateTimeFormatCode((string) $excelFormatCode->getFormatCode(), $dateWithoutTimeOkay);
402
    }
403
404
    private const POSSIBLE_DATETIME_FORMAT_CHARACTERS = 'eymdHs';
405
    private const POSSIBLE_TIME_FORMAT_CHARACTERS = 'Hs'; // note - no 'm' due to ambiguity
406
407
    /**
408 99
     * Is a given number format code a date/time?
409
     */
410 99
    public static function isDateTimeFormatCode(string $excelFormatCode, bool $dateWithoutTimeOkay = true): bool
411
    {
412 29
        if (strtolower($excelFormatCode) === strtolower(NumberFormat::FORMAT_GENERAL)) {
413
            //    "General" contains an epoch letter 'e', so we trap for it explicitly here (case-insensitive check)
414 75
            return false;
415
        }
416 1
        if (preg_match('/[0#]E[+-]0/i', $excelFormatCode)) {
417
            //    Scientific format
418
            return false;
419
        }
420 75
421 75
        // Switch on formatcode
422 31
        $excelFormatCode = (string) NumberFormat::convertSystemFormats($excelFormatCode);
423
        if (in_array($excelFormatCode, NumberFormat::DATE_TIME_OR_DATETIME_ARRAY, true)) {
424
            return $dateWithoutTimeOkay || in_array($excelFormatCode, NumberFormat::TIME_OR_DATETIME_ARRAY);
425
        }
426 48
427 1
        //    Typically number, currency or accounting (or occasionally fraction) formats
428
        if ((str_starts_with($excelFormatCode, '_')) || (str_starts_with($excelFormatCode, '0 '))) {
429
            return false;
430
        }
431 47
        // Some "special formats" provided in German Excel versions were detected as date time value,
432 2
        // so filter them out here - "\C\H\-00000" (Switzerland) and "\D-00000" (Germany).
433
        if (str_contains($excelFormatCode, '-00000')) {
434 45
            return false;
435
        }
436 45
        $possibleFormatCharacters = $dateWithoutTimeOkay ? self::POSSIBLE_DATETIME_FORMAT_CHARACTERS : self::POSSIBLE_TIME_FORMAT_CHARACTERS;
437
        // Try checking for any of the date formatting characters that don't appear within square braces
438
        if (preg_match('/(^|\])[^\[]*[' . $possibleFormatCharacters . ']/i', $excelFormatCode)) {
439 31
            //    We might also have a format mask containing quoted strings...
440 7
            //        we don't want to test for any of our characters within the quoted blocks
441 7
            if (str_contains($excelFormatCode, '"')) {
442
                $segMatcher = false;
443 7
                foreach (explode('"', $excelFormatCode) as $subVal) {
444
                    //    Only test in alternate array entries (the non-quoted blocks)
445 7
                    $segMatcher = $segMatcher === false;
446 7
                    if (
447
                        $segMatcher
448 6
                        && (preg_match('/(^|\])[^\[]*[' . $possibleFormatCharacters . ']/i', $subVal))
449
                    ) {
450
                        return true;
451
                    }
452 1
                }
453
454
                return false;
455 29
            }
456
457
            return true;
458
        }
459 19
460
        // No date...
461
        return false;
462
    }
463
464
    /**
465
     * Convert a date/time string to Excel time.
466
     *
467
     * @param string $dateValue Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
468
     *
469 186
     * @return false|float Excel date/time serial value
470
     */
471 186
    public static function stringToExcel(string $dateValue): bool|float
472 27
    {
473
        if (strlen($dateValue) < 2) {
474 161
            return false;
475 154
        }
476
        if (!preg_match('/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2}([.]\d+)?)?)?$/iu', $dateValue)) {
477
            return false;
478 13
        }
479
480 13
        $dateValueNew = DateTimeExcel\DateValue::fromString($dateValue);
481 2
482
        if (!is_float($dateValueNew)) {
483
            return false;
484 12
        }
485 5
486 5
        if (str_contains($dateValue, ':')) {
487 1
            $timeValue = DateTimeExcel\TimeValue::fromString($dateValue);
488
            if (!is_float($timeValue)) {
489 5
                return false;
490
            }
491
            $dateValueNew += $timeValue;
492 12
        }
493
494
        return $dateValueNew;
495
    }
496
497
    /**
498
     * Converts a month name (either a long or a short name) to a month number.
499
     *
500
     * @param string $monthName Month name or abbreviation
501
     *
502 12
     * @return int|string Month number (1 - 12), or the original string argument if it isn't a valid month name
503
     */
504 12
    public static function monthStringToNumber(string $monthName)
505 12
    {
506 12
        $monthIndex = 1;
507 6
        foreach (self::$monthNames as $shortMonthName => $longMonthName) {
508
            if (($monthName === $longMonthName) || ($monthName === $shortMonthName)) {
509 12
                return $monthIndex;
510
            }
511
            ++$monthIndex;
512 6
        }
513
514
        return $monthName;
515
    }
516
517
    /**
518
     * Strips an ordinal from a numeric value.
519
     *
520
     * @param string $day Day number with an ordinal
521
     *
522 18
     * @return int|string The integer value with any ordinal stripped, or the original string argument if it isn't a valid numeric
523
     */
524 18
    public static function dayStringToNumber(string $day)
525 18
    {
526 15
        $strippedDayValue = (str_replace(self::$numberSuffixes, '', $day));
527
        if (is_numeric($strippedDayValue)) {
528
            return (int) $strippedDayValue;
529 3
        }
530
531
        return $day;
532 1048
    }
533
534 1048
    public static function dateTimeFromTimestamp(string $date, ?DateTimeZone $timeZone = null): DateTime
535 1048
    {
536
        $dtobj = DateTime::createFromFormat('U', $date) ?: new DateTime();
537 1048
        $dtobj->setTimeZone($timeZone ?? self::getDefaultOrLocalTimezone());
538
539
        return $dtobj;
540 10
    }
541
542 10
    public static function formattedDateTimeFromTimestamp(string $date, string $format, ?DateTimeZone $timeZone = null): string
543
    {
544 10
        $dtobj = self::dateTimeFromTimestamp($date, $timeZone);
545
546
        return $dtobj->format($format);
547
    }
548
549
    /**
550 666
     * Round the given DateTime object to seconds.
551
     */
552 666
    public static function roundMicroseconds(DateTime $dti): void
553 666
    {
554 666
        $microseconds = (int) $dti->format('u');
555 666
        $rounded = (int) round($microseconds, -6);
556 23
        $modify = $rounded - $microseconds;
557
        if ($modify !== 0) {
558
            $dti->modify(($modify > 0 ? '+' : '') . $modify . ' microseconds');
559
        }
560
    }
561
}
562