Library for analyzing descriptions of recurring dates in C ++?

For my application, I need a parser that can handle direct date descriptions, for example. "12/31/10" this year on New Year's Eve, but can also handle descriptions / repetitions / dates, for example. "The first Monday of every month." boost :: date_time already has the concept of date generators, but I don’t think it provides any general way to convert strings to them without knowing the type of generator that will be created.

Before I go and reinvent the wheel, is there anything there for this? I am flexible with the exact string language, only as long as this non-programmer can read and understand.

+4
source share
4 answers

You can use the wonderful boost :: spirit library.

This allows you to easily create parsers for these kinds of things.

+2
source

Perhaps you can draw inspiration from the Roaring Penguin remind tool , which has a reasonably clear language (for simple cases).

+1
source

You can write your own grammar in EBNF and then use the lexer / parser generator to create the code skeleton for you.

0
source

Using this library , here is the code that prints the first Monday of every month in 2011:

 #include "date.h" #include <iostream> int main() { using namespace gregorian; std::cout << date_fmt("%A %B %e, %Y"); for (date d = first*mon/jan/2011; d <= dec/31/2011; d += month(1)) std::cout << d << '\n'; } 

Output:

 Monday January 3, 2011 Monday February 7, 2011 Monday March 7, 2011 Monday April 4, 2011 Monday May 2, 2011 Monday June 6, 2011 Monday July 4, 2011 Monday August 1, 2011 Monday September 5, 2011 Monday October 3, 2011 Monday November 7, 2011 Monday December 5, 2011 

You can also get a second, third, etc. or last working day of the month. Arithmetic can be focused on a day, a month or a year.

0
source

Source: https://habr.com/ru/post/1332556/


All Articles