Skip to content

Commit

Permalink
Added now() function
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidDuwaer committed Nov 21, 2021
1 parent 86e4515 commit e9b4399
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/Instant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,6 @@ export class Instant
new Date(this.epochMilli)
);
}
}
}

export const now = Instant.now;
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export {DayOfWeek} from './DayOfWeek';
export {DayOfWeekId} from './DayOfWeekId';
export {Duration} from './Duration';
export {Instant} from './Instant';
export {Instant, now} from './Instant';
export {IsoWeekDayNumber} from './IsoWeekDayNumber';
export {LocalDate, MonthNumber, DayOfMonthNumber} from './LocalDate';
export {LocalDateTime} from './LocalDateTime';
Expand Down
18 changes: 13 additions & 5 deletions tests/stub.test.ts → tests/Instant.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {Duration, Instant} from "../dist";
import {Duration, Instant, now} from "../dist";
import {assert} from "chai";
import {LocalDate, LocalDateTime, LocalTime, ZonedDateTime, ZoneId} from "../src";

describe('that tests run', () => {
});
import {LocalDate, LocalDateTime, LocalTime, ZoneId} from "../src";
import {describe} from "mocha";

describe('instant', () => {
it('adds duration at time transition', () => {
Expand Down Expand Up @@ -39,6 +37,16 @@ describe('instant', () => {
})
});

describe('now() function', () => {
it('returns the current time', () => {
const before = Date.now();
const sample = now();
const after = Date.now();
assert.isTrue(before <= sample.toEpochMilli());
assert.isTrue(after >= sample.toEpochMilli());
})
});


function testAddition(
start: Instant,
Expand Down

0 comments on commit e9b4399

Please sign in to comment.