From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: How to get nicer localized date? [SOLVED] Date: Mon, 13 Jun 2022 10:54:30 +0300 Message-ID: References: <87v8t51cf7.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7115"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/+ () (2022-05-21) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 13 10:02:59 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o0f2J-0001dj-0L for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 13 Jun 2022 10:02:59 +0200 Original-Received: from localhost ([::1]:36860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0f2H-0006jV-Hz for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 13 Jun 2022 04:02:57 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0f1J-0006hp-UN for help-gnu-emacs@gnu.org; Mon, 13 Jun 2022 04:01:58 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:55833) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0f1I-0003lg-5o for help-gnu-emacs@gnu.org; Mon, 13 Jun 2022 04:01:57 -0400 Original-Received: from localhost ([::ffff:102.84.37.119]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000087C61.0000000062A6EEF2.00003F01; Mon, 13 Jun 2022 01:01:53 -0700 Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <87v8t51cf7.fsf@dataswamp.org> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:137775 Archived-At: * Emanuel Berg [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/