Skip to content

Commit

Permalink
v0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmurray committed Dec 24, 2022
1 parent d6dcd79 commit ad657c6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ npm i greenwich
## Usage

```ts
import { timeParse, timeAdd } from 'greenwich';
import { timeNow, timeSpanCreate, timeToISOString } from 'greenwich';

const t0 = timeNow();
const t1 = timeAdd(t0, timeSpanCreate({ days: 10 }));

console.log(timeToISOString(t1));
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "greenwich",
"version": "0.1.0",
"version": "0.1.1",
"description": "TypeScript date and time utility library.",
"author": "Mark Murray",
"license": "MIT",
Expand Down
9 changes: 9 additions & 0 deletions src/__tests__/time-now.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { timeCompare, timeNow } from '..';

test('can get current time', async () => {
const t1 = timeNow();
await new Promise((resolve) => setTimeout(resolve, 10));
const t2 = timeNow();

expect(timeCompare(t1, t2)).toEqual(-1);
});
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './aggregate';
export * from './compare';
export * from './difference';
export * from './format';
export * from './now';
export * from './parse';
export * from './time';
export * from './truncate';
Expand Down
16 changes: 16 additions & 0 deletions src/now.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { timeCreate } from './time';
import { Time } from './types';

export const timeNow = (): Time => {
const date = new Date();

return timeCreate({
year: date.getUTCFullYear(),
month: date.getUTCMonth() + 1,
day: date.getUTCDate(),
hour: date.getUTCHours(),
minute: date.getUTCMinutes(),
second: date.getUTCSeconds(),
millisecond: date.getUTCMilliseconds(),
});
};

0 comments on commit ad657c6

Please sign in to comment.