python-humanize / python-humanize/humanize
Accept ISO 8601 string, in addition to datetime/date/time object
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 756
- Fork
- 148
- Merge medio
- 6g 1h
- PR unite (30g)
- 12
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia individuando le funzioni pubbliche di humanize che accettano valori datetime, date o time, inclusa humanize_naturaldate, e verifica la gestione attuale degli input. Controlla come i test esistenti coprono questi punti di ingresso. Il lavoro è completato quando le stringhe ISO 8601 supportate vengono accettate in modo coerente, mentre gli input costituiti da oggetti esistenti e i valori non validi mantengono il comportamento definito.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100