Skip to content

Precision loss for NSDate #427

@wkornewald

Description

@wkornewald

When converting an Instant to NSDate and back to Instant the value is rounded to milliseconds. However, when testing I see microsecond precision after calling toNSDate() and even when using NSDate.addTimeInterval() and also when instantiating a new NSDate() object. This doesn’t match what the docstring claims.

You probably only refer to the NSDateFormatter having a bug and dropping to millisecond precision? The rest of the NSDate API seems to work fine with microsecond precision though, so it makes no sense to be lossy in Kotlin.

At the Kotlin level, the loss in precision only happens in the NSDate.toKotlinInstant() extension function. Could you please fix this function to preserve microsecond precision instead of millisecond precision - consistent with the test result?

Also, the toNSDate() function doesn't round the last (microsecond) digit, which is probably a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions