Giter Site home page Giter Site logo

Comments (7)

driesvints avatar driesvints commented on June 18, 2024

This is a change in Carbon v3. Please see the docs here: https://carbon.nesbot.com/docs/#api-carbon-3

from framework.

driesvints avatar driesvints commented on June 18, 2024

We also recommend to always call createFromTimestamp with 2 parameters (i.e. explicitly pass a timezone)

from framework.

NiroDeveloper avatar NiroDeveloper commented on June 18, 2024

Yes, this means that you can only give Carbon instances to laravel with the server-timezone, which is very confusing.
Instead laravel should regonize the different timezone and convert it into the configured server timezone.

@driesvints Assume that i have a REST API and the client sends his current timestamp as UTC.
Now i want to save this timestamp into the database ... it is fully correct that the Carbon instance is in the UTC Timezone, but laravel ignores this.

from framework.

driesvints avatar driesvints commented on June 18, 2024

I don't know what you want us to do? We don't control this code, this is all Carbon.

from framework.

NiroDeveloper avatar NiroDeveloper commented on June 18, 2024

We could fix this by adding a if-statement to

public function castBinding($value)

public function castBinding($value)
{
   if ($value instanceof Carbon) {
       // The php date() function converts the timestamp into the server timezone.
       return date('Y-m-d H:i:s', $value->unix());
   }

   if ($value instanceof UnitEnum) {
       return $value instanceof BackedEnum ? $value->value : $value->name;
   }

   return $value;
}

Alternative we could read the app.timezone config or define a timezone in the database.connections config.
This will work for insert() only, for create() we have to also insert a "if" into HasAttribute->setAttribute()

This also makes the framework less dependent on external libs.

from framework.

driesvints avatar driesvints commented on June 18, 2024

I don't think we should do anything like that sorry. You should set the proper timezone as instructed by the Carbon docs.

from framework.

kylekatarnls avatar kylekatarnls commented on June 18, 2024

Yes, this means that you can only give Carbon instances to laravel with the server-timezone, which is very confusing.

No it does not mean that, on the contrary the Carbon v2 behavior was actually using the server-timezone and you can get the Carbon v2 behavior by using:

$myDatetime = Carbon::createFromTimestamp(1657996631, date_default_timezone_get());

So I'm actually puzzled how you could get a +0000 timezone previously when using Carbon 2 and would be interested to dig that deeper.

from framework.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.