Skip to content

Conversation

@hudlow
Copy link

@hudlow hudlow commented Dec 23, 2025

Peeled out of #244 for easier review — also fixes some additional bugs that will ostensibly be covered in new conformance tests.

*/
export function parseDuration(str: string): Duration {
// The regex grouping the number and the unit is:
const re = /([-+]?(?:\d+|\d+\.\d*|\d*\.\d+))(ns|us|µs|ms|s|m|h)/;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was completely wrong — duration strings can't have signs except at the very beginning.

Comment on lines -27 to -28
assert.equal(actual.seconds, -1n);
assert.equal(actual.nanos, 999999999);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong! Signs are always supposed to match.

Comment on lines -30 to -33
actual = createDuration(0n, -999999999);
assert.ok(isMessage(actual, DurationSchema));
assert.equal(actual.seconds, -1n);
assert.equal(actual.nanos, 1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants