Displaying time
Displaying a time, like a timestamp or the time since something happened, is a common feature in DHIS2 applications.
Knowing the time that something happened is useful for different reasons. Different ways of displaying time suit different use cases. This design pattern offers guidelines for how to display the time in different situations.
Goal
Reduce the mental work required by the user by displaying the time in a way that suits the context.
Relative time / from now
Relative time, or from now, takes the object timestamp, calculates the time to now, and turns that into a natural language phrase. Relative time often has boundaries set for when to use different labels. For example:
- 4 minutes ago
- 3 days ago
- a week ago
- 2 months ago
- a year ago (Check out the moment.js implementation of fromNow for commonly used boundary labels.)
When to use relative time
Use relative time when the time information is interesting based on its relationship to the current time. For example:
- Searching for a patient: showing when records were last updated helps a user find the right patient.
- Browsing a list of visualizations: showing how long ago a visualization was created makes it clear which visualizations are more recent and relevant.
- Reading through a list of comments: showing when a comment was written helps frame the information in the right context.
In each of these examples, the relative time label is the right choice because it reduces the work needed to get to the useful information. If a user would be mentally making the comparison, then doing it automatically saves time and lightens the mental load.
Only use relative time when the approximate time is useful. The level of precision goes down as time passes (a year ago applies for a long time.)
How to use relative time
Context
Make the context clear with a contextual prefix, like last updated. For example:
- Last updated 3 days ago.
- Imported 2 months ago.
- Created a year ago.
Only omit a contextual prefix when it's completely clear what the time refers to, or if the relative time appears in a table column with an appropriate header.
Make the timestamp available
A relative label might offer enough information most of the time, but it helps to make the timestamp available if it's needed.