GithubHelp home page GithubHelp logo

Comments (6)

avalanche123 avatar avalanche123 commented on June 30, 2024

Interesting issue
I would suggest to fix it with casting:

public function convertToDatabaseValue($value)
{
    if ($value instanceof \DateTime) {
        $value = $value->getTimestamp();
    }
    if (is_string($value)) {
        $value = strtotime($value);
    }
    return new \MongoDate((int) $value);
}

Jon, what do you think?

from mongodb-odm.

jseverson avatar jseverson commented on June 30, 2024

In your fix it seems like you change behavior though, now we ALWAYS get a mongodate where it seems like the old behavior we actually wanted to return null whenever $value was null (or $value was an invalid date)

from mongodb-odm.

avalanche123 avatar avalanche123 commented on June 30, 2024

Yeah, but I assume that's what you get on Unix systems anyway, right?

from mongodb-odm.

jseverson avatar jseverson commented on June 30, 2024

dunno, i'm on windows. :) i havent pushed this to our staging server and tested there yet. I've issued a pull request with my fix in it. feel free to adjust it to your code which also fixes the problem for me, but does actually change behavior. Before saving the form field the date shows as 1890 (because the date is empty in the database), however, after submitting the form the date has changed to 1970, so your change actually will change the date field value from null to 1970.

from mongodb-odm.

avalanche123 avatar avalanche123 commented on June 30, 2024

Yes, but unix timestamp starts somewhere in 1969. And I think if the value returned was null, I don't understand how your form still shows the correct value...

from mongodb-odm.

jwage avatar jwage commented on June 30, 2024

This is an old issue I think. It is fixed now. If it is a date before the epoch we have to store the date as a string formatted like this:

        $date = new \DateTime($value);
        return $date->format('c');

from mongodb-odm.

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.