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

Why is Carbon used in the Eloquent model? #1408

Closed
jenssegers opened this Issue May 25, 2013 · 3 comments

Comments

Projects
None yet
3 participants
@jenssegers
Contributor

jenssegers commented May 25, 2013

While reading through the Eloquent model code I noticed that Carbon is used to convert strings to dates. But I don't see the advantage since only methods are used that are also available in the DateTime class.

Carbon::createFromTimestamp($value);
// vs
DateTime::createFromFormat('U', $value);

and:

Carbon::createFromFormat('Y-m-d', $value);
// vs
DateTime::createFromFormat('Y-m-d', $value);

Or am I missing something else?

@deefour

This comment has been minimized.

Show comment
Hide comment
@deefour

deefour May 25, 2013

Contributor

Eloquent serves up Carbon for datetime and timestamp columns. By default it will serve up Carbon for the created_at, updated_at, and deleted_at columns. You can customize this in your models extending Eloquent\Model.

Carbon\Carbon extends \DateTime, so there is no loss of functionality by using Carbon in favor of DateTime, only more benefit/flexibility.

In the specific case you're referring to with createFromFormat, Carbon overrides DateTime's implementation. There is a whole portion of the README devoted to the additional functionality Carbon's implementation provides.

Here is the original proposal.

Contributor

deefour commented May 25, 2013

Eloquent serves up Carbon for datetime and timestamp columns. By default it will serve up Carbon for the created_at, updated_at, and deleted_at columns. You can customize this in your models extending Eloquent\Model.

Carbon\Carbon extends \DateTime, so there is no loss of functionality by using Carbon in favor of DateTime, only more benefit/flexibility.

In the specific case you're referring to with createFromFormat, Carbon overrides DateTime's implementation. There is a whole portion of the README devoted to the additional functionality Carbon's implementation provides.

Here is the original proposal.

@jenssegers

This comment has been minimized.

Show comment
Hide comment
@jenssegers

jenssegers May 25, 2013

Contributor

I know that Carbon extends the DateTime class, but it does not seem worth using it in this class.

Maybe it is better to rely on the original DateTime in a database class and let users use external libraries in their models?

Contributor

jenssegers commented May 25, 2013

I know that Carbon extends the DateTime class, but it does not seem worth using it in this class.

Maybe it is better to rely on the original DateTime in a database class and let users use external libraries in their models?

@taylorotwell

This comment has been minimized.

Show comment
Hide comment
@taylorotwell

taylorotwell May 25, 2013

Member

Carbon provides some convenience methods on top of DateTime.

Member

taylorotwell commented May 25, 2013

Carbon provides some convenience methods on top of DateTime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment