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.

Some examples:

var t = moment("1982-01-25T09:30").twix("1982-01-25T13:30");
t.format();  //=> Jan 25, 1982, 9:30 AM - 1:30 PM 
t.isSame("day"); //=> true 
t.humanizeLength(); //=> "4 hours" 
t.count("days"); //=> 1 
t.intersection(otherRange); //=> another range 

See the documentation for more.


You can find comprehensive docs here:

Detailed documentation

Breaking change in 0.8.0: Twix now provides start() and end() accessors. Previously, it was possible to access Twix fields called start and end, though they weren't documented. Because they're now functions, that will break. I did this to prevent people from mutating those dates and breaking Twix.

Breaking change in 0.7.0: Twix formatting internationalization (just French, really) is no longer supported. It doesn't seem to have had a lot of use, and it's pain to maintain. Don't worry, we still support Moment's internationalized tokens.

If you want to build and test Twix for yourself, make wraps everything you need:

make configureInstall dependencies (same as npm install)
make or make buildCompile src/*.coffee to dist/*.js
make testRun Mocha suite
make lintLinter
make benchMicrobenchmarks

Patches are welcome!

  • Submit pull requests to the develop branch. I merge develop to master when we cut a release.
  • Don't include your changes to the generated .js files in the patch; they're much harder to merge. I'll generate them when I cut the release.
  • Make sure you run the linter and the tests before submitting a PR.
  • There's a linter with a bunch of rules for keeping style consistent. Run it with make lint.


Copyright 2012-2015 Isaac Cambron and contributors. Distributed under the MIT License. See LICENSE for details.