Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle MongoDB date only #1

Open
nunomazer opened this issue Aug 1, 2017 · 0 comments
Open

Handle MongoDB date only #1

nunomazer opened this issue Aug 1, 2017 · 0 comments
Assignees

Comments

@nunomazer
Copy link
Contributor

Based on code:

use Jenssegers\Mongodb\Eloquent\Model;

class Etapa extends Model {
    protected $dates = ['data_inicio', 'data_termino'];

    public function getDataInicioAttribute($value) {
        return \Carbon\Carbon::createFromTimestamp($value->toDateTime()->getTimestamp())->timezone('UTC');
    }

    public function getDataTerminoAttribute($value) {
        return \Carbon\Carbon::createFromTimestamp($value->toDateTime()->getTimestamp())->timezone('UTC');
    }

    public function setDataInicioAttribute($value) {
        $value = \DateTime::createFromFormat('d/m/Y', $value, new \DateTimeZone('UTC'));
        $value->setTime(0, 0, 0);

        $this->attributes['data_inicio'] = new \MongoDB\BSON\UTCDateTime($value);
    }

    public function setDataTerminoAttribute($value) {
        $value = \DateTime::createFromFormat('d/m/Y', $value, new \DateTimeZone('UTC'));
        $value->setTime(0, 0, 0);

        $this->attributes['data_termino'] = new \MongoDB\BSON\UTCDateTime($value);
    }
}
@nunomazer nunomazer self-assigned this Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant