Tuesday, 15 April 2014

datetime - Natural/Relative days in Python -


I have a way to show natural time for dated objects in Python. Such as "one moment ago", "a few minutes ago", "two hours ago", "three days ago", etc. Etc.

The method "humanize" Django.contrib in Django 1.0 I am not using the Django framework, and even if I am also, it is more limited than I like.

Please let me know (and generations of explorers of the future) whether someone is doing a good job beforehand. Since this is a normal job, I think there must be something.

This is not useful for you at this moment, it can also be done for future explorers: Babel The module, which is related to all types of locale material, has more or less a function that you want to do. Currently it is only in its trunk and not in the latest public release (version 0.9.4) Once the release has the functionality ground, you can do something like: datetime import from babel.dates imported timedelta from import format_timedelta delta = timedelta (day = 6) format_timedelta (delta, locale = 'en_US') U'1 week '

It is taken directly from it. This gives you fewer paths than it does not bend at the "moments ago" level, but it must be done "n minutes" etc. Correctly plural

What is the value for this, the Babel module includes tasks for date formatting and the locale according to time, which can be useful when the time delta is large.


No comments:

Post a Comment