format string: time for today, date for others.

2011-01-05 Thread Yue Wu
Hi list,

Is there a date/time string that show the time only for today's emails
but date for else? So, in the index, the emails that got today will
show the time only, but the ones that got on other days will show the
date and time.

-- 
Regards,
Yue Wu

Key Laboratory of Modern Chinese Medicines
Department of Traditional Chinese Medicine
China Pharmaceutical University
No.24, Tongjia Xiang Street, Nanjing 210009, China


Re: format string: time for today, date for others.

2011-01-05 Thread David Champion
* On 05 Jan 2011, Yue Wu wrote: 
 Hi list,
 
 Is there a date/time string that show the time only for today's emails
 but date for else? So, in the index, the emails that got today will
 show the time only, but the ones that got on other days will show the
 date and time.

Not in out-of-box mutt.  For that you need the date_conditional patch by
Aaron Schrab.  I don't see a version on the web that is rebased against
current mutt but I can send you one if you're comfortable patching and
compiling your own mutt.

-- 
David Champion  *  d...@uchicago.edu  *  IT Services  *  University of Chicago


Re: format string: time for today, date for others.

2011-01-05 Thread Toby Cubitt
On Wed, Jan 05, 2011 at 04:32:44PM -0600, David Champion wrote:
 * On 05 Jan 2011, Yue Wu wrote: 
  Hi list,
  
  Is there a date/time string that show the time only for today's emails
  but date for else? So, in the index, the emails that got today will
  show the time only, but the ones that got on other days will show the
  date and time.
 
 Not in out-of-box mutt.  For that you need the date_conditional patch by
 Aaron Schrab.  I don't see a version on the web that is rebased against
 current mutt but I can send you one if you're comfortable patching and
 compiling your own mutt.

If I remember correctly, the date_conditional patch doesn't *quite* let
you have a different date/time string for today, rather it gives you a
different date/time string for the last 24h.

A while back, I wrote a modified version of the date_conditional patch so
that it could be used to produce different formats for mails from today,
from the current month, from the current year, etc. I haven't gotten
around to making it available online, but if you want a copy I'd be happy
to mail it to you.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: ts...@cantab.net
web: www.dr-qubit.org


Re: format string: time for today, date for others.

2011-01-05 Thread David Champion
* On 05 Jan 2011, Toby Cubitt wrote: 
 
 If I remember correctly, the date_conditional patch doesn't *quite* let
 you have a different date/time string for today, rather it gives you a
 different date/time string for the last 24h.

The best documentation I've seen is the changelog entry that I wrote for
my mercurial patch queue:

Allows you to construct format expressions based on relative dates.

This adds conditionality features to mutt's date-formatting
operators, so that you can build conditions based on whether the
date in question is less than or grater than some amount in the
past.

