Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Accept ISO 8601 string, in addition to datetime/date/time object

未關閉
#129 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

@velle 已經在處理了。

開始於 2023年7月9日。

  • #130 來自 @velle —— 未關閉

評估

難度
4/5
預估耗時
3-5 天
新手友好度
42/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
python
領域
backend

研究方向

首先找出接受 datetime、date 或 time 值的公開 humanize 函式,包括 humanize_naturaldate,並檢視它們目前的輸入處理方式。檢查現有測試如何涵蓋這些進入點。完成的標準是:受支援的 ISO 8601 字串能一致地被接受,同時現有的物件輸入和無效值保留已定義的行為。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
Python
星號
760
分支
166
平均合併
4 天 3 小時
30 天內合併 PR
7

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python-humanize/humanize 的其他 Issue

查看 python-humanize/humanize 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。