all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to get nicer localized date?
@ 2022-06-12 17:34 Jean Louis
  2022-06-13  3:15 ` Emanuel Berg
  0 siblings, 1 reply; 5+ messages in thread
From: Jean Louis @ 2022-06-12 17:34 UTC (permalink / raw)
  To: Help GNU Emacs

I have been reading description of `format-time-string' but I cannot
find a way to get a nicer, readable, easier understandable, localized
date. I have to give an ISO 8601 date "2022-06-12" to a function and
to convert it automatically to the date in particular language, like
German, but without abbreviations and without time.

This function is attempt to do that:

;; Work in progress
(defun rcd-iso8601-date-to-locale-date (date locale)
  "Convert ISO 8601 date to localized date."
  (let* ((system-time-locale locale)
	 (date (format-time-string "%A %x" (float-time (date-to-time date))))
	 (place (string-match " ..:..:.." date))
	 (date (substring date 0 place)))
    date))

However, I do not find the output here nice:

;; (rcd-iso8601-date-to-locale-date "2022-06-12" "en_US.UTF-8") ⇒ "Sun 12 Jun 2022"

As I would rather like the output to be "Sunday, June 12th 2022" or
similar, to be very readable.

;; (rcd-iso8601-date-to-locale-date "2022-06-12" "de_DE.UTF-8") ⇒ "So 12 Jun 2022"

Also the above one is not what I really want, I would like it as
"Sonntag, 12 Juni 2022"

I would like to have full name of week day and full name of the
month. And I cannot find solution in the current
`format-time-string'. Function shall be general so that it is switched
by locale string such as "de_DE.UTF-8".


Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to get nicer localized date?
  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   ` How to get nicer localized date? [SOLVED] Jean Louis
  0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg @ 2022-06-13  3:15 UTC (permalink / raw)
  To: help-gnu-emacs

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")

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to get nicer localized date? [SOLVED]
  2022-06-13  3:15 ` Emanuel Berg
@ 2022-06-13  7:54   ` Jean Louis
  2022-06-13 21:00     ` Emanuel Berg
  0 siblings, 1 reply; 5+ messages in thread
From: Jean Louis @ 2022-06-13  7:54 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to get nicer localized date? [SOLVED]
  2022-06-13  7:54   ` How to get nicer localized date? [SOLVED] Jean Louis
@ 2022-06-13 21:00     ` Emanuel Berg
  2022-06-13 21:30       ` Emanuel Berg
  0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg @ 2022-06-13 21:00 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Louis wrote:

> In some countries that may pass [...]

Search for "locale" in `format-time-string' ... 9 occurrences.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to get nicer localized date? [SOLVED]
  2022-06-13 21:00     ` Emanuel Berg
@ 2022-06-13 21:30       ` Emanuel Berg
  0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2022-06-13 21:30 UTC (permalink / raw)
  To: help-gnu-emacs

>> In some countries that may pass [...]
>
> Search for "locale" in `format-time-string' ...
> 9 occurrences.

Hm ... there seems to be no locale version of the day of the
month, or year! Bummer, but we'll do without, like this

  (format-time-string "%d %A %B %Y") ; 13 Monday June 2022

But actually it is better to always write dates like this

  (format-time-string "%F") ; 2022-06-13

And with time

  (format-time-string "%F %H:%M") ; 2022-06-13 23:28

And in computer systems

  (format-time-string "%FT%T%z") ; 2022-06-13T23:28:35+0200

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-13 21:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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   ` How to get nicer localized date? [SOLVED] Jean Louis
2022-06-13 21:00     ` Emanuel Berg
2022-06-13 21:30       ` Emanuel Berg

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.