New Code!
For the past few days, I've been working over the date parsing code for at, and I've finally worked it into the point where I can set it aside and work on the rest of the code that makes at a functional batcher. I am still planning on putting at job running into cron, but I've been reluctant to modify and restart cron because I'm still waiting for the 112 day uptime rollover that has been so good at confusing vixie-cron for the last decade or so. So, instead of doing that I've pulled the guts of the time maker out and stuffed them into its own (BSD-licensed) library, which I'm going to release now so that people with other (and less-capable) at date parsers can include the library in their code releases.
The new maketime() function understands a fairly extensive list of date specifications, as (sketchily) described in the manpage:
Name
maketime - parse an at-format date
Synopsis
#include "at.h"
time_t
maketime(int argc, char *argv, int (error)(char *,...));
Description
The maketime() function parses the at-format date string contained in argc and and returns the time_t value that it compiles to.
The date string consists of an optional time, an optional date, or a time offset. The time may be HH:MM, HH am/pm, or the symbolic names noon, teatime (4pm,) or midnight. The date can be MM/DD, MM/DD/YY, DD.MM, DD.MM.YY, DD-Month, DD-Month-YY, DD Month, DD Month YY, Month DD, or Month DD, YY ( if the YY is two digits, it's assumed to b e the year within the current century .)
Date offsets may be prefixed with a time, and are of the form + quantity units or quantity units from specific-date. A specific date is a day of the week, today, tomorrow, or yesterday.
In addition, the names one through ten are recognised as the numbers 1 through 10.
Return Values
Upon successful completion returns the time_t date that the at date compiles to, otherwise 0 is returned.
Errors
When an error is detected, maketime calls the user-supplied error function to report the error before it returns. If no error function was supplied, maketime merely prints a diagnostic to stderr and returns.
See Also
at(1).
This allows me to do some pretty ridiculous at time specifications, such as
- at teatime three weeks from friday
- at one month from now
- at 11:30 tonight
- at noon next friday
- at midnight friday
- at exactly three months from now
- at 8:45am 31 July 2008
- at midnight Dec 31, 2007
This code is not exhaustively tested. It builds on MacOS leopard-1, FreeBSD 4.8, and SLS linux. I suspect it will build on Mastodon as well. It might even build on embrace-and-extend-OS but I'm not going to bet on it until I've wrapped configure.sh around it. But it is new, so it's the ideal candidate to be New Code!