8000 Include milliseconds when sorting by time · Issue #978 · jarun/nnn · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Include milliseconds when sorting by time #978

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

Closed
gyvess opened this issue Apr 29, 2021 · 8 comments
Closed

Include milliseconds when sorting by time #978

gyvess opened this issue Apr 29, 2021 · 8 comments

Comments

@gyvess
Copy link
gyvess commented Apr 29, 2021

Linux Kernel 5.11.10
nnn v4.0
BTRFS

Long story short, I was trying to get sxiv to order pictures in the same way nnn presents them from newest to oldest. These are hundreds of images downloaded within seconds using wget2. I think nnn ignores milliseconds when sorting by time, and therefore is unable to match the order of something like ls --full-time -t.

For example, here is a list of milliseconds printed in the exact order nnn presents files from newest to oldest.

16:03:56.244992419
16:03:56.399992413
16:03:56.361992414
16:03:56.071992426
16:03:56.157992422
16:03:56.203992421
16:03:56.032992427
16:03:55.774992438
16:03:55.997992429
16:03:55.786992437
16:03:55.948992431

Now here is the correct order if the files are supposed to be newest to oldest.

16:03:56.399992413
16:03:56.361992414
16:03:56.244992419
16:03:56.203992421
16:03:56.157992422
16:03:56.071992426
16:03:56.032992427
16:03:55.997992429
16:03:55.948992431
16:03:55.786992437
16:03:55.774992438
@jarun
Copy link
Owner
jarun commented Apr 30, 2021

nnn considers up to nanoseconds. By default we use the modification time from stat. From man stat:

           struct stat {
               ...
               /* Since Linux 2.6, the kernel supports nanosecond
                  precision for the following timestamp fields.
                  For the details before Linux 2.6, see NOTES. */

               struct timespec st_atim;  /* Time of last access */
               struct timespec st_mtim;  /* Time of last modification */
               struct timespec st_ctim;  /* Time of last status change */
               ...
           };

The time comparison is done in entrycmp():

2513         if (cfg.timeorder) {
2514                 if (pb->t > pa->t)
2515                         return 1;
2516                 if (pb->t < pa->t)
2517                         return -1;
2518         }

Note that nnn can sort by access time and change time too based on user preference.

@jarun jarun closed this as completed Apr 30, 2021
@gyvess
Copy link
Author
gyvess commented Apr 30, 2021

I don't understand. Then why does nnn sort in the wrong order. My example was using modified time, which doesn't match ls -t sort. However, I also changed the time preference to access time and change time within nnn and neither sort within nnn matches ls -ut nor ls -ct respectively.

@jarun
Copy link
Owner
jarun commented Apr 30, 2021

I don't know why you are seeing this. I checked in /bin and saw the order is same for nnn and ls.

@gyvess
Copy link
Author
gyvess commented Apr 30, 2021

Interesting, because mine isn't. Guess I have to examine this ebuild next
21-04-30-032234_maim
.

@jarun
Copy link
Owner
jarun commented Apr 30, 2021

Confirm that you are not using sessions and it's retained. Check your nnn startup options also your system locale , filesystem (ext4 for me) etc.

My locale:

$ locale       
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_IN.UTF-8
LC_TIME=en_IN.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_IN.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_IN.UTF-8
LC_NAME=en_IN.UTF-8
LC_ADDRESS=en_IN.UTF-8
LC_TELEPHONE=en_IN.UTF-8
LC_MEASUREMENT=en_IN.UTF-8
LC_IDENTIFICATION=en_IN.UTF-8
LC_ALL=

My nnn compilation options:

sudo make CFLAGS=-march=corei7 O_NORL=1 O_NOMOUSE=1 O_NOBATCH=1 O_NOSSN=1 O_QSORT=1 O_NOUG=1 O_CKBOARD=1 O_NOX11=1 strip install

@gyvess
Copy link
Author
gyvess commented May 1, 2021

Ran without sessions, same thing. Recompiled without my arrow patch and without compilation options, same thing.

/bin is located on a drive using XFS and the original files I discovered this problem with are on another drive using BTRFS.

My locale:

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8

My nnn compilation options:

make -j32 -l32 O_NOMOUSE=1 O_CTX8=1 O_NERD=1

@jarun
Copy link
Owner
jarun commented May 1, 2021

And what are the program options you use to start nnn?

@jarun
Copy link
Owner
jarun commented May 1, 2021

I can reproduce this with the following script:

#!/bin/bash

today=$( date +%Y%m%d )   # or: printf -v today '%(%Y%m%d)T' -1
number=0

fname=$today.txt

while [ "$number" -le 20 ]; do
    printf -v fname '%s-%02d.txt' "$today" "$(( ++number ))"
    touch "$fname"
done

@jarun jarun reopened this May 1, 2021
@jarun jarun closed this as completed in 04e216a May 1, 2021
jarun added a commit that referenced this issue May 1, 2021
@jarun jarun mentioned this issue May 1, 2021
36 tasks
@jarun jarun mentioned this issue May 19, 2021
50 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Jun 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0