fixing ddate(1)

I needed to fix a date formatting problem wherein the ddate(1) command in Linux would print dates like the “11st” or “12nd” of a given season. I downloaded the source tarball from here and edited the only file in it, ddate.2.0.c. I changed line 97 from this:

inline char *ending(int i) { return (i%10==1)?"st":(i%10==2?"nd":(i%10==3?"rd":"th"));};

to this (keeping the same formatting out of (misplaced, IMO) courtesy for the original author):

inline char *ending(int i) { return (i>10&&i<20?"th":(i%10==1?"st":(i%10==2?"nd":(i%10==3?"rd":"th")));};

If I were to rewrite this with better formatting, it’d be:

inline char *ending(int i) {
	return (
		 i > 10 && i < 20 ? "th" : /* teens */
		(i % 10 == 1      ? "st" :
		(i % 10 == 2      ? "nd" :
		(i % 10 == 3      ? "rd" :
		            "th"))) /* default case */

Though I must admit, dates like 11st and 13rd are very much in the Discordian spirit. 🙂

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: