help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get nicer localized date? [SOLVED]


From: Jean Louis
Subject: Re: How to get nicer localized date? [SOLVED]
Date: Mon, 13 Jun 2022 10:54:30 +0300
User-agent: Mutt/+ () (2022-05-21)

* 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/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]