coresmart / persistencejs

persistence.js is an asynchronous Javascript database mapper library. You can use it in the browser, as well on the server (and you can share data models between them).
http://persistencejs.org
1.73k stars 240 forks source link

Persistence Sync Date #96

Open ball-hayden opened 11 years ago

ball-hayden commented 11 years ago

I'm having an issue with persistence.sync.js regarding dates.

I have set the server to send all dates as an Epoch based string as follows:

    $json = new \stdClass();

    foreach ($this as $key => $value) {
        if ($value instanceof \DateTime) {
            $json->$key = $value->format('U');
        } else {
            $json->$key = $value;
        }
    }
    return $json;

Looking at the data that is being sent, this is working as expected, with the date field being sent as an integer.
However, when persistence.sync.js reads the JSON data, the logged INSERT command is as follows:

INSERT INTO `mytable` (`text_field_a`, `text_field_b`, `text_field_c`, `date_field`, id) VALUES (?, ?, ?, ?, ?) ["TestA", "TestB", "TestC", NaN, "ABC049AC6EF144CF99FEFD52A8A47532"]

(note NaN value for date field)

Looking through the sync source, I can't work out where this is occurring as the correct integer value is being read in 'Step 3' (line 169). I'm guessing it's somewhere in persisting the data.

I'm using Chrome 22.0.1201.0

Any help would be appreciated.

Regards

Hayden