Holly Bostick:
> > [...]
> > Sorry, couldn't help with the rest of your problem, but I think
> > it is assumed that ls will display the year only for files older
> > than a year old. Quite clever, in my opinion.
>
> OK, I see what you mean-- or maybe I don't:
> [...]
> I see that many files that are more than a year old then are
> followed by the year, but some are not, and some which are less
> than a year old are followed by a year.

Why bother?
Untar coreutils and look at src/ls.c:

static char const *long_time_format[2] =
  {
   /* strftime format for non-recent files (older than 6 months), in
      -l output when --time-style=locale is specified.  This should
      contain the year, month and day (at least), in an order that is
      understood by people in your locale's territory.
      Please try to keep the number of used screen columns small,
      because many people work in windows with only 80 columns. But
      make this as wide as the other string below, for recent files.*/
   N_("%b %e  %Y"),
   /* strftime format for recent files (younger than 6 months), in
      -l output when --time-style=locale is specified.  This should
      contain the month, day and time (at least), in an order that is
      understood by people in your locale's territory.
      Please try to keep the number of used screen columns small,
      because many people work in windows with only 80 columns.  But
      make this as wide as the other string above, for non-recent
      files.  */
   N_("%b %e %H:%M")
  };

> But even leaving aside the inconsistencies (only for the purposes of
> this discussion), this is not the behaviour I expect or in fact
> desire. I normally expect the year to be displayed whenever the
> current calendar year is different from that associated with the
> file-- thus, if the file was created in 2006, I would not expect the
> year to be shown, but if it was created in 2005, I would expect the
> year to be shown, whether or not the current date was one year or
> more from the month and day that the file was created.

The code you should change is here:

static void print_long_format (const struct fileinfo *f) {
  char modebuf[12];
  ........

  if ((when_local = localtime (&when)))
    {
      time_t six_months_ago;
      int recent;
      char const *fmt;

      /* If the file appears to be in the future, update the current
         time, in case the file happens to have been modified since
         the last time we checked the clock.  */
      if (current_time < when
          || (current_time == when && current_time_ns < when_ns))
        {
  /* Note that get_current_time calls gettimeofday which, on some non-
   compliant systems, clobbers the buffer used for localtime's result.
   But it's ok here, because we use a gettimeofday wrapper that
   saves and restores the buffer around the gettimeofday call.  */
          get_current_time ();
        }

      /* Consider a time to be recent if it is within the past six
         months.  A Gregorian year has 365.2425 * 24 * 60 * 60 ==
         31556952 seconds on the average.  Write this value as an
         integer constant to avoid floating point hassles.  */
      six_months_ago = current_time - 31556952 / 2;
      recent = (six_months_ago <= when
                && (when < current_time
                    || (when == current_time && when_ns <= current_time_ns)));
      fmt = long_time_format[recent];
   ............
}

May be, you could add a command-line option ;-)

HTH
Sergio
-- 
gentoo-user@gentoo.org mailing list

Reply via email to