Published on : 2026-04-29 10:00
       
       One of the small things that always bothered me in slstatus was 
       the default uptime format. It works, but it is a bit too plain for
       my taste. I wanted something more human-readable: instead of hours 
       and minutes, I wanted uptime displayed as days, hours, and minutes 
       when and if the system's uptime is more than 24 hours.
       
       Example
       ‾‾‾‾‾‾‾
        * 5h 23m
        * 1 day, 4h 12m
        * 3 days, 7h 55m
       
       The tweaking
       ‾‾‾‾‾‾‾‾‾‾‾‾
       The idea is simple: check whether the system has been up for more 
       than 24 hours. If so, split the total hours into days and 
       remaining hours.
       
       First of all we have to create the days variable as an unsigned 
       integer (unsigned means that values cannot be negative). For this 
       we have to modify the line:
       
           uintmax_t h, m;
       
       and add the day variable d:
       
           uintmax_t d, h, m;
       
       Now that we have the days variable (d) we should also do some math 
       and calculate it. We know a day has 24 hours. 1 hour has 3600 
       seconds. This mean that a day has 24 * 3600 seconds which equals 
       to 86400 seconds.
       
       Now that the math is sorted it's time to apply it:
       
           d = uptime.tv_sec / 86400;
       
       This just divides the number of seconds the system is up to 86400. 
       We now have days but we're not done yet. Add this line above:
       
           h = uptime.tv_sec / 3600;
           m = uptime.tv_sec % 3600 / 60;
       
       Oh my god, we're almost done. Only this line remains:
       
           return bprintf("%juh %jum", h, m);
       
       It's time to modify it with our new logic and math. We do have 
       days but if we leave it as is the output will be something like:
       
           2 days, 49h 3m
       
       instead of
       
           2 days, 1h 3m
       
       We need to calculate the number of hours remaining if days are 
       present:
       
           if (d > 0) {
               h = h - ( d * 24);
               return bprintf("%ju %s, %juh %jum",
               d, d==1 ? "day" : "days", h, m);
               ## Make sure the 2 lines are just 1 line ##
               ## gopher only allows 70 chars on 1 line ##
           } else {
               return bprintf("%juh %jum", h, m);
           }
       
       See what we did there ? If days (d) is greater than 0 means we 
       have days present. Hours (h) becomes number of hours (h) minus 
       number of days (d) times 24. This means that, if we have 49 hours 
       total uptime, number of days (d) is 2 and hours (h) becomes 1 
       instead of 49:
       
           49 - ( 2 * 24 ) = 49 - 48 = 1
       
       We have some more magik there as well because of my OCD. Instead 
       of just showing 2d, 1h 3m I opted to show "day" or "days" 
       depending on whever days is 1 or more than 1. The logic is in:
       
           d==1 ? "day" : "days");
       
       If days (d) is not present we stick to the default output of 
       uptime.c which is:
       
           return bprintf("%juh %jum", h, m);
       
       I rambled a lot trying to explain simple tweaks, time to stop :-). 
       You can see, by looking at the original uptime.c below and the 
       tweaked one, that the changes are small but awesome.
       
       Original uptime.c
       ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
       
 (TXT) Original uptime.c
       
       Tweaked uptime.c
       ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
 (TXT) Tweaked uptime.c
       
       Why bother?
       ‾‾‾‾‾‾‾‾‾‾‾
       This is a tiny patch, but it makes uptime much easier to scan in 
       a status bar. Large hour counts like 127h are technically fine, 
       but not very intuitive. That is one of the joys of suckless tools: 
       tiny source code, tiny patches, and behavior exactly how you want.
       
 (HTM) slstatus home page
 (HTM) slstatus source
       
       Screenshot
       ‾‾‾‾‾‾‾‾‾‾
       I almost forgot. Here's a screenshot of my slstatus on my ROG 
       laptop with almost 2 days uptime 👏.
       
 (IMG)  slstatus on ROG laptop
       
 (DIR)  Back to my phlog