Comments (6)
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.
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.
Yeah, but I assume that's what you get on Unix systems anyway, right?
from mongodb-odm.
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.
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.
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)
- Cannot override the class metadata factory via configuration since 2.5.0 HOT 3
- Indices from sub classes always get re-created HOT 3
- The implementation of Countable on the CachingIterator is causing the UniqueEntityValidator to always fail HOT 2
- 2dsphere indexes get re-created everytime HOT 1
- Mapping validation does not validate targetDocument
- README link to API is broken HOT 1
- BC Break if the storeEmptyArray is not defined in the mapping HOT 8
- Add `dm` input option to commands that requires it
- GridFs HydratorException : Expected association field "metadata" to be of type "array", "object" received HOT 4
- Embedded Subset Pattern implementation HOT 2
- MongoDB-ODM & Spiral framework. HOT 1
- Update embed many attribute to empty array HOT 3
- Issues with the compatibility of getRepository() function in MongoDB DocumentManager and Persistence ManagerRegistry
- Document is insert and then updated during one flush operation HOT 4
- Saving documents with embedded collections and default storage strategy leads to inconsistent state between in memory objects and database HOT 1
- Duplicate objectToArray keys in AggregationOperatorsProviderTrait HOT 1
- Issue in flush When duplication index error occurs. HOT 1
- Proxy methods in CreateCommand may be obsolete
- Implement `skip-<feature>` options in CLI commands HOT 1
- Add CI workflow to check documentation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongodb-odm.