AzureStorageExplorer icon indicating copy to clipboard operation
AzureStorageExplorer copied to clipboard

Nanoseconds are not sorted correctly

Open webbiscuit opened this issue 1 year ago • 2 comments

Preflight Checklist

Storage Explorer Version

1.32.1

Regression From

No response

Architecture

x64

Storage Explorer Build Number

20231114.10

Platform

macOS

OS Version

macOs 14.2.1

Bug Description

Datetimes are not sorted correctly at the nanosecond level: image The screenshot is a sort from latest to oldest times. The top 3 times are in the wrong order. It looks like nanoseconds are being ignored in the sorting.

Steps to Reproduce

Launch Storage Explorer Find a table with timestamps close together Click the column to sort ascending/descending See the timestamps out of order

Actual Experience

Launch Storage Explorer Find a table with timestamps close together Click the column to sort ascending/descending Timestamps are out of order

Expected Experience

Launch Storage Explorer Find a table with timestamps close together Click the column to sort ascending/descending Timestamps are in order

Additional Context

No response

webbiscuit avatar Jan 19 '24 16:01 webbiscuit

The problem with timestamps is that they are converted to JavaScript Date objects for sorting. Date objects only have millisecond precision. Hence why timestamps that differ by a few nanoseconds may be sorted in the wrong order.

However, it's possible we can get away with string comparisons to get around the precision issue. The strings themselves are ISO Zulu strings, so we shouldn't have to worry about number/letter comparisons messing the order up.

craxal avatar Jan 19 '24 18:01 craxal

String comparisons are a bit risky, as it's difficult to predict how locales will order certain characters.

The Temporal API provides the necessary nanosecond precision and works beautifully, but comparing Temporal objects is very slow compared to Date objects.

I think the optimal solution here is to use a combination of the two. Since it's less likely for DateTime values to differ by less than a millisecond, we can take advantage of the faster comparison of Date objects. If the Date objects are the same, only then will we parse and compare the values as Temporal objects.

craxal avatar Mar 05 '24 19:03 craxal