I’m looking for a plain C counterpart for date.js date.parse().
That is, something that understands “week ago” or “yesterday” as input. English-only is OK.
Note: a library should not be licensed under GPL, so Git’s date.c or parser for GNU date -d wouldn’t do. BTW, if you wonder why wouldn’t I just sit down and code this, go and look at the source of mentioned libraries…
The following solution is not exactly what you’ve asked for but I hope that despite not being a plain C answer it will cover your needs. Reinventing the wheel isn’t a way to go so let’s use date.js in C by running it with SpiderMonkey, the Mozilla JavaScript engine.
Here’s how I did it. I’ve begun with downloading date.js and translating it into a
const char*namedcodedefined indate.js.h.Then I took the JSAPI’s Hello, World! as a starting point.
Here’s how it works in practice.
As you can see it’s quite fast and you could significantly increase its performance by reusing the initially created context for all subsequent calls to
Date.parse.Speaking of licensing issues, date.js is available under terms of MIT and SpiderMonkey is available under MPL 1.1, GPL 2.0 or LGPL 2.1. Linking it dynamically satisfies the non-GPL requirement.
TL;DR:
git clone https://gist.github.com/2180739.git && cd 2180739 && make && ./parse yesterday