Skip to content

Draft: Add KFormat::{formatHumanReadableDate, formatHumanReadableDateTime}

Méven Car requested to merge meven/kcoreaddons:humanreadbaleDate into master

I am not satisfied with the current state of date formatting in kcoreaddons. We have currently two main used date format provided by KFormat::formatRelativeDate. It supports two type of QLocal::FormatType (datetime version after,):

Long: Monday 1 December 2021 CEST, Monday 1 December 2021 CEST, 12:02:00
Short: 01/12/2021, 01/21/2021 12:02

And adjacent relative: Two days ago A moment ago

Plus time when we use DateTime version of formatRelativeDate.

I propose to have another way to display date and datetime in a more human readable way:

Date: Monday 1 December 2021
DateTime: Monday 1 December 2021 at 12:02

While keeping the relative dates rendering.

Advantages compared to Long Format: no timezone, "at" before times (for datetime version), no seconds, shorter
Advantages compared to Short Format: no seconds, more readable
Drawback compared to short format: longer.

The main drawback of this MR is that we will ask our i18n teams to provide date and time formats instead of relying on Qt ones that are an important limit.

Then applications can choose the one they want or let the user choose for themselves. I would propose this new format to be the default one though.

I could offer a Narrow version of this format with years omitted for current year and/or current months, or a Short version with abbreviated months and days. We could also omit day of the week in any of those formats to have a shorter text. But the default Long one here has the advantage of being very consistent and the most human readable a date can be.

cc @ngraham #VDG

A preview of what it would look like in dolphin: Before:

before-new

After:

after-new Dolphin detail view uses formatHumanReadableDateTime and its information panel formatHumanReadableDate.

Edited by Méven Car

Merge request reports

Loading