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

Wrong format date when created #310

Closed
projct1 opened this issue Sep 20, 2017 · 7 comments
Closed

Wrong format date when created #310

projct1 opened this issue Sep 20, 2017 · 7 comments
Labels
invalid Not applicable or incorrect wontfix Will not be addressed

Comments

@projct1
Copy link

projct1 commented Sep 20, 2017

Q A
Bug? no
New Feature? no
Framework Laravel
Framework version 5.5.3
Package version 4.1.2
PHP version 7.0.1

Actual Behaviour

Saving date field with format Y-m-d 00:00:00

Expected Behaviour

Saving date field with format Y-m-d

Steps to Reproduce

Create any record, having date field.

@quetzyg
Copy link
Contributor

quetzyg commented Sep 20, 2017

This doesn't seem to be an issue with the package.

@projct1
Copy link
Author

projct1 commented Sep 20, 2017

MySQL field type is date,
In model $dates = ['date'];

class AuditingListener
{
    public function handle(Auditing $event)
    {
        dump($event->model->date); //already wrong value 2017-01-10 00:00:00
    }
}

Order::create([
    'date' => Request::input('date'); //2017-01-10
]);

After this, new_values has 2017-01-10 00:00:00

@quetzyg
Copy link
Contributor

quetzyg commented Sep 20, 2017

That's an Eloquent issue, which has been documented in the troubleshooting section.

@quetzyg quetzyg closed this as completed Sep 20, 2017
@quetzyg quetzyg added invalid Not applicable or incorrect wontfix Will not be addressed labels Sep 20, 2017
@projct1
Copy link
Author

projct1 commented Sep 20, 2017

Can we solve this problem automatically at core level?
Before or after calling method transformAudit run code like that:

if (isset($this->casts[$key]) && $this->casts[$key] == 'date') {
    return Carbon::parse($value)->toDateString();
}

@projct1
Copy link
Author

projct1 commented Sep 20, 2017

Now have to use many crutches before save audit, for example:

if (isset($this->casts[$key]) && $this->casts[$key] == 'date') {
    return $value->toDateString();
}

And before output, for example:

if ($value instanceof \DateTime && $value->toTimeString() == '00:00:00') {
    return $value->toDateString();
}

@quetzyg
Copy link
Contributor

quetzyg commented Sep 20, 2017

Sorry, I'm not gonna fix upstream issues here. If they say it's an expected behaviour, we should keep it consistent. Bump the upstream issue and propose a fix there, not here.

@projct1
Copy link
Author

projct1 commented Sep 20, 2017

Ok ) Thank you for your responsiveness )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Not applicable or incorrect wontfix Will not be addressed
Projects
None yet
Development

No branches or pull requests

2 participants