Subject: Re: bug#21229: 24.5; parse-time-string ignore PM/AM

From: Tino Calancha <[email-masked]>
Date: Tue, 11 Aug 2015 20:47:19 +0900 (JST)

Exactly, there are a lot, its always a mess.

I attached my tentative idea to support
(format-time-string "%p")
(format-time-string "%D")

I didnt tested so much. Im sure you can find a better way.

(parse-time-string "08/11/15 08:37:48 PM")
(48 37 20 11 8 2015 nil nil nil)
(parse-time-string "08/11/15 08:37:48 AM")
(48 37 8 11 8 2015 nil nil nil)

Tino

On Tue, 11 Aug 2015, Andreas Schwab wrote:

> Tino Calancha <[email-masked]> writes:
>
>> "%m/%d/%y" is better option because is seems more
>> standard:
>
> The nice things about standards is that there are so many to chose from.
>
> Andreas.
>
> -- 
> Andreas Schwab, SUSE Labs, [email-masked]
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."
>

--- parse-time.el	2015-08-11 18:06:46.895638495 +0900
+++ parse-time_3.el	2015-08-11 20:22:45.627737133 +0900
@@ -55,6 +55,7 @@
       (cond ((eq char ?+) 1)
 	    ((eq char ?-) -1)
 	    ((eq char ?:) ?d)
+	    ((eq char ?/) ?e)
 	    ((string-match "[[:upper:]]" (setq str (string char))) ?A)
 	    ((string-match "[[:lower:]]" str) ?a)
 	    ((string-match "[[:digit:]]" str) ?0)))))
@@ -156,6 +157,12 @@
 			(= (aref parse-time-elt 4) ?-)
 			(= (aref parse-time-elt 7) ?-)))
      [0 4] [5 7] [8 10])
+    ((5 4 3)
+     ,#'(lambda () (and (stringp parse-time-elt)
+			(= (length parse-time-elt) 8)
+			(= (aref parse-time-elt 2) ?/)
+			(= (aref parse-time-elt 5) ?/)))
+     [6 8] [0 2] [3 5])
     ((2 1 0)
      ,#'(lambda () (and (stringp parse-time-elt)
 			(= (length parse-time-elt) 5)
@@ -182,7 +189,10 @@
 The values are identical to those of `decode-time', but any values that are
 unknown are returned as nil."
   (let ((time (list nil nil nil nil nil nil nil nil nil))
-	(temp (parse-time-tokenize (downcase string))))
+		(temp (parse-time-tokenize (downcase string)))
+		(has-pm nil))
+	(when (member "pm" temp)
+	  (setq has-pm t))
     (while temp
       (let ((parse-time-elt (pop temp))
 	    (rules parse-time-rules)
@@ -216,6 +226,13 @@
 				       (funcall this)))
 				 parse-time-val)))
 		  (rplaca (nthcdr (pop slots) time) new-val))))))))
+    (let ((year (nth 5 time)))
+	  (cond ((and (>= year 50) (<= year 110))
+			 (setf (nth 5 time) (+ 1900 year)))
+			((and (>= year 0) (<= year 49))
+			 (setf (nth 5 time) (+ 2000 year)))))
+	(when (and has-pm (< (nth 2 time) 12))
+	  (setf (nth 2 time) (+ (nth 2 time) 12)))
     time))
 
 (provide 'parse-time)