Other helper methods

General utility functions used within Omnipresence.

omnipresence.util.ago(then, now=None)[source]

Given a datetime object, return a string giving an approximate relative time, such as “5 days ago”.

omnipresence.util.andify(seq, two_comma=False)[source]

Given a list, join its elements and return a string of the form “x and y” for a two-element list, or “x, y, and z” for three or more elements. If two_comma is True, insert a comma before “and” even if the list is only two elements long (“x, and y”).


Convert a duration of the form ”?w?d?h?m?s” into a datetime.timedelta object, where individual components are optional.


Convert a duration of the form ”?w?d?h?m?s” to a readable string representation of the form “2 weeks, 5 days, and 20 hours”.

omnipresence.util.truncate_unicode(s, char_limit, byte_limit, encoding='utf-8')[source]

Truncate a Unicode string so that it fits both within the specified character limit and, when encoded in the given encoding, the specified byte limit. Return the truncated string as a byte string.