After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 325064 - add new date formating function
add new date formating function
Status: RESOLVED DUPLICATE of bug 649900
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
: 416481 (view as bug list)
Depends on:
Blocks: 346337
 
 
Reported: 2005-12-27 14:53 UTC by Benoît Dejean
Modified: 2011-09-05 00:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] Initial implementation of time formatting (6.07 KB, patch)
2007-12-19 17:53 UTC, Emmanuele Bassi (:ebassi)
none Details | Review

Description Benoît Dejean 2005-12-27 14:53:38 UTC
Hi,
    i really miss a function like "char * g_format_date(time_t date);" that would format a timestampt just like evolution does in the date column in the message list :

"15:00"
"Today 01:00"
"Yesterday 14:13"
"Sun 8:02"
"30 apr 06:40"
"7 jul 2003"

I think this is a great feature that should be provided by glib.
Thanks.
Comment 1 Paolo Borelli 2005-12-28 13:57:54 UTC
indeed this would be a useful addition to glib IMHO. The returned string should be locale dependent.

By the way the api should take a GTime not a time_t for consistency with other glib api.
Comment 2 Federico Mena Quintero 2005-12-29 18:37:05 UTC
I'd love to have something like this for bug #324543.

What if we had:

typedef enum {
  G_TIME_COMPONENT_SHOW_DATE = 1 << 0,
  G_TIME_COMPONENT_SHOW_TIME = 1 << 1
} GTimeComponentFlags;

typedef enum {
  G_TIME_FORMAT_SHORT,
  G_TIME_FORMAT_LONG,
  G_TIME_FORMAT_CONTEXTUAL
} GTimeFormat;

char *g_format_time (GTime time, GTimeComponentFlags flags, GTimeFormat format);
char *g_format_explicit_time (int year, int month, int day,
                              int hour, int min, int sec, 
                              GTimeComponentFlags flags,
                              GTimeFormat format);

So far I can remember these cases for formatting dates and times:

  - a short string for lists and other compact displays of data
  - a long string for when you can affort the screen real estate
  - "contextual" is "Today hh:mm", "Yesterday hh:mm", "Wednesday hh:mm",
    "February 29 hh:mm", depending on the closeness to $now.
Comment 3 Matthias Clasen 2005-12-30 02:15:32 UTC
Is this just for "human-readable" date formats, or does it also cover things like 
2005-12-03 ?

GTime has been deprecated, so it should not be used in new api.
Comment 4 Federico Mena Quintero 2006-04-06 15:42:00 UTC
Just human-readable dates.
Comment 5 Matthias Clasen 2007-03-16 04:26:51 UTC
*** Bug 416481 has been marked as a duplicate of this bug. ***
Comment 6 Kjartan Maraas 2007-05-07 10:00:29 UTC
Is this in any way related to bug 21859?
Comment 7 Murray Cumming 2007-05-07 10:08:36 UTC
> Is this in any way related to bug 21859?

Roughly. That bug is about parsing dates, and this bug is about showing (text representations of) dates.
Comment 8 Emmanuele Bassi (:ebassi) 2007-12-19 17:53:29 UTC
Created attachment 101269 [details] [review]
[PATCH] Initial implementation of time formatting

this is an initial implementation of g_format_time_for_display(), similar to g_format_size_for_display(). it uses the same logic as the equivalent function inside GtkFileChooserDefault, but adds second and minute granularity; the output is a UTF-8 string that looks like:

  test format time for display:
    formatted time (now -10 seconds)     = 19 seconds ago
    formatted time (now -120 seconds)    = 19 minutes ago
    formatted time (now -3720 seconds)   = Today at 16:41
    formatted time (now -83720 seconds)  = Yesterday at 18:28
    formatted time (now -163720 seconds) = Monday
    formatted time (now -621170 seconds) = 12/10/07

improvements:
* direction-proof (dates set in the future)
* more granularity (?)
* localization
Comment 9 Emmanuele Bassi (:ebassi) 2007-12-19 17:58:47 UTC
the number discrepancy is due to the "lag" introduced by testglib, in case you wonder :-)
Comment 10 William Lachance 2008-03-06 20:37:47 UTC
Note that we just modified the file chooser to not say "Today at XX:XX", as "today" is rather redundant (see bug 410517). Also bear in mind that it may in some cases be desirable to explicitly request the time in a shorter format if space doesn't permit (see bug 410519).
Comment 11 Tor Lillqvist 2008-03-07 00:09:00 UTC
Eek. I just want to say that I personally hate it when computers try to behave like people *talk* and display things like "yesterday at 14:13". I hate it in Evolution and the file chooser, too.

I can hardly imagine any context in a UI where seeing a point in time expressed in such a varying textual format would make sense. Especially no sense at all it makes when there are several rows of date and time in a column and the rows are sorted according to time. It makes it very hard to quickly see the relative time differences between the rows. One has to parse the individual weekday names and mentally make decisions like "was this 'Tuesday' long after the fifth of last month or not" or "hmm, the 'five minutes ago' on this row is just seconds after the '13:14' on the previous row, isn't it".

It's *much* easier when one just uses a numeric only format with leading zeros. Then everything lines up nicely, as comparing digits quickly with a glance is easy. If one also uses the ISO8601 (most significant unit first) date format, it's even easier.

You wouldn't want to scan a bank account statement, credit card bill etc if it had the amounts expressed as "two bucks", "56.37", "half your weekly salary", etc? 

And if you then say, "but the API suggested here isn't for use in tabular context, but for more prose-like contexts", well, huh? Why not then go the full way and totally try to behave like people talk and produce very free form text like "last Indepencece Day", "the upcoming New Year's Eve", "Super Bowl weekend", "the day before <spouse>'s birthday" etc. Obviousyly this would not only be language, but also country and religion dependent, and would need to be individually tweakable, with a set of personal settings  for personally important dates. I am not entirely serious here.
Comment 12 William Lachance 2008-03-07 17:48:41 UTC
As far as I can see, the API is intended exactly for tabular contexts, like Evolution and the file chooser. 

What's intuitive is obviously rather subjective. :) I personally find it helpful (not necessarily being one to keep track of today's exact date), and would add that popular web applications like facebook and gmail _do_ print out dates this way, so it's not like we're doing something weird and unusual. I don't think the comparison with a credit card statement is quite right: there you already start out with a very specific context (the month of the bill).

Perhaps the best way of settling this would be to get the opinion of someone with usability experience.
Comment 13 Benjamin Otte (Company) 2009-06-18 10:57:06 UTC
Can we get something like this merged for the next release?
I'd like to use it and copy/paste sucks.

Also, I think seconds granularity is kind of ugly, if you want to display it in the file chooser, because you'll have to update it again in a second. The same probably goes for minute-granularity.

The function in the file chooser (that the patch liberally copies from) only requires updating the string once per day, which is probably fine to just ignore. People rarely keep their file chooser or Nautilus window open for more than a day.
Comment 14 Matthias Clasen 2010-06-15 05:00:25 UTC
Given the discussion surrounding size formatting elsewhere, I am very reluctant to take any more 'human-readable' formatting functions into glib at all.
Comment 15 Matthias Clasen 2011-09-05 00:39:39 UTC

*** This bug has been marked as a duplicate of bug 649900 ***