Skip to content

Commit

Permalink
Minor tweaks (by Stefan Monnier, upon addition to NonGNU ELPA).
Browse files Browse the repository at this point in the history
  • Loading branch information
doublep committed Feb 3, 2025
1 parent 38f0e18 commit ca27cf4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
/Eldev-local
/.eldev
/dist

# Helpful for those who check out this out directly into `~/.emacs.d/elpa'.
/datetime-autoloads.el
/datetime-pkg.el
28 changes: 21 additions & 7 deletions datetime.el
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@
(datetime--define-error 'datetime-unsupported-timezone "Timezones are currently not supported")


(defconst datetime--directory (file-name-directory (or load-file-name (buffer-file-name))))
;; Defining the three extmap database variables like this so that values _are_ replaced if these
;; variable declaration is reevaluated (rather, the whole buffer). Otherwise e.g. reinstalling
;; `datetime' package could leave unusable extmap objects referring to removed files.
;;
;; FIXME: Would be nice to add ERT test(s).

;; Extracted from Java using `dev/HarvestData.java'. All patterns are
;; obviously of `java' type.
Expand All @@ -153,10 +157,10 @@
;; - all patterns have the following fallbacks: `:short' defaults to
;; `:medium', `:long' defaults to `:medium', `:full' defaults to
;; `:long'.
(defvar datetime--locale-extmap (extmap-init (expand-file-name "locale-data.extmap" datetime--directory) :auto-reload t))
(defvar datetime--locale-extmap nil)

;; Extracted from Java using `dev/HarvestData.java'.
(defvar datetime--timezone-extmap (extmap-init (expand-file-name "timezone-data.extmap" datetime--directory) :weak-data t :auto-reload t))
(defvar datetime--timezone-extmap nil)

;; Extracted from Java using `dev/HarvestData.java'.
;;
Expand All @@ -171,7 +175,19 @@
;; English locale;
;; [ABBREVIATED FULL] -- no special for DST;
;; [ABBREVIATED-STD ABBREVIATED-DST FULL-STD FULL-DST].
(defvar datetime--timezone-name-extmap (extmap-init (expand-file-name "timezone-name-data.extmap" datetime--directory) :weak-data t :auto-reload t))
(defvar datetime--timezone-name-extmap nil)

(dolist (entry
'((datetime--locale-extmap "locale-data.extmap" :auto-reload t)
(datetime--timezone-extmap "timezone-data.extmap" :weak-data t :auto-reload t)
(datetime--timezone-name-extmap "timezone-name-data.extmap" :weak-data t :auto-reload t)))
(let ((directory (file-name-directory (or load-file-name (buffer-file-name))))
(variable (nth 0 entry))
(filename (nth 1 entry))
(options (nthcdr 2 entry)))
(unless (ignore-errors (file-equal-p (file-name-directory (cdr (assq 'filename (extmap-statistics (symbol-value variable)))))
directory))
(set variable (apply #'extmap-init (expand-file-name filename directory) options)))))

(defvar datetime--pattern-parsers '((parsed . (lambda (pattern options) pattern))
(java . datetime--parse-java-pattern)))
Expand Down Expand Up @@ -223,7 +239,6 @@ You can see the list of locales supported by the library by
evaluating this form:
(prin1-to-string (sort (datetime-list-locales t) #\\='string<))"
:group 'datetime
;; The only minor problem is the type won't be rebuilt if `datetime--locale-extmap' is
;; autoreloaded, but oh well.
:type `(choice (const nil) ,@(mapcar (lambda (locale) `(const ,locale)) (datetime-list-locales t))))
Expand All @@ -237,7 +252,6 @@ You can see the list of supported timezones by evaluating this
form:
(prin1-to-string (sort (datetime-list-timezones) #\\='string<))"
:group 'datetime
:type `(choice (const nil) ,@(mapcar (lambda (locale) `(const ,locale)) (datetime-list-timezones))))


Expand Down Expand Up @@ -1826,7 +1840,7 @@ OPTIONS are passed to `datetime-recode-pattern'. Currently no
options can affect result of this function."
(datetime--pattern-includes-p type pattern options second-fractional))

(define-obsolete-function-alias 'datetime-pattern-includes-millisecond-p 'datetime-pattern-includes-second-fractionals-p "0.6.1")
(define-obsolete-function-alias 'datetime-pattern-includes-millisecond-p #'datetime-pattern-includes-second-fractionals-p "0.6.1")

(defun datetime-pattern-num-second-fractionals (type pattern &rest options)
"Determine number of second fractional digits in the PATTERN.
Expand Down

0 comments on commit ca27cf4

Please sign in to comment.