From: Jean Louis <bugs@gnu.support>
To: help-gnu-emacs@gnu.org
Subject: Re: How to get nicer localized date? [SOLVED]
Date: Mon, 13 Jun 2022 10:54:30 +0300 [thread overview]
Message-ID: <YqbtNkLW7opGnoFA@protected.localdomain> (raw)
In-Reply-To: <87v8t51cf7.fsf@dataswamp.org>
* Emanuel Berg <incal@dataswamp.org> [2022-06-13 06:17]:
> Jean Louis wrote:
>
> > Also the above one is not what I really want, I would like
> > it as "Sonntag, 12 Juni 2022"
>
> (format-time-string "%A, %d %B %Y")
If that would be so simple, but it is not.
In some countries that may pass, in others not, because after the date
there may be need for a dot like: (format-time-string "%A, %d. %B %Y")
-- while in English there should not be any dot. That is one example.
I was thinking this may be decided automatically by locale, and it is
true that %c gives a result, just that I like readable, fully
understandable dates without doubts.
Date formats in various languages - Meta
https://meta.wikimedia.org/wiki/Date_formats_in_various_languages
You may see here:
de German Deutsch 1. Januar 2009
sv Swedish svenska 1 januari 2009
I consider this solved. I have decided to define the locale for each
language in the database, as my documents are database based and have
their dates and languages.
ID 1
HID "English"
Extension "en"
Name "English"
Original "English"
Google Translate t
RTL nil
Locale "en_US.UTF-8"
I could as well insert the date formatting string straight into the
database. But now I am keeping it in the Emacs Lisp as following:
;; Work in progress
(defun rcd-iso8601-date-format-time-format (locale)
(cond ((string= locale "en_US.UTF-8") "%A, %e %B %Y")
((string= locale "de_DE.UTF-8") "%A, %e %B %Y")
((string= locale "hr_HR.UTF-8") "%A, %e. %B %Y")
(t "%A, %e %B %Y")))
(defun rcd-iso8601-date-to-locale-date (date locale)
"Convert ISO 8601 date to localized date."
(let* ((system-time-locale locale)
(format (rcd-iso8601-date-format-time-format locale))
(date (format-time-string format (float-time (date-to-time date)))))
date))
;; (rcd-iso8601-date-to-locale-date "2022-06-12" "en_US.UTF-8") ⇒ "Sunday, 12 June 2022"
;; (rcd-iso8601-date-to-locale-date "2022-06-12" "hr_HR.UTF-8") ⇒ "nedjelja, 12. lipnja 2022"
;; (rcd-iso8601-date-to-locale-date "2022-06-12" "de_DE.UTF-8") ⇒ "Sonntag, 12 Juni 2022"
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
In support of Richard M. Stallman
https://stallmansupport.org/
next prev parent reply other threads:[~2022-06-13 7:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-12 17:34 How to get nicer localized date? Jean Louis
2022-06-13 3:15 ` Emanuel Berg
2022-06-13 7:54 ` Jean Louis [this message]
2022-06-13 21:00 ` How to get nicer localized date? [SOLVED] Emanuel Berg
2022-06-13 21:30 ` Emanuel Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YqbtNkLW7opGnoFA@protected.localdomain \
--to=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.