When thinking about recurring dates, I realized that it’s actually a pretty tough problem. How do you represent recurring dates in a database? Ideally, you don’t want all the instances of recurring dates from the epoch until the End of Time. I had an inkling that it should be possible to express a generalized sense of a range of dates, but I didn’t really know exactly how that would manifest itself.
That’s when I started looking for what people had done before me, since I dislike reinventing the wheel. The first thing I came upon was this recurrence python module. Reading his comments in the code, I thought being able to express dates as an equivalent of a polynomial made a lot of sense.
In fact, functions are condensed form of a set of numbers. Not all sets of numbers can be expressed by functions, but most of the ones that we care about can usually be. That makes them useful. Are there equivalent of ‘functions for dates’?
That’s when I ran into Runt, a ruby library that deals with recurring dates, which are based off of temporal expressions pattern by Martin Fowler.
But it wasn’t exactly what I had in mind when I read ‘temporal expressions’. I was thinking that Martin Fowler came up with something like regular expressions, but for time. After reading the tutorial, it wasn’t exactly what I had in mind. It used classes and patterns to represent recurring dates, rather than an expression, like a function.
So we come to the crux of my musing. Are there the equivalent of regular expressions for time, and would it be a good idea to use it?
When I first started using regular expressions, I thought it was hard to use. Not only could I not remember what some of the symbols meant, but it was dense and not easy to read. A complicated regex quickly got out of hand. I wondered if there were alternatives to regex. And apparently I wasn’t the only one either(and that post was from 2001).
If I were to use something like regex for date and time, like a temporal expression–tempex*, I wouldn’t want something syntactically like regex. It’s really rather hard to read, even if it’s powerful (read “dense”: can say alot with a little).
In drawing the parallel between regex and functions, that could be the reason why people find math arcane: the expressions in math and regex both can say alot with a little.
One should be able to represent dates and times in a matter that you can express sets of dates succinctly, and event better, be able to do operations on them, such as union, intersect, and difference.
I was surprised that it seems like there’s nothing out there that I can find that is a regular expression for time. This shouldn’t be the case. Runt is the closest thing that I can find so far. Anyone else know of anything else out there?
* I’ll have to pick some other name later. people already use the term for natural language processing of time-related phrases, in addition to Martin Fowler’s usage for the pattern