Twix.js allows you to work with date ranges
Twix is a comprehensive JS library for working with date ranges, and includes a customizable smart formatter. It's written in CoffeeScript and it depends on Moment.js.
var t = moment"1982-01-25T09:30"twix"1982-01-25T13:30";tformat; //=> Jan 25, 1982, 9:30 AM - 1:30 PMtisSame"day"; //=> truethumanizeLength; //=> "4 hours"tcount"days"; //=> 1tintersectionotherRange; //=> another range
See the documentation for more.
You can find comprehensive docs here:
Breaking change in 0.9.0: The
showDate smart format option has been deprecated but also modified. It previously hid the date if the range spanned only one day, regardless of the day. I found that confusing, so you now have two options: a. hide the date with
hideDate: true or b. use
implicitDate: true to elide the date if it spans one day and that day is today.
showDate has been aliased to
!implicitDate, though that behavior is not consistent with the old behavior. If for some reason "hide the date if the range spans only one day" is a real use case for you that I just broke, please let me know.
If you want to build and test Twix for yourself,
make wraps everything you need:
||Install dependencies (same as
||Run Mocha suite|
Patches are welcome!
.jsfiles in the patch; they're much harder to merge. I'll generate them when I cut the release.
Copyright 2012-2015 Isaac Cambron and contributors. Distributed under the MIT License. See LICENSE for details.