* On 09 Nov 2012, Jeremy Kitchen wrote:
> On Fri, Nov 09, 2012 at 11:12:34AM +0000, Jamie Paul Griffin wrote:
> > Hi
> >
> > I would like to use the method of setting messages to expire described
> > on Gary's page[1] but the problem is that this script uses gnu date(1)
> > and I have BSD date(1).
>
> there's no compatible option with bsd `date`?
>
> You could also replace the call to `date` with a $SCRIPTING_LANGUAGE
> script (perl would probably work pretty well for this, and I believe
> perl is pretty standard on the BSDs) which does the same thing. All it's
> doing with GNU `date` is spitting out an RFC822 formatted `date`, which
> I would think BSD `date` is capable of doing, but a simple perl script
> would definitely be able to.
The greater problem in Gary's script for Jamie is not printing an RFC822
date (there is no one-shot option, but the formatters are all there),
but parsing date/time from natural language, which GNU date's '-d' does.
Python option:
$ easy_install parsedatetime
$ python
>>> from parsedatetime.parsedatetime import Calendar
>>> import time
>>> rfc822format = '%a, %d %b %Y %H:%M:%S -0000'
>>> c = Calendar()
>>> st, flag = c.parse('next Monday at 2pm')
>>> t = time.mktime(st)
>>> tm = time.gmtime(t)
>>> time.strftime(rfc822format, tm)
'Mon, 12 Nov 2012 20:00:00 -0000'
parsedatetime doesn't know anything about timezones, so the mktime and
gmtime are just to adapt the struct_time value from c.parse() from local
time to GMT, so that the RFC822 address can assume it. This lets the
script work for anyone, without needing to calculate a zone offset for
your locale.
--
David Champion • [email protected]