Skip to content

Instantly share code, notes, and snippets.

@hgarcia
Created November 7, 2011 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgarcia/1344152 to your computer and use it in GitHub Desktop.
Save hgarcia/1344152 to your computer and use it in GitHub Desktop.
var TimeTraveller = require('timeTraveller).TimeTraveller;
var ttDate = new TimeTraveller().now();
d.addYears(100);
d.addMonths(1);
d.addDays(10);
d.addHours(2);
d.addMinutes(75); // Will roll over an hour
d.addSeconds(2);
d.addMilliseconds(1000);
var d = new TimeTraveller().now();
console.log(d); //Mon, 04 Jul 2011 23:03:22 GMT
d.addYears(2);
console.log(d); //Thu, 04 Jul 2013 23:03:22 GMT
d.addYears(-4);
console.log(d); //Thu, 04 Jul 2009 23:03:22 GMT
d.addYears(2).addMonths(6).addHours(12);
var d = new TimeTraveller().now();
d.isSameSecond(secondDate);
d.isSameMinute(secondDate);
d.isSameHour(secondDate);
d.isSameDay(secondDate);
d.isSameMonth(secondDate);
d.isSameYear(secondDate);
d.isSame(secondDate, 'm'); //Same as calling isSameMinute();
d.isSame(secondDate); //Will compare both dates to the millisecond, same as doing ((d - secondDate) === 0);
//Difference
var d = new TimeTraveller().now();
var ts = d.differenceFrom(new Date());
//Milliseconds
var ts = new TimeSpan(1300);
//Two dates
var ts = new TimeSpan(date, secondDate);
//Returns the diff in milliseconds between the two dates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment