Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TheOneoftheother opened this issue Jun 23, 2023 · 2 comments

Comments

@TheOneoftheother
Copy link

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
Copy link
Contributor

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
Copy link

mumpitzstuff commented Jul 14, 2024

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);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants