diff options
author | John-Mark Bell <jmb@netsurf-browser.org> | 2024-03-05 21:37:45 +0000 |
---|---|---|
committer | John-Mark Bell <jmb@netsurf-browser.org> | 2024-03-05 21:43:48 +0000 |
commit | 167676c335a517333005b59746006b4fccd45af5 (patch) | |
tree | 118debe8b5bc2014363cc8654c091b9015247e8c /desktop/cookie_manager.c | |
parent | b5f4d905f958ebfce9be2ab8daa5d42b62f7277d (diff) | |
download | netsurf-167676c335a517333005b59746006b4fccd45af5.tar.gz netsurf-167676c335a517333005b59746006b4fccd45af5.tar.bz2 |
Cookie/History/Hotlist: locale-aware time formatting
(as)ctime are defined as always formatting times using English
day/month names. As these views are for the user's benefit, use
the selected locale to format the information, instead.
Use of (as)ctime on RISC OS with UnixLib is fragile, anyway, as
that implementation always produces a locale-aware serialization
(which is not what the spec defines). This caused assertions to
fire in the previous implementation (which expected ctime to be
locale-unaware). Fixes #2869.
Diffstat (limited to 'desktop/cookie_manager.c')
-rw-r--r-- | desktop/cookie_manager.c | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/desktop/cookie_manager.c b/desktop/cookie_manager.c index 3e0417f23..7cb93dff7 100644 --- a/desktop/cookie_manager.c +++ b/desktop/cookie_manager.c @@ -232,10 +232,6 @@ cookie_manager_field_builder(enum cookie_manager_field field, * * The time should be converted to text in the users locacle * - * \todo This should probably generate the user text using localtime - * and strftime with the c format specifier. Currently ctime will - * always generate output in the C locale. - * * \param field Cookie manager treeview field to build * \param fdata Cookie manager entry field data to set * \param value Time to show in field @@ -246,22 +242,20 @@ cookie_manager_field_builder_time(enum cookie_manager_field field, struct treeview_field_data *fdata, const time_t *value) { - const char *date; - char *date2; + struct tm ftime; fdata->field = cm_ctx.fields[field].field; - - date = ctime(value); - date2 = strdup(date); - if (date2 == NULL) { - fdata->value = NULL; - fdata->value_len = 0; - } else { - assert(date2[24] == '\n'); - date2[24] = '\0'; - - fdata->value = date2; - fdata->value_len = strlen(date2); + fdata->value = NULL; + fdata->value_len = 0; + + if (localtime_r(value, &ftime) != NULL) { + const size_t vsize = 256; + char *value = malloc(vsize); + if (value != NULL) { + fdata->value = value; + fdata->value_len = strftime(value, vsize, + "%a %b %e %H:%M:%S %Y", &ftime); + } } return NSERROR_OK; |