ReallySmallSoftware / cordova-plugin-firestore

A Google Firebase Firestore plugin to enable realtime synchronisation between app and cloud and automatically handle limited connectivity.
Other
22 stars 10 forks source link

[Bug][Android] Dates are being incorrectly unwrapped #37

Open ebhsgit opened 2 years ago

ebhsgit commented 2 years ago

Expected Behavior

Correct date value is parsed

Actual Behavior

The left most number is lost, causing incorrect Date value

Steps to Reproduce the Problem

async add(json: {}) {
   const db = await Firestore.initialise({})
   db.get().collection("path").add(json)
}

add({
   date: new Date(0)
})

running the above code will generate an exception

Error processing collection add in thread
    java.lang.NumberFormatException: For input string: ""
        at java.lang.Long.parseLong(Long.java:606)
        at java.lang.Long.parseLong(Long.java:636)
        at uk.co.reallysmall.cordova.plugin.firestore.JSONDateWrapper.unwrapDate(JSONDateWrapper.java:34)
        at uk.co.reallysmall.cordova.plugin.firestore.JSONHelper.fromJSON(JSONHelper.java:83)
        at uk.co.reallysmall.cordova.plugin.firestore.JSONHelper.toSettableMapInternal(JSONHelper.java:119)
        at uk.co.reallysmall.cordova.plugin.firestore.JSONHelper.toSettableJSONInternal(JSONHelper.java:113)
        at uk.co.reallysmall.cordova.plugin.firestore.JSONHelper.fromJSON(JSONHelper.java:98)
        at uk.co.reallysmall.cordova.plugin.firestore.CollectionAddHandler.handle(CollectionAddHandler.java:35)
        at uk.co.reallysmall.cordova.plugin.firestore.FirestorePlugin.execute(FirestorePlugin.java:73)
         ...
         ...

The reason is because the value is encoded as __DATE:0 JSONDateWrapper.unwrapDate() will strip 8 characters (prefixLength + 1), which return empty string.

The correct behaviour should be to strip 7 chars.

Specifications