Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using parse_datetime from gnu c

Tags:

c

I am developing a program for analyzing time series under gnu/linux. To analyze a time window, I want to be able to specify start/end times on the command line. Parsing dates using strptime is simple enough, however I would like to use the flexible 'natural language' format as it is used by the unix ''date'' command. There, this is done using the parse_datetime function.

I have the source of the coreutils, but would like to avoid copying over the code and all attached header files.

My question is: is there a standard library under Unix/Linux which gives access to the full power of parse_datetime().

like image 996
Floyd Avatar asked Jan 11 '13 09:01

Floyd


1 Answers

The function you refer to is not part of any standard, nor any stock utility library. However, it is available as a semi-standalone component as part of gnulib, namely the parse-datetime module. You will need to take it and incorporate it into your program; the gnulib distribution has tools for that. Be aware that if you do this you have to GPL your entire program (this is not a big deal if the program is only for your personal use -- the GPL's requirements only kick in when you start giving the compiled program to other people).

A possible alternative is g_date_set_parse from GLib, but I can't speak to how clever it is.

like image 131
zwol Avatar answered Oct 29 '22 17:10

zwol