Anyone knows why `org.w3c.files.File.lastModified`...
# javascript
t
Anyone knows why
org.w3c.files.File.lastModified
it is declared as an
Int
in Kotlin? It returns the wrong value and I think it should be a
Long
. Also, if I use
kotlinx.datetime.Instant.fromEpochMilliseconds(file.lastModified.toLong())
the web browser hangs.
At the end I used this workaround. It's ugly but works, let me know if there is a better way, I would be thankful.
Copy code
val lastModified = (js("file.lastModified.toString()") as String).toLongOrNull()
if (lastModified != null) Instant.fromEpochMilliseconds(lastModified.toLong())
m
I think the file.lastModified property is a Javascript number type : Integers can only be represented without loss of precision in the range -2^53 + 1 to 2^53 - 1, inclusive (obtainable via Number.MIN_SAFE_INTEGER and Number.MAX_SAFE_INTEGER), because the mantissa can only hold 53 bits (including the leading 1). As per: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
In Kotlin/JS Long is handled using a Wrapper class, whereas other primitives use the JS native Number
t
It's
JsLong
:)
Latest declarations you can find in
kotlin-browser