Skip to content

A simple C library for parsing arbitrary date strings

License

Notifications You must be signed in to change notification settings

mheyman/approxidate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Approxidate Build Status

Taken from Linus' original code in /git/date.c, approxidate gives you a dead-simple way to get a timestamp from tons of date formats. Unlike git's original approxidate, this approxidate also returns microseconds.

Usage

There's only one function: int approxidate(const char *date, struct timeval *t). It returns 0 when it parsed the date, -1 when it couldn't.

When compiling, copy both approxidate.{c,h} to your project, link in the math library (-lm), and you're good.

#include <approxidate.h>

struct timeval t;
approxidate("10/Mar/2013:12:43:02.603 -0500", &t);
approxidate("10/Mar/2013:12:43:02 -0500", &t);

Note: If no timezone is given, the system's local timezone is used.

For more, see test.c.

Speed

From benchmark.c (for 1,000,000 iterations):

$ make

rm -f test
gcc -g -Wall -O2 -std=gnu99 benchmark.c approxidate.c -lm -o benchmark

approxidate time: 0.363872
strptime time: 0.622350

Python

Check out: https://pypi.python.org/pypi/approxidate

About

A simple C library for parsing arbitrary date strings

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 93.9%
  • Python 3.5%
  • Makefile 2.6%