diff --git a/src/Instant.ts b/src/Instant.ts index 1100a59..96f463e 100644 --- a/src/Instant.ts +++ b/src/Instant.ts @@ -178,4 +178,6 @@ export class Instant new Date(this.epochMilli) ); } -} \ No newline at end of file +} + +export const now = Instant.now; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index a44f7ab..77b63e7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/tests/stub.test.ts b/tests/Instant.test.ts similarity index 85% rename from tests/stub.test.ts rename to tests/Instant.test.ts index ffcfe0b..2d413c2 100644 --- a/tests/stub.test.ts +++ b/tests/Instant.test.ts @@ -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', () => { @@ -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,