This Space for Rent

New Code (silly trivial edition)!

I was home sick today, and halfway through the afternoon I started to itch to write code. I'm slowly building up the list of essential programs for the core of the next release of Mastodon, and I've been needing to write a version of date that supports some of the new date formats that have appeared since the 1980s.

It turned out that the copy of strftime() in libc 4 doesn't deal very well with the requirements of the new date formats, so I was stuck either patching the existing (LGPLed and incomprehensible) strftime(), snarfing a modern Posix! Compliant! strftime() from one of the BSDs, or writing my own.

I wrote my own, of course, but I edited the BSD manpage for it. I'm sure the Posix-style %E? format options are useful for someone, but that someone isn't me, and they're nowhere to be found in either the code or the manpage.

But, anyway, back to date, which was the reason I needed to write my own strftime(). Date has new display formats to reflect the exciting world of the information superhighway:

orc@pell(bin)> date
Wed Oct 03 21:12:51 PDT 2007
orc@pell(bin)> date -I
Wed Sep 5146 21:12:54 PDT 1993

The new -I (aka --psu) option correctly displays the date for usenet purposes. Remember, It's always September on the Information Superhighway!, and this New Code! will help you know the correct date.


I’ve always just used this perl script that I snarfed from somewhere:


sepdate utility

usage: sepdate [month date year]

where day month year are date of interest – default is today

e.g. sepdate 10 21 95

for October 21, 1995

Prints the date in same format as Unix date command (default)

but unlike the buggy date command this script does take into account the

fact that September 1993 never ended.

Known bugs and odd features:

- if date other than today is specified, time is displayed as 00:00:00.

- arguments are not checked other than to see if there are 3 or none.

- dates prior to 9 1 93 are rendered as nonpositive dates in Sept. 1993.

require “”;

if ($#ARGV == 2) {
$thetime = &timelocal(0,0,0,$ARGV[1],$ARGV[0]-1,$ARGV[2])
elsif ($#ARGV == -1) {
$thetime = time
else {
die ‘usage: sepdate [month date year]’

$days = int (($thetime - &timelocal(0,0,0,31,7,93)) / (60 * 60 * 24));
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($thetime);

printf (“%3s Sep %2d %2.2d:%2.2d:%2.2d %3s 1993\n”,

Paul Tomblin Thu Oct 4 04:57:25 2007

Yes, but the problem with the perl version of date -I is that it’s written in perl, and I’m planning on putting date into Mastodon-core, which isn’t going to have perl.

It helps that I’m not a perl programmer, and that I’m perfectly happy to reinvent the wheel when it’s a fairly small wheel.

David Parsons Thu Oct 4 09:46:47 2007

Comments are closed