def in_words(self, locale=None, separator=' '): """ Get the current interval in words in the current locale. Ex: 6 jours 23 heures 58 minutes :param locale: The locale to use. Defaults to current locale. :type locale: str :param separator: The separator to use between each unit :type separator: str :rtype: str """ periods = [ ('year', self.years), ('month', self.months), ('week', self.weeks), ('day', self.remaining_days), ('hour', self.hours), ('minute', self.minutes), ('second', self.remaining_seconds) ] if locale is None: locale = pendulum.get_locale() locale = pendulum.locale(locale) parts = [] for period in periods: unit, count = period if abs(count) > 0: translation = locale.translation( 'units.{}.{}'.format( unit, locale.plural(abs(count)) ) ) parts.append(translation.format(count)) if not parts and abs(self.microseconds) > 0: translation = locale.translation( 'units.second.{}'.format(locale.plural(1)) ) us = abs(self.microseconds) / 1e6 parts.append( translation.format('{:.2f}'.format(us)) ) return decode(separator.join(parts))
def in_words(self, locale=None, separator=" "): """ Get the current interval in words in the current locale. Ex: 6 jours 23 heures 58 minutes :param locale: The locale to use. Defaults to current locale. :type locale: str :param separator: The separator to use between each unit :type separator: str :rtype: str """ periods = [ ("year", self.years), ("month", self.months), ("week", self.weeks), ("day", self.remaining_days), ("hour", self.hours), ("minute", self.minutes), ("second", self.remaining_seconds), ] if locale is None: locale = pendulum.get_locale() locale = pendulum.locale(locale) parts = [] for period in periods: unit, count = period if abs(count) > 0: translation = locale.translation( "units.{}.{}".format(unit, locale.plural(abs(count))) ) parts.append(translation.format(count)) if not parts: if abs(self.microseconds) > 0: unit = "units.second.{}".format(locale.plural(1)) count = "{:.2f}".format(abs(self.microseconds) / 1e6) else: unit = "units.microsecond.{}".format(locale.plural(0)) count = 0 translation = locale.translation(unit) parts.append(translation.format(count)) return decode(separator.join(parts))
def in_words(self, locale=None, separator=" "): """ Get the current interval in words in the current locale. Ex: 6 jours 23 heures 58 minutes :param locale: The locale to use. Defaults to current locale. :type locale: str :param separator: The separator to use between each unit :type separator: str :rtype: str """ periods = [ ("year", self.years), ("month", self.months), ("week", self.weeks), ("day", self.remaining_days), ("hour", self.hours), ("minute", self.minutes), ("second", self.remaining_seconds), ] if locale is None: locale = pendulum.get_locale() locale = pendulum.locale(locale) parts = [] for period in periods: unit, count = period if abs(count) > 0: translation = locale.translation( "units.{}.{}".format(unit, locale.plural(abs(count))) ) parts.append(translation.format(count)) if not parts and abs(self.microseconds) > 0: translation = locale.translation("units.second.{}".format(locale.plural(1))) us = abs(self.microseconds) / 1e6 parts.append(translation.format("{:.2f}").format(us)) return decode(separator.join(parts))