Giter VIP home page Giter VIP logo

Comments (4)

isometriq avatar isometriq commented on September 24, 2024

Also, by using "_sort=created_at", I would expect the dates to be ascending.
In my example, it is reversed.

from laravel-api-handler.

marcelgwerder avatar marcelgwerder commented on September 24, 2024

I really only translate created_at to ORDER BY created_at ASC and -created_at to ORDER BY created_at DESC. From there the sorting depends on your system and the datatypes used. On my MySQL 5.6 instance this works as expected for both datetime and timestamp fields.

from laravel-api-handler.

isometriq avatar isometriq commented on September 24, 2024

created_at

That's odd, it seems that the entry that is not in the right order has actually a 0000-00-00 00:00:00 value, but it gets the current date and time (not exactly the same perhaps because of the locale).

By looking at this I would say that all is fine and that the problem is the date/time being incorrectly interpreted. Maybe it's my MariaDB 10.1.13 installation ..I've heard about potential problem with MySQL 5.7 and zero-timestamps.

from laravel-api-handler.

isometriq avatar isometriq commented on September 24, 2024

Ok found the culprit i think, in my base Model class...

protected function asDateTime($value)
{
    if ($value == "0000-00-00 00:00:00") {
        return \Carbon\Carbon::create();
    }
    return parent::asDateTime($value); // TODO: Change the autogenerated stub
}

public function getCreatedAtAttribute($value) {
    return $value == "-0001-11-30 00:00:00" ? "0000-00-00 00:00:00" : $value;
}

public function getUpdatedAtAttribute($value) {
    return $value == "-0001-11-30 00:00:00" ? "0000-00-00 00:00:00" : $value;
}

By commenting, the value becomes

"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00"

and is now sorted correctly... so all his good!

from laravel-api-handler.

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.