Skip to content

Conversation

@hudlow
Copy link
Collaborator

@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.

@hudlow hudlow requested a review from srikrsna-buf December 23, 2025 16:12
*/
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
Collaborator 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
Collaborator 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
Collaborator Author

Choose a reason for hiding this comment

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

Nope!

@hudlow hudlow merged commit eb01dd5 into main Dec 23, 2025
12 checks passed
@hudlow hudlow deleted the hudlow/timestamp-and-durations branch December 23, 2025 16:25
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