Longer durations (>7 days) are not formatted in a human-readable way

While Coda displays shorter durations in a human-readable way (e.g. “1 hr 30 mins” or “1 day 3 hrs”, it appears that “day” is the maximum term it will use, displaying longer durations as e.g. “1508 days” instead of in years, months, weeks. This does not seem to be affected by the precision setting at all.

I’ve made a testcase here with various durations: https://coda.io/d/_dvpm1X4YHZ3/Duration-issues_su_VW

I imagine one of the challenges in displaying durations like this in a readable way is months, since we need additional metadata to go from a date difference to a number of months. There are two ways to go about this:

  • When the duration value is produced by a date difference, retain the dates that produce it as hidden metadata on the duration value. Then the algorithm that does the formatting can access that and use it for better formatting when it’s available.
  • For durations more than a few months, you can just divide by 30.437 and it gives a pretty accurate number of months.

Regardless of months, at least weeks instead of days is pretty low hanging fruit! “11 weeks 5 days”, while not ideal, is far better than “82 days”, and that has none of the month challenges.

2 Likes

hi @Lea_Verou , you are right that Coda is not doing a great job here. The duration function does not feel like it has given much thought. The AI is a bit of a help, but not always since it makes mistakes. We need a programmed solution as long as AI fails us :wink:

You are an expert in calculating with dates. I need you to give me the delta between {“type”:“Column”,“columnId”:“c-UAe8zeH3gJ”,“gridId”:“grid-mZxABr6qea”} and {“type”:“Column”,“columnId”:“c-7is5UKCutz”,“gridId”:“grid-mZxABr6qea”}
Only use year(s), month(s), week(s) or day(s) and hour(s) when necessary. Do not show the instructions in the outcome, show the outcome as short as possible.

I remember @Paul_Danyliuk once wrote a sort of solution using Sign() , but I lost the details.

4 Likes

This is a brilliant workaround, thank you!

I used this:

Display the time that passed from {“type”:“Column”,“columnId”:“c-UAe8zeH3gJ”,“gridId”:“grid-mZxABr6qea”}to {“type”:“Column”,“columnId”:“c-7is5UKCutz”,“gridId”:“grid-mZxABr6qea”}in a compact but human readable way. Only display the time passed, no other information. Never display more than 2 terms, and only display terms of consecutive precision, and only show integers. For durations less than a month, you can use weeks too, but prefer months whenever possible.

2 Likes

It will be near-perfect — perhaps perfect — if you add a learner shot for each of the examples.

This is proof that we may soon see CFL at risk of unemployment because of AI. :slight_smile:

it is an interesting idea that examples can reduce the risks for errors seriously, I’ll give that a try, merci @Bill_French

1 Like

I created the prompt below:

Display the time that passed from  {"type":"Column","columnId":"c-UAe8zeH3gJ","gridId":"grid-mZxABr6qea"} to {"type":"Column","columnId":"c-7is5UKCutz","gridId":"grid-mZxABr6qea"} in a compact but human readable way. Only display the time passed, no other information. Never display more than 3 terms. For durations less than a month, you can use weeks to, but use months whenever possible.
Only display terms of consecutive precision.
Only show integers. 

Examples to use to format your outcomes are:
38 minutes
2 hours and 5 minutes
2 days, 2 hours and 39 minutes
9 months, 3 weeks and 4 days
1 year, 2 months and 3 days
4 years, 7 months and 5 days

the outcome is not 100% right, maybe the example should contain more details.

cheers, Christiaan

Creating an a field that properly formats the output for longer durations is a bit of a band-aid. It is important that we can also enter durations such as “3 weeks” or “2 years.”

Oh I’ve made a pack for this! Took me a few weeks to build, it was a little more complex than anticipated :sweat_smile: But super happy with the end result!

1 Like

hi @Lea_Verou ,

The prompt you find on this page may solve your issue:

Enjoy, Christiaan

1 Like