Skip to content

Commit 8dea0c0

Browse files
fix ignoring date format
1 parent b33b674 commit 8dea0c0

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Eloquent/DocumentModel.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function getQualifiedKeyName()
106106
*
107107
* @param mixed $value
108108
*/
109-
public function fromDateTime($value): UTCDateTime
109+
public function fromDateTime($value): UTCDateTime|string
110110
{
111111
// If the value is already a UTCDateTime instance, we don't need to parse it.
112112
if ($value instanceof UTCDateTime) {
@@ -117,7 +117,9 @@ public function fromDateTime($value): UTCDateTime
117117
if (! $value instanceof DateTimeInterface) {
118118
$value = parent::asDateTime($value);
119119
}
120-
120+
if (isset($this->dateFormat)) {
121+
return $value->format($this->getDateFormat());
122+
}
121123
return new UTCDateTime($value);
122124
}
123125

@@ -148,9 +150,6 @@ public function getDateFormat()
148150
/** @inheritdoc */
149151
public function freshTimestamp()
150152
{
151-
if (isset($this->dateFormat)) {
152-
return Date::now();
153-
}
154153
return new UTCDateTime(Date::now());
155154
}
156155

0 commit comments

Comments
 (0)