Gentoo Archives: gentoo-user

From: Sergio Polini <sp_rm_it@×××××.it>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Re: ls date was: Bizarre etc/cfg-update problem
Date: Sat, 07 Jan 2006 19:38:35
Message-Id: 200601072037.12339.sp_rm_it@yahoo.it
In Reply to: Re: [gentoo-user] Re: ls date was: Bizarre etc/cfg-update problem by Holly Bostick
1 Holly Bostick:
2 > > [...]
3 > > Sorry, couldn't help with the rest of your problem, but I think
4 > > it is assumed that ls will display the year only for files older
5 > > than a year old. Quite clever, in my opinion.
6 >
7 > OK, I see what you mean-- or maybe I don't:
8 > [...]
9 > I see that many files that are more than a year old then are
10 > followed by the year, but some are not, and some which are less
11 > than a year old are followed by a year.
12
13 Why bother?
14 Untar coreutils and look at src/ls.c:
15
16 static char const *long_time_format[2] =
17 {
18 /* strftime format for non-recent files (older than 6 months), in
19 -l output when --time-style=locale is specified. This should
20 contain the year, month and day (at least), in an order that is
21 understood by people in your locale's territory.
22 Please try to keep the number of used screen columns small,
23 because many people work in windows with only 80 columns. But
24 make this as wide as the other string below, for recent files.*/
25 N_("%b %e %Y"),
26 /* strftime format for recent files (younger than 6 months), in
27 -l output when --time-style=locale is specified. This should
28 contain the month, day and time (at least), in an order that is
29 understood by people in your locale's territory.
30 Please try to keep the number of used screen columns small,
31 because many people work in windows with only 80 columns. But
32 make this as wide as the other string above, for non-recent
33 files. */
34 N_("%b %e %H:%M")
35 };
36
37 > But even leaving aside the inconsistencies (only for the purposes of
38 > this discussion), this is not the behaviour I expect or in fact
39 > desire. I normally expect the year to be displayed whenever the
40 > current calendar year is different from that associated with the
41 > file-- thus, if the file was created in 2006, I would not expect the
42 > year to be shown, but if it was created in 2005, I would expect the
43 > year to be shown, whether or not the current date was one year or
44 > more from the month and day that the file was created.
45
46 The code you should change is here:
47
48 static void print_long_format (const struct fileinfo *f) {
49 char modebuf[12];
50 ........
51
52 if ((when_local = localtime (&when)))
53 {
54 time_t six_months_ago;
55 int recent;
56 char const *fmt;
57
58 /* If the file appears to be in the future, update the current
59 time, in case the file happens to have been modified since
60 the last time we checked the clock. */
61 if (current_time < when
62 || (current_time == when && current_time_ns < when_ns))
63 {
64 /* Note that get_current_time calls gettimeofday which, on some non-
65 compliant systems, clobbers the buffer used for localtime's result.
66 But it's ok here, because we use a gettimeofday wrapper that
67 saves and restores the buffer around the gettimeofday call. */
68 get_current_time ();
69 }
70
71 /* Consider a time to be recent if it is within the past six
72 months. A Gregorian year has 365.2425 * 24 * 60 * 60 ==
73 31556952 seconds on the average. Write this value as an
74 integer constant to avoid floating point hassles. */
75 six_months_ago = current_time - 31556952 / 2;
76 recent = (six_months_ago <= when
77 && (when < current_time
78 || (when == current_time && when_ns <= current_time_ns)));
79 fmt = long_time_format[recent];
80 ............
81 }
82
83 May be, you could add a command-line option ;-)
84
85 HTH
86 Sergio
87 --
88 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Re: ls date was: Bizarre etc/cfg-update problem Willie Wong <wwong@×××××××××.EDU>