Update value date agar bisa menerima format UTC
This commit is contained in:
parent
90ad785e49
commit
5c5d56b473
@ -280,10 +280,10 @@ class PatientModel extends Model {
|
||||
|
||||
private function transformPatientData(array $patient): array {
|
||||
$patient["Age"] = $this->calculateAgeFromBirthdate($patient["Birthdate"], $patient["DeathDateTime"]);
|
||||
$patient["Birthdate"] = $this->formatedDate($patient["Birthdate"]);
|
||||
$patient["CreateDate"] = $this->formatedDate($patient["CreateDate"]);
|
||||
$patient["DelDate"] = $this->formatedDate($patient["DelDate"]);
|
||||
$patient["DeathDateTime"] = $this->formatedDate($patient["DeathDateTime"]);
|
||||
// $patient["Birthdate"] = $this->formatedDate($patient["Birthdate"]);
|
||||
// $patient["CreateDate"] = $this->formatedDate($patient["CreateDate"]);
|
||||
// $patient["DelDate"] = $this->formatedDate($patient["DelDate"]);
|
||||
// $patient["DeathDateTime"] = $this->formatedDate($patient["DeathDateTime"]);
|
||||
$patient["BirthdateConversion"] = $this->formatedDateForDisplay($patient["Birthdate"]);
|
||||
$patient["LinkTo"] = $this->getLinkedPatients($patient['LinkTo']);
|
||||
$patient["Custodian"] = $this->getCustodian($patient['Custodian']);
|
||||
@ -344,19 +344,19 @@ class PatientModel extends Model {
|
||||
}
|
||||
|
||||
// Conversion Time to Format Y-m-d H:i
|
||||
private function formatedDate($dateString) {
|
||||
$date = \DateTime::createFromFormat('Y-m-d H:i', $dateString);
|
||||
// private function formatedDate($dateString) {
|
||||
// $date = \DateTime::createFromFormat('Y-m-d H:i', $dateString);
|
||||
|
||||
if (!$date) {
|
||||
$timestamp = strtotime($dateString);
|
||||
if ($timestamp) {
|
||||
return date('Y-m-d H:i', $timestamp);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// if (!$date) {
|
||||
// $timestamp = strtotime($dateString);
|
||||
// if ($timestamp) {
|
||||
// return date('Y-m-d H:i', $timestamp);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
return $date->format('Y-m-d H:i');
|
||||
}
|
||||
// return $date->format('Y-m-d H:i');
|
||||
// }
|
||||
|
||||
// Conversion Time to Format j M Y
|
||||
private function formatedDateForDisplay($dateString) {
|
||||
@ -385,17 +385,20 @@ class PatientModel extends Model {
|
||||
|
||||
// Preventif 0000-00-00
|
||||
private function isValidDateTime($datetime) {
|
||||
// Check datetime format
|
||||
$formats = ['Y-m-d', 'Y-m-d H:i:s'];
|
||||
try {
|
||||
// Kalau input hanya Y-m-d (tanpa jam)
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $datetime)) {
|
||||
$dt = \DateTime::createFromFormat('Y-m-d', $datetime);
|
||||
return $dt ? $dt->format('Y-m-d') : null; // hanya tanggal
|
||||
}
|
||||
|
||||
foreach ($formats as $format) {
|
||||
$dt = \DateTime::createFromFormat($format, $datetime);
|
||||
if ($dt !== false && $dt->format($format) === $datetime) {
|
||||
return $datetime;
|
||||
}
|
||||
// Selain itu (ISO 8601 atau datetime lain), format ke Y-m-d H:i:s
|
||||
$dt = new \DateTime($datetime);
|
||||
return $dt->format('Y-m-d H:i:s');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user