[darcs-users] example of annotate.py alternative output

Kannan Goundan cakoose at yahoo.com
Mon Mar 21 06:26:14 UTC 2005


> Attached is a patch for a better date format. I used python's 
> strftime with a "%x %X" format which means "locale's date"
"locale's 
> time", so I get 02/28/05 19:57:42 here in the US.
>
> Modify function pretty_date as you see fit.

[snip]

> +def pretty_date(date):
> +   import time
> +   return time.strftime("%x %X", time.strptime(date,
"%Y%m%d%H%M%S"))

Wow.  I didn't know you could do it so easily.

The file I tried it on (DarcsArguments.lhs from darcs-unstable) has
some timestamps that are formatted differently:

   Thu Oct 31 13:29:44 EST 2002

It looks like Darcs doesn't use this format anymore (all the recent
patches use the more compact format).  Here's a modified version of
the function that tries to handle both cases.

I'm not sure why, but the "time.strptime(...)" on my machine doesn't
seem to think 'EST' is a valid time zone.  If I replace it with
'PST', 'PDT', 'UTC' or 'GMT', it works fine.

And I'm really sorry if this message doesn't thread up in the
archives.  Does anyone know how I can get Pipermail/Mailman to thread
my messages properly?  I'm also sorry about the footers -- I really
don't care whether you Yahoo or not.  I need to find a new e-mail
provider.

INPUT_TIME_FORMATS = [
  "%Y%m%d%H%M%S",
  "%a %b %d %H:%M:%S %Z %Y",
  "%a %b %d %H:%M:%S EST %Y",  # hack hack
]

def pretty_date(date_string):
   import time
   # Try all the time formats until one works
   for parse_format in INPUT_TIME_FORMATS:
      try:
         timestamp = time.strptime(date_string, parse_format)
         return time.strftime("%x %X", timestamp)
      except ValueError:
         pass
   # Unable to parse
   #raise ("Couldn't parse '%s'" % date_string)
   return date_string




		
__________________________________ 
Do you Yahoo!? 
Make Yahoo! your home page 
http://www.yahoo.com/r/hs




More information about the darcs-users mailing list