Merge pull request #1662 from Kodiologist/win-strftime
Fix date and time hy-reprs on Windows
This commit is contained in:
commit
d1c7ab08ed
2
NEWS.rst
2
NEWS.rst
@ -17,6 +17,8 @@ Bug Fixes
|
|||||||
------------------------------
|
------------------------------
|
||||||
* Fixed bugs in the handling of unpacking forms in method calls and
|
* Fixed bugs in the handling of unpacking forms in method calls and
|
||||||
attribute access.
|
attribute access.
|
||||||
|
* Fixed crashes on Windows when calling `hy-repr` on date and time
|
||||||
|
objects.
|
||||||
|
|
||||||
0.15.0
|
0.15.0
|
||||||
==============================
|
==============================
|
||||||
|
@ -121,19 +121,23 @@
|
|||||||
|
|
||||||
(hy-repr-register datetime.datetime (fn [x]
|
(hy-repr-register datetime.datetime (fn [x]
|
||||||
(.format "(datetime.datetime {}{})"
|
(.format "(datetime.datetime {}{})"
|
||||||
(.strftime x "%Y %-m %-d %-H %-M %-S")
|
(-strftime-0 x "%Y %m %d %H %M %S")
|
||||||
(-repr-time-innards x))))
|
(-repr-time-innards x))))
|
||||||
(hy-repr-register datetime.date (fn [x]
|
(hy-repr-register datetime.date (fn [x]
|
||||||
(.strftime x "(datetime.date %Y %-m %-d)")))
|
(-strftime-0 x "(datetime.date %Y %m %d)")))
|
||||||
(hy-repr-register datetime.time (fn [x]
|
(hy-repr-register datetime.time (fn [x]
|
||||||
(.format "(datetime.time {}{})"
|
(.format "(datetime.time {}{})"
|
||||||
(.strftime x "%-H %-M %-S")
|
(-strftime-0 x "%H %M %S")
|
||||||
(-repr-time-innards x))))
|
(-repr-time-innards x))))
|
||||||
(defn -repr-time-innards [x]
|
(defn -repr-time-innards [x]
|
||||||
(.rstrip (+ " " (.join " " (filter identity [
|
(.rstrip (+ " " (.join " " (filter identity [
|
||||||
(if x.microsecond (str-type x.microsecond))
|
(if x.microsecond (str-type x.microsecond))
|
||||||
(if (not (none? x.tzinfo)) (+ ":tzinfo " (hy-repr x.tzinfo)))
|
(if (not (none? x.tzinfo)) (+ ":tzinfo " (hy-repr x.tzinfo)))
|
||||||
(if (and PY36 (!= x.fold 0)) (+ ":fold " (hy-repr x.fold)))])))))
|
(if (and PY36 (!= x.fold 0)) (+ ":fold " (hy-repr x.fold)))])))))
|
||||||
|
(defn -strftime-0 [x fmt]
|
||||||
|
; Remove leading 0s in `strftime`. This is a substitute for the `-`
|
||||||
|
; flag for when Python isn't built with glibc.
|
||||||
|
(re.sub r"(\A| )0([0-9])" r"\1\2" (.strftime x fmt)))
|
||||||
|
|
||||||
(hy-repr-register collections.Counter (fn [x]
|
(hy-repr-register collections.Counter (fn [x]
|
||||||
(.format "(Counter {})"
|
(.format "(Counter {})"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user