Example: %?[1y?less than one yeargreater than one year?
Example: %?[3d?less than three daysgreater than three days?

This is particularly useful in concert with nested_if.  For example,
this expression:
%[1y?%[1w?%[1d?%[ %H:%M]%[%a %d]%[%b %d]%[%y%m%d]

means to show the YYMMDD date for messages older than one year,
the mon dd date for messages from one week to one year, the day
dd date for messages from 1 to 7 days old, and the HH:MM time for
messages under one day old.

So it can handle a single split point as it stands (less than 24h,
greater than 24h).

 A while back, I wrote a modified version of the date_conditional patch so
 that it could be used to produce different formats for mails from today,
 from the current month, from the current year, etc. I haven't gotten
 around to making it available online, but if you want a copy I'd be happy
 to mail it to you.

That's what I want as well, but I do it by using date_conditional in
conjunction with the more general nested_if patch.  Nested_if, as its
name suggests, lets you nest mutt's ternary conditionals arbitrarily
deep.

-- 
David Champion  *  d...@uchicago.edu  *  IT Services  *  University of Chicago


Re: format string: time for today, date for others.

2011-01-05 Thread Andreas Kneib
Hi,

* Yue Wu schrieb am Donnerstag, den 06. Januar 2011:

 Is there a date/time string that show the time only for today's emails
 but date for else? So, in the index, the emails that got today will
 show the time only, but the ones that got on other days will show the
 date and time.

I use this script:
http://groups.google.com/group/de.comm.software.mailreader.misc/browse_thread/thread/ab966bddc0b42446/421549103438b830?q=#421549103438b830

In ~/.muttrc:
#v+
set index_format=./format_date.sh '%[%s]' |
#v-

#
#!/bin/bash
#
# File: format_date.sh 

epoch=$1

if [ $(($(date '+%s') - $1)) -gt 86400 ]; then
echo %4C %Z %{%d.%m.%y} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s%
else
echo %4C %Z %{   %H:%M} %-15.15F (%?l?%4l%4c?) %?H?[%H]?%s%
fi 
#


Andreas


Re: format string: time for today, date for others.

2011-01-05 Thread Toby Cubitt
On Wed, Jan 05, 2011 at 05:20:19PM -0600, David Champion wrote:
 * On 05 Jan 2011, Toby Cubitt wrote: 
  
  If I remember correctly, the date_conditional patch doesn't *quite*
  let you have a different date/time string for today, rather it gives
  you a different date/time string for the last 24h.
 
 The best documentation I've seen is the changelog entry that I wrote for
 my mercurial patch queue:
 
 Allows you to construct format expressions based on relative dates.
 
 This adds conditionality features to mutt's date-formatting
 operators, so that you can build conditions based on whether the
 date in question is less than or grater than some amount in the
 past.
 
 Example: %?[1y?less than one yeargreater than one year?
 Example: %?[3d?less than three daysgreater than three days?
 
 This is particularly useful in concert with nested_if.  For example,
 this expression:
 %[1y?%[1w?%[1d?%[ %H:%M]%[%a %d]%[%b %d]%[%y%m%d]
 
 means to show the YYMMDD date for messages older than one year,
 the mon dd date for messages from one week to one year, the day
 dd date for messages from 1 to 7 days old, and the HH:MM time for
 messages under one day old.
 
 So it can handle a single split point as it stands (less than 24h,
 greater than 24h).

Yes, but how would you use this to e.g. print only the time for all
emails received today, but print the date for all emails received
yesterday or earlier? A split point of 24h is no use. If it's currently
10am, say, then all mails since 10am the previous day will display the
time only. Whereas what's wanted is all emails since midnight to display
the time, and emails prior to midnight to display the date.

I don't think this can be done with the date_conditional patch as it
stands, because the split point would have to depend on the current time,
and I know of no way of putting that calculation into the date-format
string.

I just modified the time comparisons in my version of the
date_conditional patch so that an interval of 1 day implies fractions of
a day are discarded before comparing with the current time, an interval
of 1 month discards days and below, an interval of a year discards months
and below, etc.

This lets me display just the time for today's emails, the day and month
for this year's emails, and the full date for older emails. That way, I
can see at a glance which emails arrived today, which arrived this year,
and which are older than a year. (As opposed to which arrived within the
last 24h, which arrived within the last 30 days, which arrived within the
last 365 days.)

  A while back, I wrote a modified version of the date_conditional
  patch so that it could be used to produce different formats for mails
  from today, from the current month, from the current year, etc. I
  haven't gotten around to making it available online, but if you want
  a copy I'd be happy to mail it to you.
 
 That's what I want as well, but I do it by using date_conditional in
 conjunction with the more general nested_if patch. Nested_if, as its
 name suggests, lets you nest mutt's ternary conditionals arbitrarily
 deep.

Indeed, I use nested_if with my modified date_conditional patch.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: ts...@cantab.net
web: www.dr-qubit.org


Re: format string: time for today, date for others.

2011-01-05 Thread David Champion
* On 05 Jan 2011, Toby Cubitt wrote: 
 
 Yes, but how would you use this to e.g. print only the time for all
 emails received today, but print the date for all emails received
 yesterday or earlier? A split point of 24h is no use. If it's currently

That's what nested_if is for.  Here is the date string from my $index_format:

%[1y?%[1w?%[1d?%[ %H:%M]%[%a %d]%[%b %d]%[%y%m%d]

that is,
if  1y:
if  1w:
if  1d:
%H:%M
else:
# = 1d
%a %d
else:  
# = 1w
%b %d
else:
# = 1y
%y%m%d

It does work, or I've been misreading my index for the last 5 years. ;)

-- 
David Champion  *  d...@uchicago.edu  *  IT Services  *  University of Chicago


Re: format string: time for today, date for others.

2011-01-05 Thread Toby Cubitt
On Wed, Jan 05, 2011 at 07:22:18PM -0600, David Champion wrote:
 * On 05 Jan 2011, Toby Cubitt wrote: 
  
  Yes, but how would you use this to e.g. print only the time for all
  emails received today, but print the date for all emails received
  yesterday or earlier? A split point of 24h is no use. If it's currently
 
 That's what nested_if is for.  Here is the date string from my $index_format:
 
 %[1y?%[1w?%[1d?%[ %H:%M]%[%a %d]%[%b %d]%[%y%m%d]
 
 that is,
 if  1y:
   if  1w:
   if  1d:
   %H:%M
   else:
   # = 1d
   %a %d
   else:  
   # = 1w
   %b %d
 else:
   # = 1y
   %y%m%d
 
 It does work, or I've been misreading my index for the last 5 years. ;)

Perhaps I'm being dense here. But if it's 10:00 on the 6 January, and
there's an email dated 19:00 on the 5 January, then surely this will
display 19:00? But I want it to display Sun 05, because the email is
from yesterday, not today. I'm sure your date format does what you want,
it's just not what I'm talking about.

As far as I recall (it's a long time since I looked at it), the
date_conditional patch straightforwardly compares the email date stamp
against the current time. The 1d conditional is true whenever the email
is dated less than 24h before the current time. That's *not* what I'm
after. When the current time is 00:01 on the 6 Jan, I want an email that
arrived at 23:59 on the 5 Jan to display Sun 05, even though the email
is only two minutes old.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: ts...@cantab.net
web: www.dr-qubit.org