toniebox-reverse-engineering / teddy

With this tool you can dump existing files for the famous audio box or create custom ones.
246 stars 32 forks source link

Sort by date not working correctly - sort is numeric instead by timestamp #64

Open TheOneoftheother opened 1 year ago

TheOneoftheother commented 1 year ago

Sorting of this dates/times is done wrong.: Sorting within teddybench by date results in wrong order.

01.02.2023 22:49:14 01.02.2023 22:52:42

02.02.2023 01:10:12

02.06.2023 00:07:54

03.01.2023 23:30:50 03.03.2023 18:46:10

06.05.2023 18:48:28

08.02.2023 22:15:10 09.02.2023 00:54:48

10.03.2023 15:25:44

....

Sorting seems to be done numeric but not by timestamp.

To reproduce Adjust Modify and Create Timestamp of files according to above examples and sort by date. e.g. i ensured that both timestamps modify and Create are identical. for directory as for files.

steve8x8 commented 10 months ago

Just a quick thought: would it help to change the system's date representation to something that can be properly sorted, as in 2022-12-24?

mumpitzstuff commented 5 hours ago

The issue is caused by using the string representation of the DateTime object.

s1 = t1.FileInfo.CreationTime.ToString();
s2 = t2.FileInfo.CreationTime.ToString();

returnVal = String.Compare(s1, s2);

Could easily be fixed in my opinion by doing the following:

int returnVal = 0;

if (Characteristic != 2)
{
    returnVal = String.Compare(s1, s2);
}
else
{
    // do not use the string representation to avoid wrong sort results
    returnVal = DateTime.Compare(t1.FileInfo.CreationTime, t2.FileInfo.CreationTime);
}