-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DurationSpec, Duration.of(DurationSpec), Instant.plus/.add(Dura…
…tionSpec), Instant.minus(DurationSpec) and Instant.minus/add(Duration/DurationSpec)
- Loading branch information
1 parent
e9b4399
commit b330f93
Showing
7 changed files
with
212 additions
and
59 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,9 @@ | ||
export interface DurationSpec | ||
{ | ||
years?: number | ||
days?: number | ||
hours?: number | ||
minutes?: number | ||
seconds?: number | ||
millis?: number | ||
} |
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,38 @@ | ||
import {Duration} from "../dist"; | ||
import {assert} from "chai"; | ||
import {describe} from "mocha"; | ||
|
||
describe('Duration', () => { | ||
describe('.of factory method', () => { | ||
it('accepts whole years', () => { | ||
assert.equal(Duration.of({years: 2}).toString(), 'P2Y'); | ||
}) | ||
it('accepts whole fractional years', () => { | ||
assert.equal(Duration.of({years: 2.5}).toString(), 'P2Y6M'); | ||
}) | ||
it('accepts whole negative whole years', () => { | ||
assert.equal(Duration.of({years: -2}).toString(), '-P2Y'); | ||
}) | ||
it('accepts whole negative fractional years', () => { | ||
assert.equal(Duration.of({years: -2.5}).toString(), '-P2Y6M'); | ||
}) | ||
it('accepts whole days', () => { | ||
assert.equal(Duration.of({days: 2}).toString(), 'P2D'); | ||
}) | ||
it('accepts whole hours', () => { | ||
assert.equal(Duration.of({hours: 2}).toString(), 'PT2H'); | ||
}) | ||
it('accepts whole minutes', () => { | ||
assert.equal(Duration.of({minutes: 2}).toString(), 'PT2M'); | ||
}) | ||
it('accepts whole seconds', () => { | ||
assert.equal(Duration.of({seconds: 2}).toString(), 'PT2S'); | ||
}) | ||
it('accepts 1/1000ths of seconds', () => { | ||
assert.equal(Duration.of({seconds: 0.002}).toString(), 'PT0.002S'); | ||
}) | ||
it('throws error when attempting to enter <1/1000ths of seconds', () => { | ||
assert.throws(() => Duration.of({seconds: 0.0002})); | ||
}) | ||
}); | ||
}); |
Oops, something went wrong.