Created
November 7, 2011 04:01
-
-
Save hgarcia/1344152 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TimeTraveller = require('timeTraveller).TimeTraveller; | |
var ttDate = new TimeTraveller().now(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d.addYears(2).addMonths(6).addHours(12); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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