robsonvn / laravel-couchdb

A CouchDB based Eloquent model and Query builder for Laravel
56 stars 28 forks source link

Default date format should be ISO 8601 #18

Open ecordani opened 6 years ago

ecordani commented 6 years ago

Hi, I'm building an API gateway with Lumen 5.4 (btw, it works!) and the database is feeded by an iOS application with Couchbase Lite library. The datetime format used in Model.php ('Y-m-d H:i:s') mimics the format used by MySql and is not in the standard format used in CouchDB (for example "2018-05-04T11:40:52.280Z"). Is there a reason for this decision? Thanks!

ecordani commented 6 years ago

Ok, I found a way to override the default format. I've added the following code snippet in my model definition:

protected function serializeDate(\DateTimeInterface $date) { return $date->format('c'); }

robsonvn commented 6 years ago

Unfortunately, this was a bad decision I had when I was building the application which I completely regret.

The default date format should be ISO 8601 so I am reopening and renaming this issue to fix it later.

You can define your personal date format on your model, though.

protected $dateFormat = 'l jS \of F Y h:i:s A';