question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

version/3.0: Add a 'duration' format

See original GitHub issue

Spun off from #356 to avoid PRs which don’t attract comments 😉.

On IRC today, Tony Tam pointed out that folks currently work around the lack of durations by using an int64 for millisecond offsets, but that’s not very human readable. And we care about human-readability or we’d all be using protobufs instead of JSON, right? 😉.

The support for ISO 8601 durations in native JavaScript is unclear, but both Firefox 31.5 and Chromium 41.0 give:

> new Date('P3D')
Invalid Date

So the millisecond approach may be easier to use in JavaScript applications, where date-times are stored as millisecond offsets from the epoch, you can instantiate Dates from those millisecond offsets, and durations are in milliseconds by default.

The Moment.js library supports durations based on millisecond offsets:

moment.duration(100);

explicit units:

moment.duration(2, 'seconds');

and [{day}.]{hour}:{minute}[:{second}[.{fraction}]] strings:

moment.duration('23:59');
moment.duration('23:59:59');
moment.duration('23:59:59.999');
moment.duration('7.23:59:59.999');

And it renders ISO 8601 durations, but it doesn’t appear to parse that format.

Java parses ISO 8601 durations with an extension to support negative durations.

Go parses durations from its own format.

Python has a duration type, but does not parse ISO 8601 durations.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
MikeRalphsoncommented, Oct 7, 2020

Sorry, in a bit of a rush, but basically:

  • format is an open-ended keyword, you can use any value
  • duration was added to JSON Schema as a format value to indicate ISO-8601 durations in Draft 2019-09. OAS will not define conflicting behaviour
1reaction
handrewscommented, Oct 8, 2020

@nasht00 note that the “not a validation assertion by default” is due to format never having been implemented consistently for validation. The date and time formats tend to be well-supported, but others tend to be partially supported (e.g. validation of email being done as just checking for an @ sign) or use inconsistent definitions (e.g. validation of regex being done according to whatever regex syntax is supported by the implementation language, even if that doesn’t quite align with the ECMA standard cited in the spec).

The expectation is that the new modular extension vocabulary support will result in well-defined validation keywords being created that don’t staple completely unrelated concepts together. A date and time vocabulary with well-defined validation keywords would be very easy to add, as those concepts have very clear specifications from IETF and/or ISO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

format-duration - npm
Convert a number in milliseconds to a standard duration string.. Latest version: 3.0.1, last published: 6 days ago.
Read more >
Timex.Format.Duration.Formatters.Default - HexDocs
Timex.Format.Duration.Formatters.Default (timex v3.7.9). Handles formatting Duration values as ISO 8601 durations as described below.
Read more >
How to format a duration in java? (e.g format H:MM:SS)
Just hit the wall with time zone normalization when used this method. You have to add sdf.setTimeZone(TimeZone.getTimeZone("GMT+0")); before using the format ...
Read more >
moment-duration-format | Yarn - Package Manager
Format plugin for the Moment Duration object. This is a plugin to the Moment.js JavaScript date library to add comprehensive formatting to Moment...
Read more >
Compose file version 3 reference - Docker Documentation
This table shows which Compose file versions support specific Docker releases. Compose file format, Docker Engine release. Compose specification, 19.03.0+. 3.8 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found