-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
97 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class After { | ||
constructor (amount) { | ||
this._amount = amount; | ||
Object.freeze(this); | ||
} | ||
|
||
get hours () { | ||
return { duration: (this._amount * 60 * 60 * 1000) | 0 }; | ||
} | ||
|
||
get hour () { | ||
return this.hours; | ||
} | ||
|
||
get minutes () { | ||
return { duration: (this._amount * 60 * 1000) | 0 }; | ||
} | ||
|
||
get minute () { | ||
return this.minutes; | ||
} | ||
|
||
get seconds () { | ||
return { duration: (this._amount * 1000) | 0 }; | ||
} | ||
|
||
get second () { | ||
return this.seconds; | ||
} | ||
|
||
get milliseconds () { | ||
return { duration: this._amount | 0 }; | ||
} | ||
get millisecond () { | ||
return this.milliseconds; | ||
} | ||
} | ||
|
||
const after = (amount) => new After(amount); | ||
|
||
module.exports = { | ||
after | ||
}; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint-env mocha */ | ||
/* eslint-disable no-unused-expressions */ | ||
const chai = require('chai'); | ||
chai.should(); | ||
const { after } = require('../lib'); | ||
|
||
describe('#after', function () { | ||
it('should correctly calculate milliseconds', function () { | ||
after(100).milliseconds.duration.should.equal(100); | ||
after(1).millisecond.duration.should.equal(1); | ||
after(0).milliseconds.duration.should.equal(0); | ||
}); | ||
it('should correctly calculate seconds', function () { | ||
after(1).second.duration.should.equal(1000); | ||
after(0).seconds.duration.should.equal(0); | ||
after(10).seconds.duration.should.equal(10000); | ||
after(1.5).seconds.duration.should.equal(1500); | ||
}); | ||
|
||
it('should correctly calculate minutes', function () { | ||
after(1).minute.duration.should.equal(60000); | ||
after(0).minutes.duration.should.equal(0); | ||
}); | ||
|
||
it('should correctly calculate hours', function () { | ||
after(1).hour.duration.should.equal(3600000); | ||
after(0).hours.duration.should.equal(0); | ||
}); | ||
}); |