3 ms·
ISO 8601 contains durations and time intervals which are totally undervalued! (https://en.wikipedia.org/wiki/ISO_8601#Time_intervals https://en.wikipedia.org/wi
by valenterry 6y ago
ISO 8601 contains durations and time intervals which are totally undervalued! (https://en.wikipedia.org/wiki/ISO_8601#Time_intervals https://en.wikipedia.org/wiki/ISO_8601#Time_intervals)
E.g.: 2021-05-01T12:00:00Z/P2H
They are so convenient. Ever stored a tuple of two datetimes to model a time interval? E.g. a meeting that takes place on 2021-05-01T12:00:00Z and takes two hours?
Don't! Instead, store it as an interval: "2021-05-01T12:00:00Z/P2H"
Or are you creating an API where a duration or a time interval is expected? E.g. "give me all sales in this time period..."
Using time intervals for that makes it so much more easy for people to code against it and execute manual queries.
For JVM developers, there is a library out there that has amazing support: https://github.com/MenoData/Time4J https://github.com/MenoData/Time4J
For python developers, there is pendulum which supports most of the functionality.
- em500 6y agoI agree it's undervalued. Sadly too few people are aware that a standard notation for time intervals even exists, and external software support is very sparse (e.g. lacking in Pandas, R, most SQL implementations). Which leads to too many devs rolling their own buggy solutions for datetime arithmetic.
- twic 6y agoAs of Java 8, the JDK also has support for ISO duration formats, via java.time.Period and java.time.Duration.
- valbaca 6y ago100% agree that it's undervalued. Was just in a software design meeting where they were trying to figure out how to represent exactly this: a time interval. I had to repeat "Just read ISO 8601 and use it" like a dozen times. "Bu-bu-but what if we want to represent a recurring..." READ IT. AND USE IT.
- brewmarche 6y agoShouldn't it be /PT2H instead of /P2H?