Fix ROC date parsing for roster import
This commit is contained in:
@@ -348,7 +348,30 @@ class ImportMembersCommand extends Command
|
|||||||
|
|
||||||
if (is_numeric($value)) {
|
if (is_numeric($value)) {
|
||||||
$numeric = (float) $value;
|
$numeric = (float) $value;
|
||||||
if ($numeric > 10000) {
|
$digits = preg_replace('/\D/', '', (string) $numeric);
|
||||||
|
|
||||||
|
if (strlen($digits) === 6 || strlen($digits) === 7) {
|
||||||
|
$yearLength = strlen($digits) - 4;
|
||||||
|
$rocYear = (int) substr($digits, 0, $yearLength);
|
||||||
|
$month = (int) substr($digits, $yearLength, 2);
|
||||||
|
$day = (int) substr($digits, $yearLength + 2, 2);
|
||||||
|
$year = $rocYear + 1911;
|
||||||
|
|
||||||
|
if (checkdate($month, $day, $year)) {
|
||||||
|
return sprintf('%04d-%02d-%02d', $year, $month, $day);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen($digits) === 8) {
|
||||||
|
$year = (int) substr($digits, 0, 4);
|
||||||
|
$month = (int) substr($digits, 4, 2);
|
||||||
|
$day = (int) substr($digits, 6, 2);
|
||||||
|
if (checkdate($month, $day, $year)) {
|
||||||
|
return sprintf('%04d-%02d-%02d', $year, $month, $day);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($numeric > 0) {
|
||||||
return ExcelDate::excelToDateTimeObject($numeric)->format('Y-m-d');
|
return ExcelDate::excelToDateTimeObject($numeric)->format('Y-m-d');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -477,6 +500,10 @@ class ImportMembersCommand extends Command
|
|||||||
$update['birth_date'] = $birthDate;
|
$update['birth_date'] = $birthDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($birthDate && $member->birth_date && $this->isInvalidDate($member->birth_date)) {
|
||||||
|
$update['birth_date'] = $birthDate;
|
||||||
|
}
|
||||||
|
|
||||||
if ($gender && ! $member->gender) {
|
if ($gender && ! $member->gender) {
|
||||||
$update['gender'] = $gender;
|
$update['gender'] = $gender;
|
||||||
}
|
}
|
||||||
@@ -512,6 +539,20 @@ class ImportMembersCommand extends Command
|
|||||||
return $update;
|
return $update;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isInvalidDate(mixed $value): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$date = $value instanceof \DateTimeInterface ? $value : new \DateTime($value);
|
||||||
|
} catch (\Exception) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$year = (int) $date->format('Y');
|
||||||
|
$currentYear = (int) date('Y');
|
||||||
|
|
||||||
|
return $year < 1900 || $year > ($currentYear + 1);
|
||||||
|
}
|
||||||
|
|
||||||
protected function toPinyin(string $name): string
|
protected function toPinyin(string $name): string
|
||||||
{
|
{
|
||||||
// Simple romanization for email generation
|
// Simple romanization for email generation
|
||||||
|
|||||||
Reference in New Issue
Block a user