0

Is there a standard or at least generally accepted convention to represent relative dates?

For ex.,

-5d => 5 days ago
5d 4m 3s => 5 days, 4 minutes and 3 secs

where units are y, M, d, h, m, s

Note that I checked on the question but that talks about absolute date ranges but here I'm looking for relative date conventions.

metasync
  • 338
  • 1
  • 10
  • 1
    Does this answer your question? [Is there any kind of standard for representing date ranges?](https://stackoverflow.com/questions/20413843/is-there-any-kind-of-standard-for-representing-date-ranges) – Ouroborus May 27 '22 at 01:24
  • Checked on that but that doesn't answer as that is more of absolute date ranges. But here -5d means actual date can change depending on when you try to interpret it. I know there is ISO relative time standard like P10H but that seems not very user friendly to enter in UI – metasync May 27 '22 at 01:29
  • We generally make UIs for users with several languages and other cultural backgrounds. So there could not possibly be a standard that would be suitable for all users everywhere. – Ole V.V. Apr 27 '23 at 16:37

1 Answers1

1

I think you are looking for ISO 8601 Time intervals, specifically Durations.

There are four ways to express a time interval:

  1. Start and end, such as "2007-03-01T13:00:00Z/2008-05-11T15:30:00Z"
  2. Start and duration, such as "2007-03-01T13:00:00Z/P1Y2M10DT2H30M"
  3. Duration and end, such as "P1Y2M10DT2H30M/2008-05-11T15:30:00Z"
  4. Duration only, such as "P1Y2M10DT2H30M", with additional context information
Adam Millerchip
  • 20,844
  • 5
  • 51
  • 74
  • Thank you for the answer. As I mentioned in the comment, I was aware of ISO standard for duration for we feel it is not user friendly to enter that in UI. So i was looking for any other "friendly" convention like for ex., `5d 2s`. – metasync May 27 '22 at 02:22
  • 1
    I see - questions seeking recommendations for libraries and other resources are off-topic for Stack Overflow. – Adam Millerchip May 27 '22 at 02:47
  • 1
    It seems that a related question has been asked in relation to Moment JS [here: Support locale/humanize #16](https://github.com/jsmreese/moment-duration-format/issues/16) and has been turned down. Other than that I did a short search and didn’t find anything interesting. So my guess is that it does not exist. – Ole V.V. Apr 27 '23 at 16:42