beansoup.utils package¶
Submodules¶
beansoup.utils.dates module¶
Utilities for working with dates.
-
beansoup.utils.dates.add_biz_days(date, num_biz_days)[source]¶ Add a number of business days to a date.
If the starting date falls on a weekend, it is moved to the next business day before adding the delta.
Parameters: - date – The starting date; a datetime.date object.
- num_biz_days – The number of business days to add to the starting date; a non-negative int.
Returns: A datetime.date object.
-
beansoup.utils.dates.month_number(month)[source]¶ Turns a month name into its corresponding month number.
It recognizes full and abbreviated (three letters) English month names (case insensitive) as well as month number with or without a leading 0.
Parameters: month (str) – The name of a month or its three-letter abbreviation or its numerical equivalent. Returns: The number in [1,12] corresponding to the given month name, or None if it does not recognize the given name. Return type: int or None
beansoup.utils.links module¶
Utilities for working with links.
-
beansoup.utils.links.count(link_prefix=None, start=1)[source]¶ An iterator that returns unique link names.
Parameters: - link_prefix – A string or None. If the former, link names will be of the form link_prefix-#; otherwise, they will be UUIDs.
- start – An integer; the start of the number sequence when used with a link prefix.
Returns: An iterator that returns unique link names as strings.
beansoup.utils.periods module¶
Utilities to work with monthly billing periods.
-
beansoup.utils.periods.count(date, reverse=False)[source]¶ Make an iterator that returns monthly-spaced dates.
Parameters: - date – A datetime.date object; the starting date.
- reverse – A boolean value; if True, the iterator will go back in time.
Returns: An iterator.
-
beansoup.utils.periods.enclose_date(date, first_day=1)[source]¶ Compute the monthly period containing the given date.
Parameters: - date – A datetime.date object.
- first_day – The first day of the monthly cycle. It must be an int in the interval [1,28].
Returns: A pair of datetime.date objects; the start and end dates of the monthly period containing the given date.
-
beansoup.utils.periods.greatest_start(date, first_day=1)[source]¶ Compute the starting date of the monthly period containing the given date.
More formally, it computes the greatest start date of the monthly cycle based on first_day that is less than or equal to the given date.
Parameters: - date – A datetime.date object.
- first_day – The first day of the monthly cycle. It must be an int in the interval [1,28].
Returns: The starting date of the monthly period containing the given date as a datetime.date object.
-
beansoup.utils.periods.lowest_end(date, first_day=1)[source]¶ Compute the ending date of the monthly period containing the given date.
More formally, it computes the lowest end date of the monthly cycle based on first_day that is greater than or equal to the given date.
Parameters: - date – A datetime.date object.
- first_day – The first day of the monthly cycle. It must be an int in the interval [1,28].
Returns: The ending date of the monthly period containing the given date as a datetime.date object.
-
beansoup.utils.periods.next(date)[source]¶ Add one month to the given date.
Note that if the given date falls on a day of the month greater than the number of days in the following month, the result will not have the same day of the month as the input. For example:
next(datetime.date(2015, 1, 30)) == datetime.date(2015, 3, 2)Parameters: date – A datetime.date object. Returns: A datetime.date object whose value is one month later than the given date.
-
beansoup.utils.periods.prev(date)[source]¶ Subtract one month from the given date.
Note that if the given date falls on a day of the month greater than the number of days in the following month, the result will not have the same day of the month as the input. For example:
prev(datetime.date(2015, 3, 30)) == datetime.date(2015, 3, 2)Parameters: date – A datetime.date object. Returns: A datetime.date object whose value is one month earlier than the given date.