python-humanize / python-humanize/humanize
Accept ISO 8601 string, in addition to datetime/date/time object
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 756
- Fork
- 148
- Merge trung bình
- 6 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 12
Mô tả
Motivation:
I believe that the humanize functions are often used indrectly from template engines. In my case I use Jinja2 templating engine and the jinja2_humanize_extension, which relies on the humanize package.
{{ value | humanize_naturaldate }}
In many cases the underlying data (either a database, json-file or csv-file) stores/returns the datetime (or date or time) as a string, formatted in ISO8601 format. But in order to make humanize_naturaldate accept this, I need to first parse it.
{{ value | fromisoformat | humanize_naturaldate }}
The fromisoformat then needs to be set as a filter in the local or global jinja environment.
It would be great if humanize accepted these ISO8661 strings itself.
How to implement:
As far as I can tell, it would be very simple to implement and very simple to maintain. Every function callable by the client, that takes a datetime should start with:
if type(value) == str:
try:
value = datetime.datetime.fromisoformat(value)
else:
value = str
Similarly for date and time objects.
I will admit that I have only studied the code cursorily, and I might have missed some reasons why this is more complex than I currently believe it is.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách xác định các hàm humanize công khai nhận các giá trị datetime, date hoặc time, bao gồm humanize_naturaldate, và xem xét cách xử lý đầu vào hiện tại của chúng. Kiểm tra cách các bài kiểm thử hiện có bao quát các điểm vào này. Công việc được hoàn tất khi các chuỗi ISO 8601 được hỗ trợ được chấp nhận nhất quán, trong khi các đầu vào đối tượng hiện có và các giá trị không hợp lệ vẫn giữ nguyên hành vi đã được định nghĩa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 42/100