Classes | Functions | Variables
mycroft.util.format Namespace Reference

Classes

class  DateTimeFormat
 

Functions

def _translate_word (name, lang)
 
def expand_options
 
def join_list (items, connector, sep=None, lang=None)
 
def nice_date (dt, lang=None, now=None)
 
def nice_date_time (dt, lang=None, now=None, use_24hour=False, use_ampm=False)
 
def nice_duration (duration, lang=None, speech=True)
 
def nice_number (number, lang=None, speech=True, denominators=None)
 
def nice_time (dt, lang=None, speech=True, use_24hour=False, use_ampm=False)
 
def nice_year (dt, lang=None, bc=False)
 
def pronounce_number (number, lang=None, places=2, short_scale=True, scientific=False)
 

Variables

 date_time_format
 
 NUMBER_TUPLE
 

Function Documentation

def mycroft.util.format._translate_word (   name,
  lang 
)
private
Helper to get word tranlations

Args:
    name (str): Word name. Returned as the default value if not translated.
    lang (str): Language code, e.g. "en-us"

Returns:
    str: translated version of resource name

Definition at line 50 of file format.py.

def mycroft.util.format.expand_options (   parentheses_line)

Definition at line 550 of file format.py.

def mycroft.util.format.join_list (   items,
  connector,
  sep = None,
  lang = None 
)
Join a list into a phrase using the given connector word

Examples:
    join_list([1,2,3], "and") ->  "1, 2 and 3"
    join_list([1,2,3], "and", ";") ->  "1; 2 and 3"

Args:
    items(array): items to be joined
    connector(str): connecting word (resource name), like "and" or "or"
    sep(str, optional): separator character, default = ","
Returns:
    str: the connected list phrase

Definition at line 521 of file format.py.

def mycroft.util.format.nice_date (   dt,
  lang = None,
  now = None 
)
Format a datetime to a pronounceable date

For example, generates 'tuesday, june the fifth, 2018'
Args:
    dt (datetime): date to format (assumes already in local timezone)
    lang (string): the language to use, use Mycroft default language if not
        provided
    now (datetime): Current date. If provided, the returned date for speech
        will be shortened accordingly: No year is returned if now is in the
        same year as td, no month is returned if now is in the same month
        as td. If now and td is the same day, 'today' is returned.
Returns:
    (str): The formatted date string

Definition at line 371 of file format.py.

def mycroft.util.format.nice_date_time (   dt,
  lang = None,
  now = None,
  use_24hour = False,
  use_ampm = False 
)
    Format a datetime to a pronounceable date and time

    For example, generate 'tuesday, june the fifth, 2018 at five thirty'

    Args:
        dt (datetime): date to format (assumes already in local timezone)
        lang (string): the language to use, use Mycroft default language if
            not provided
        now (datetime): Current date. If provided, the returned date for
            speech will be shortened accordingly: No year is returned if
            now is in the same year as td, no month is returned if now is
            in the same month as td. If now and td is the same day, 'today'
            is returned.
        use_24hour (bool): output in 24-hour/military or 12-hour format
        use_ampm (bool): include the am/pm for 12-hour format
    Returns:
        (str): The formatted date time string

Definition at line 394 of file format.py.

def mycroft.util.format.nice_duration (   duration,
  lang = None,
  speech = True 
)
Convert duration in seconds to a nice spoken timespan

Examples:
   duration = 60  ->  "1:00" or "one minute"
   duration = 163  ->  "2:43" or "two minutes forty three seconds"

Args:
    duration: time, in seconds
    lang (str, optional): a BCP-47 language code, None for default
    speech (bool): format for speech (True) or display (False)
Returns:
    str: timespan as a string

Definition at line 444 of file format.py.

def mycroft.util.format.nice_number (   number,
  lang = None,
  speech = True,
  denominators = None 
)
Format a float to human readable functions

This function formats a float to human understandable functions. Like
4.5 becomes 4 and a half for speech and 4 1/2 for text
Args:
    number (int or float): the float to format
    lang (str): code for the language to use
    speech (bool): format for speech (True) or display (False)
    denominators (iter of ints): denominators to use, default [1 .. 20]
Returns:
    (str): The formatted string.

Definition at line 246 of file format.py.

def mycroft.util.format.nice_time (   dt,
  lang = None,
  speech = True,
  use_24hour = False,
  use_ampm = False 
)
Format a time to a comfortable human format

For example, generate 'five thirty' for speech or '5:30' for
text display.

Args:
    dt (datetime): date to format (assumes already in local timezone)
    lang (str): code for the language to use
    speech (bool): format for speech (default/True) or display (False)
    use_24hour (bool): output in 24-hour/military or 12-hour format
    use_ampm (bool): include the am/pm for 12-hour format
Returns:
    (str): The formatted time string

Definition at line 288 of file format.py.

def mycroft.util.format.nice_year (   dt,
  lang = None,
  bc = False 
)
    Format a datetime to a pronounceable year

    For example, generate 'nineteen-hundred and eighty-four' for year 1984

    Args:
        dt (datetime): date to format (assumes already in local timezone)
        lang (string): the language to use, use Mycroft default language if
        not provided
        bc (bool) pust B.C. after the year (python does not support dates
            B.C. in datetime)
    Returns:
        (str): The formatted year string

Definition at line 422 of file format.py.

def mycroft.util.format.pronounce_number (   number,
  lang = None,
  places = 2,
  short_scale = True,
  scientific = False 
)
Convert a number to it's spoken equivalent

For example, '5' would be 'five'

Args:
    number: the number to pronounce
    short_scale (bool) : use short (True) or long scale (False)
        https://en.wikipedia.org/wiki/Names_of_large_numbers
    scientific (bool) : convert and pronounce in scientific notation
Returns:
    (str): The pronounced number

Definition at line 329 of file format.py.

Variable Documentation

mycroft.util.format.date_time_format
Initial value:
2  os.path.dirname(os.path.abspath(__file__)) + '/../res/text')

Definition at line 242 of file format.py.

mycroft.util.format.NUMBER_TUPLE
Initial value:
1 = namedtuple(
2  'number',
3  ('x, xx, x0, x_in_x0, xxx, x00, x_in_x00, xx00, xx_in_xx00, x000, ' +
4  'x_in_x000, x0_in_x000, x_in_0x00'))

Definition at line 79 of file format.py.



mycroft_ros
Author(s):
autogenerated on Mon Apr 26 2021 02:35:41