Date range calculations

It happens once in a while that I come across a web-form that asks for 2 dates to indicate a time span. I know it can give quite an amount of trouble to program such a date range, especially due to validation. Luckily there can be tons of packages found on GitHub for frameworks like jQuery or AngularJS. What I didn’t found was a simple data type, so without any form of presentation, to handle and validate those ranges.

Recently I had to work with time spans that were not to overlap with each other and had to be subjected to all kinds of calculations. This inspired me to create a value object for it. Beware, the DateRange object.

Installation

This package is available via Bower:

Or NPM:

Usage

Creating a date range is as easy as creating any object. When the passed dates do not form a valid range pair an error will be thrown.

This object can now give you any info about the range you like.

Calculating with a date range

Now, especially when the validation of you date range depends on other dates or ranges, some of the next methods might be useful to achieve this.

Documentation

Full documentation can be found on GitHub.

Issues can also be filed there.

CSS-string to jQuery object

CSS-selectors are clean and clear, element#id.class.another-class. But why, if we want to create an element, do we have to do this?

I build a css parser that converts a css-selector into a jQuery object. For now, only node-type, id and classes are implemented.

Creating an element is now a piece of cake.

The wins might not be as astronomical as I make it sound, but in future posts I might come up with some handy uses for this code.