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.


This package is available via Bower:



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.


Full documentation can be found on GitHub.

Issues can also be filed there.

JS Value Objects

In the ‘days of the web-application’ that we live in, more and more calculation is done in the browser, but the code is often not prepared for that. When performing form-validation it can still give you headaches to come up with a decent structure to minimize the redundancy but still keep it dynamic enough so it can handle unknown future changes.

In the upcoming months I hope to write a serie of posts about the use of the Value Object pattern in JavaScript. This will be an experimental journey were I will try to find a way to improve the maintainability and sustainability of JavaScript applications.