Fix date and time hy-reprs on Windows
This commit is contained in:
parent
109c0b0f5b
commit
7ba2105a2b
2
NEWS.rst
2
NEWS.rst
@ -17,6 +17,8 @@ Bug Fixes
|
||||
------------------------------
|
||||
* Fixed bugs in the handling of unpacking forms in method calls and
|
||||
attribute access.
|
||||
* Fixed crashes on Windows when calling `hy-repr` on date and time
|
||||
objects.
|
||||
|
||||
0.15.0
|
||||
==============================
|
||||
|
@ -121,19 +121,23 @@
|
||||
|
||||
(hy-repr-register datetime.datetime (fn [x]
|
||||
(.format "(datetime.datetime {}{})"
|
||||
(.strftime x "%Y %-m %-d %-H %-M %-S")
|
||||
(-strftime-0 x "%Y %m %d %H %M %S")
|
||||
(-repr-time-innards 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]
|
||||
(.format "(datetime.time {}{})"
|
||||
(.strftime x "%-H %-M %-S")
|
||||
(-strftime-0 x "%H %M %S")
|
||||
(-repr-time-innards x))))
|
||||
(defn -repr-time-innards [x]
|
||||
(.rstrip (+ " " (.join " " (filter identity [
|
||||
(if x.microsecond (str-type x.microsecond))
|
||||
(if (not (none? x.tzinfo)) (+ ":tzinfo " (hy-repr x.tzinfo)))
|
||||
(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]
|
||||
(.format "(Counter {})"
|
||||
|
Loading…
Reference in New Issue
Block a user