Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

twix

icambron212.5kMIT1.3.0TypeScript support: definitely-typed

Twix.js allows you to work with date ranges

twix, date, date range

readme

Twix.js

MIT License Build Status Version NPM version

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.

Documentation

You can find comprehensive docs here:

Detailed documentation

Breaking change in 1.0.0: Removed the deprecated showYear and showDate smart formatter options. Use hideYear, hideDate, implicitYear, and implicitDate instead.

Building

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

Command Function
make configure Install dependencies (same as npm install)
make or make build Compile src/*.coffee to dist/*.js
make test Run Mocha suite
make lint Linter
make bench Microbenchmarks

Contributing

Patches are welcome!

  • 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. Use make lint and make test.
  • If you make a change that will need documentation, make the appropriate update to docs. It will get published to the website on the next release.

Changelog

CHANGELOG

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

Phasers to stun

changelog

Changelog

  • 1.2.1: Add formatting for japanese dates

  • 1.2.1: Fix for AMD support

  • 1.2.0: Add basic internationalization

  • 1.1.4: Add a floating point option to length

  • 1.1.3: Fix for split

  • 1.1.2: Added toArray

  • 1.1.0: Smart formatting: hideTime causes months to collapse

  • 1.0.0: Removed deprecated options

  • 0.9.0: Deprecated the show options to format(). Added explicitDate, hideTime, and hideYear options.

  • 0.8.1: isValid() now checks if the start and end are valid moments.

  • 0.8.0: Added start() and end(). Lots of code cleanup.

  • 0.7.0: Fixed bug in xor() and difference(). Fixed compatibility with other plugins. Removed custom locale support. Deprecated twentyFourHour. Moved bin to dist.

  • 0.6.5: Fix for contains() on all-day ranges

  • 0.6.4: Use peerDependency for Moment

  • 0.6.3: Moment 2.10 compatibility

  • 0.6.2: Fix iterate for months

  • 0.6.1: Meteor support

  • 0.6.0: Moment deprecations, s/lang/locale, xor, intersection, split, difference, immutability

  • 0.5.1: Make Twix compatible with Moment 2.8.1

  • 0.5.0: Fix intersection/overlap behavior (#36), expand signature, and deal with Moment deprecations.

  • 0.4.0: Simplified internationalization support (possibly breaking change for those few people using French support), added more complex iteration durations. Reverted build complexity.

  • 0.3.0: AMD support, basic internationalization support, bug fix for countInner and iterateInner. Component and bower support. New build system and code organization.

  • 0.2.2: Added isValid and intersection, fixed overlaps for adjacent times, renamed merge to union, added deprecation warnings.

  • 0.2.1: Added countInner, contains, iterateInner, and length

  • 0.2.0: Deprecated sameDay, sameYear, countDays, daysIn, past, and duration. Added isSame, humanizeLength, asDuration, isPast, isFuture, isCurrent. Added duration methods. Emphasized moment() monkey patch methods over Twix() constructor. Some bug fixes.

  • Older versions - wasn't tracking.