Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding helper function to create a timestamp #583

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function getCurrentTimeInHighPrecision(): string {
* @returns string
*/
export function createTimestamp(
year: number, month: number, day: number, hour: number, minute: number, second: number, millisecond: number, microsecond: number
year?: number, month?: number, day?: number, hour?: number, minute?: number, second?: number, millisecond?: number, microsecond?: number
flothjl marked this conversation as resolved.
Show resolved Hide resolved
): string {
return Temporal.ZonedDateTime.from({
timeZone: 'UTC',
Expand Down
18 changes: 9 additions & 9 deletions tests/utils/test-data-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type { PrivateJwk, PublicJwk } from '../../src/types/jose-types.js';

import * as cbor from '@ipld/dag-cbor';
import { CID } from 'multiformats/cid';
import { createTimestamp } from '../../src/index.js';
import { DataStream } from '../../src/utils/data-stream.js';
import { getCurrentTimeInHighPrecision } from '../../src/utils/time.js';
import { PermissionsGrant } from '../../src/interfaces/permissions-grant.js';
Expand Down Expand Up @@ -832,15 +833,14 @@ export class TestDataGenerator {
* @returns random UTC ISO-8601 timestamp
*/
public static randomTimestamp(): string {
return Temporal.ZonedDateTime.from({
timeZone : 'UTC',
year : this.randomInt(2000, 2022),
month : this.randomInt(1, 12),
day : this.randomInt(1, 28),
hour : this.randomInt(0, 23),
minute : this.randomInt(0, 59),
second : this.randomInt(0, 59),
}).toInstant().toString({ smallestUnit: 'microseconds' });
return createTimestamp(
this.randomInt(2000, 2022),
this.randomInt(1, 12),
this.randomInt(1, 28),
this.randomInt(0, 23),
this.randomInt(0, 59),
this.randomInt(0, 59)
);
}

/**
Expand Down