pyppin.text.now_and_then¶
Produce human-readable strings expressing relative time for status pages and debugging.
Functions
|
Output a string '{then}, {duration} ago' or '{then}, {duration} from now', or the like, expressing "then" in terms of "now." This tends to be useful in debugging and status pages. |
|
Express a time delta in words, e.g. |
|
Like relative_time_string, but using a sign_mode (-, +, etc) instead of "ago" and "from now." |
Classes
|
This class just wraps some handy constants to pass as 'format' to now_and_then. |
- pyppin.text.now_and_then.now_and_then(now: Optional[datetime], then: datetime, julian: bool = False, format: Optional[str] = None) str [source]¶
Output a string ‘{then}, {duration} ago’ or ‘{then}, {duration} from now’, or the like, expressing “then” in terms of “now.” This tends to be useful in debugging and status pages.
For hopefully obvious reasons, don’t use this in outside-facing UI’s; this code is 100% English-based, and would be virtually impossible to localize, as different cultures express temporal relationships differently.
- Parameters
now – The current time, which we use as a baseline. If not given, we use right now.
then – The time we want to express
julian – If True, use Julian (astronomical) years for intervals longer than a year; otherwise, use Gregorian years.
format – If given, the format in which to print out ‘now’. The default is to use ISO format.
The argument order may seem a bit counterintuitive at first (why is the time we want to express the second argument??) but experiment shows it works well, because it matches the name of the function, which is also a common English idiom, and you usually have a variable named ‘now’ anyway!
- class pyppin.text.now_and_then.Formats[source]¶
Bases:
object
This class just wraps some handy constants to pass as ‘format’ to now_and_then.
- pyppin.text.now_and_then.relative_time_string(delta: timedelta, julian: bool = False) str [source]¶
Express a time delta in words, e.g. “15 seconds ago” or “3 years from now.”
- Parameters
delta – The time to be expressed.
julian – If True, use Julian (astronomical) years; otherwise, use Gregorian years.
- pyppin.text.now_and_then.time_delta_string(delta: timedelta, julian: bool = False, sign_mode: Sign = Sign.NEGATIVE_ONLY) str [source]¶
Like relative_time_string, but using a sign_mode (-, +, etc) instead of “ago” and “from now.”
So for example, it may yield “+3 years” or “-15 seconds” rather than “3 years from now” and “15 seconds ago.”