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

    Add :any-decimal-separator option to accept both decimal dot and decimal 
comma, regardless of what pattern uses.
---
 datetime.el | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/datetime.el b/datetime.el
index d1ac7dcd18..3d1bb34fca 100644
--- a/datetime.el
+++ b/datetime.el
@@ -81,7 +81,10 @@
 ;;   millisecond (NUMBER)
 ;;   second-fractional (NUMBER)
 ;;       this is a generalization used internally: (second-fractional . 3)
-;;       means millis, (second-fractional . 6) -- micros, and so on.
+;;       means millis, (second-fractional . 6) -- micros, and so on;
+;;
+;;   decimal-separator (PREFERRED)
+;;       either dot or comma;
 ;;
 ;;   timezone (?) -- currently not supported further than pattern parsing
 
@@ -196,7 +199,12 @@
                  (_
                   (error "Illegal pattern character `%c'" character))))
               (t
-               (datetime--extend-as-is-part parts (string character))))))
+               (if (and (or (= character ?.) (= character ?,))
+                        (plist-get options :any-decimal-separator)
+                        (eq (car-safe (car parts)) 'second)
+                        (< scan length) (= (aref pattern scan) ?S))
+                   (push (cons 'decimal-separator character) parts)
+                 (datetime--extend-as-is-part parts (string character)))))))
     (nreverse parts)))
 
 (defun datetime--format-java-pattern (parts options)
@@ -245,6 +253,7 @@
                           (`hour-am/pm-1-12   (cons ?h details))
                           (`minute            (cons ?m details))
                           (`second            (cons ?s details))
+                          (`decimal-separator details)
                           (`millisecond       (cons ?S details))
                           (`second-fractional (if (plist-get options 
:second-fractional-extension)
                                                   (cons ?S details)
@@ -380,6 +389,7 @@ specified otherwise.
                           (`hour-am/pm-1-12  12)
                           (`minute           59)
                           (`second           59)
+                          (`decimal-separator (rx (or "." ",")))
                           ((or `millisecond `second-fractional)
                            (apply #'concat (make-list details (rx (any 
"0-9")))))
                           (`timezone
@@ -413,7 +423,7 @@ specified otherwise.
 
 (defun datetime-recode-pattern (from to pattern &rest options)
   "Recode PATTERN between two supported types.
-As a special case, either of FROM and TO can be set to 'parsed.
+As a special case, either of FROM and TO can be set to \\='parsed.
 This is useful as a speed optimization in a few cases where you
 perform several transformations on the same pattern.
 
@@ -423,7 +433,14 @@ Options can be a list of the following keyword arguments:
 
     In Java patterns any number of \"S\" stand for milliseconds.
     With this extension they are instead interpreted according to
-    how many \"S\" there is, e.g. \"SSSSSS\" means microseconds."
+    how many \"S\" there is, e.g. \"SSSSSS\" means microseconds.
+
+  :any-decimal-separator
+
+    Treat a decimal dot or comma in pattern between seconds and
+    milli- or microseconds (etc.) as a placeholder for _any_
+    decimal separator and also accept commas in this place.  This
+    only works if TO is \\='parsed."
   (datetime--format-pattern to (datetime--parse-pattern from pattern options) 
options))
 
 

Reply via email to