-
-
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.
Add fullTimeAgo function to calculate time duration in various units (#…
…94)
- Loading branch information
Showing
5 changed files
with
181 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ jobs: | |
- run: pnpm run build | ||
- run: pnpm run check | ||
- run: pnpm run lint | ||
- run: pnpm run test:unit |
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 |
---|---|---|
|
@@ -11,3 +11,6 @@ vite.config.ts.timestamp-* | |
|
||
# Example data | ||
/examples/my_user.json | ||
|
||
# Bun | ||
bun.lockb |
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,37 @@ | ||
import { describe, test } from 'vitest' | ||
import { fullTimeAgo, timeAgo } from './dates' | ||
|
||
describe('timeAgo', () => { | ||
test('just now', ({ expect }) => expect(timeAgo(new Date())).toBe('just now')) | ||
|
||
test('in the future', ({ expect }) => { | ||
const date = new Date(8640000000000000) | ||
expect(timeAgo(date)).toBe('in the future') | ||
}) | ||
|
||
test('2 subepochs ago', ({ expect }) => { | ||
const date = new Date(-8640000000000000) | ||
expect(timeAgo(date)).toBe('2 subepochs ago') | ||
}) | ||
}) | ||
|
||
describe('fullTime', () => { | ||
test('min date', ({ expect }) => { | ||
const date = new Date(-8640000000000000) | ||
expect(fullTimeAgo(date)).toBeTypeOf('string') | ||
}) | ||
|
||
test('in the future', ({ expect }) => { | ||
const date = new Date(8640000000000000) | ||
expect(fullTimeAgo(date)).toBe('in the future') | ||
}) | ||
|
||
test('1h 2m 3s ago', ({ expect }) => { | ||
const date = new Date() | ||
date.setHours(date.getHours() - 1) | ||
date.setMinutes(date.getMinutes() - 2) | ||
date.setSeconds(date.getSeconds() - 3) | ||
|
||
expect(fullTimeAgo(date)).toBe('1 hour 2 minutes 3 seconds ago') | ||
}) | ||
}) |
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,8 @@ | ||
import { test } from 'vitest' | ||
import { Duration, durationUnit } from './duration' | ||
|
||
test('MAX_SAFE_INTEGER', ({ expect }) => { | ||
const duration = new Duration(Number.MAX_SAFE_INTEGER, durationUnit.millisecond) | ||
const subepochs = duration.to(durationUnit.subepoch).value | ||
expect(subepochs).toBe(2.8542678186223407) | ||
}) |