@@ -36,10 +36,10 @@ abstract class Model extends \Illuminate\Database\Eloquent\Model {
3636 protected static $ resolver ;
3737
3838 /**
39- * Convert a DateTime to a storable string .
39+ * Convert a DateTime to a storable MongoDate object .
4040 *
4141 * @param DateTime|int $value
42- * @return string
42+ * @return MongoDate
4343 */
4444 public function fromDateTime ($ value )
4545 {
@@ -66,11 +66,13 @@ public function fromDateTime($value)
6666 */
6767 protected function asDateTime ($ value )
6868 {
69+ // Convert MongoDate to timestamp
6970 if ($ value instanceof MongoDate)
7071 {
7172 $ value = $ value ->sec ;
7273 }
7374
75+ // Convert timestamp to string for DateTime
7476 if (is_int ($ value ))
7577 {
7678 $ value = "@ $ value " ;
@@ -82,7 +84,7 @@ protected function asDateTime($value)
8284 /**
8385 * Get a fresh timestamp for the model.
8486 *
85- * @return DateTime
87+ * @return MongoDate
8688 */
8789 public function freshTimestamp ()
8890 {
@@ -195,13 +197,13 @@ public function setRawAttributes(array $attributes, $sync = false)
195197 {
196198 foreach ($ attributes as $ key => &$ value )
197199 {
198- // Convert MongoId
200+ // Convert MongoId to string
199201 if ($ value instanceof MongoId)
200202 {
201203 $ value = (string ) $ value ;
202204 }
203205
204- // Convert MongoDate
206+ // Convert MongoDate to string
205207 else if ($ value instanceof MongoDate)
206208 {
207209 $ value = $ this ->asDateTime ($ value )->format ('Y-m-d H:i:s ' );
0 commit comments