branch: elpa/datetime
commit 0ec8ecf25e857638ead944eeb3e7d68c6f16f2de
Author: Paul Pogonyshev <pogonys...@gmail.com>
Commit: Paul Pogonyshev <pogonys...@gmail.com>

    Fix several issues that resulted in weekday number being formatted 
incorrectly for half of the locales; add tests.
---
 datetime.el          |  31 ++++++++++++++++++++++---------
 dev/HarvestData.java |   5 +++++
 locale-data.extmap   | Bin 410110 -> 423256 bytes
 test/format.el       |  11 +++++------
 4 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/datetime.el b/datetime.el
index 24857f37bf..51abd69ccc 100644
--- a/datetime.el
+++ b/datetime.el
@@ -376,7 +376,8 @@ form:
                                   (5 'narrow)
                                   (_ (error "Pattern character `%c' must come 
in 1-5 repetitions" character))))))
                        ((or ?E ?c ?e)
-                        (if (and (= character ?e) (<= num-repetitions 2))
+                        (if (or (cond ((= character ?e) (<= num-repetitions 2))
+                                      ((= character ?c) (=  num-repetitions 
1))))
                             (cons 'weekday num-repetitions)
                           (cons (if (= character ?c) 'weekday-standalone-name 
'weekday-context-name)
                                 (pcase num-repetitions
@@ -750,7 +751,11 @@ to this function.
             (`weekday
              (setq need-weekday t)
              (push (datetime--digits-format details) format-parts)
-             (push `(1+ weekday) format-arguments))
+             (let ((first-day-of-week (datetime-locale-field locale 
:first-day-of-week)))
+               (push (if (= first-day-of-week 0)
+                         `(1+ weekday)
+                       `(1+ (mod (- weekday ,first-day-of-week) 7)))
+                     format-arguments)))
             ((or `weekday-context-name `weekday-standalone-name)
              (setq need-weekday t)
              (push "%s" format-parts)
@@ -1928,21 +1933,28 @@ separated by a space, for quite a few locales it is 
different."
   "Get a FIELD of data for the LOCALE.
 Supported fields:
 
-  :decimal-separator
+  :decimal-separator         (a character, usually dot or comma)
   :eras-short                (alias: :eras)
   :eras-full
   :eras-narrow
   :month-context-short       (alias: :month-context-abbr)
   :month-context-full        (alias: :month-context-names)
   :month-context-narrow
-  :weekday-context-abbr
-  :weekday-context-names
   :month-standalone-short    (alias: :month-standalone-abbr)
   :month-standalone-full     (alias: :month-standalone-names)
   :month-standalone-narrow
-  :weekday-standalone-abbr
-  :weekday-standalone-names
-  :am-pm"
+  :weekday-context-short     (alias: :weekday-context-abbr)
+  :weekday-context-full      (alias: :weekday-context-names)
+  :weekday-context-narrow
+  :weekday-standalone-short  (alias: :weekday-standalone-abbr)
+  :weekday-standalone-full   (alias: :weekday-standalone-names)
+  :weekday-standalone-narrow
+  :first-day-of-week         (a number, with 0 standing for Monday)
+  :am-pm
+
+Unless something else is stated explicitly, values are arrays of
+strings.  Lengths of arrays for the same field are the same
+across all locales (12 months, 7 weekdays etc.)."
   ;; Additionally `:day-periods', `:date-patterns', `:time-patterns' and
   ;; `:date-time-pattern-rule' are supported for internal use.
   (let ((data (extmap-get datetime--locale-extmap locale t)))
@@ -1965,6 +1977,7 @@ Supported fields:
         (pcase field
           (:decimal-separator                       ?.)
           ((or :eras-short :eras-full :eras-narrow) datetime--english-eras)
+          (:first-day-of-week                       6)  ; See comments in 
`HarvestData.java'.
           (:am-pm                                   
datetime--english-am-pm)))))
 
 (defun datetime--era-field (details)
@@ -2034,7 +2047,7 @@ create based on locales `datetime' knows about.
 
 Note that this database doesn't include timezone names.  See
 `datetime-timezone-name-database-version'."
-  8)
+  9)
 
 (defun datetime-timezone-database-version ()
   "Return timezone database version, a simple integer.
diff --git a/dev/HarvestData.java b/dev/HarvestData.java
index 0cb29c6ac8..4b681db9d8 100644
--- a/dev/HarvestData.java
+++ b/dev/HarvestData.java
@@ -90,6 +90,8 @@ public class HarvestData
             map.put (":weekday-standalone-short",  toLispVector (getNames 
(locale, ChronoField.DAY_OF_WEEK,   "ccc",   1,  7)));
             map.put (":weekday-standalone-full",   toLispVector (getNames 
(locale, ChronoField.DAY_OF_WEEK,   "cccc",  1,  7)));
             map.put (":weekday-standalone-narrow", toLispVector (getNames 
(locale, ChronoField.DAY_OF_WEEK,   "ccccc", 1,  7)));
+            // Subtracting 1 so that it works as zero-based index in weekday 
name arrays.
+            map.put (":first-day-of-week",         String.valueOf 
(WeekFields.of (locale).getFirstDayOfWeek ().getValue () - 1));
             map.put (":am-pm",                     toLispVector (getNames 
(locale, ChronoField.AMPM_OF_DAY,   "a",     0,  1)));
             map.put (":day-periods",               findDayPeriodData (locale));
 
@@ -255,6 +257,9 @@ public class HarvestData
                                                                          
":weekday-standalone-narrow", ":weekday-context-narrow");
     private static Map <String, String>  LOCALE_DEFAULT_VALUES = Map.of 
(":decimal-separator",         "?.",
                                                                          
":eras",                      ENGLISH_ERAS,
+                                                                         // 
First day defaults to Sunday.  This is used for all "no-country"
+                                                                         // 
locales in Java, so is the most useful as the default.
+                                                                         
":first-day-of-week",         "6",
                                                                          
":am-pm",                     ENGLISH_AM_PM,
                                                                          
":date-time-pattern-rule",    "(t . \" \")");
 
diff --git a/locale-data.extmap b/locale-data.extmap
index 1744cdf8cc..d5e66434ff 100644
Binary files a/locale-data.extmap and b/locale-data.extmap differ
diff --git a/test/format.el b/test/format.el
index b021b53541..0acb7dfa4b 100644
--- a/test/format.el
+++ b/test/format.el
@@ -175,12 +175,11 @@
   ;; Loop over all supported Java specifiers and make sure we produce the same 
results for
   ;; them as the Java benchmark.  To make it somewhat faster, combine multiple 
elements
   ;; into one pattern where easily possible,
-  (dolist (entry '(("G GG GGG GGGG GGGGG"                                   
era       t)
-                   ("y yy yyy yyyy"                                         
year    nil)
-                   ("M MM MMM MMMM MMMMM / L LL LLL LLLL LLLLL"             
month     t)
-                   ;; FIXME: fails for 'c', 'e' and 'ee' (weekday _number_) 
currently.
-                   ;; 'cc' (exactly two repetitions) is not supported.
-                   ("E EE EEE EEEE EEEEE / ccc cccc ccccc / eee eeee eeeee" 
weekday   t)))
+  (dolist (entry '(("G GG GGG GGGG GGGGG"                                      
    era       t)
+                   ("y yy yyy yyyy"                                            
    year    nil)
+                   ("M MM MMM MMMM MMMMM / L LL LLL LLLL LLLLL"                
    month     t)
+                   ;; 'cc' (exactly two repetitions) is not supported (by Java 
and so by us).
+                   ("E EE EEE EEEE EEEEE / c ccc cccc ccccc / e ee eee eeee 
eeeee" weekday   t)))
     (let ((pattern         (nth 0 entry))
           (unit            (nth 1 entry))
           (locale-specific (nth 2 entry)))

Reply via email to