parse_int

class convert2.parse_int.Anything2Int[source]

Parse anything to int.

The logic:

  • for int: force to be generic int type.
  • for float: round.
  • for str: extract int from string, for exmplae: “you have 5 dollar” -> 5
    if there is more than 1 integer, “You got 3, he got 4”, raise ValueError
  • for datetime: it’s utc timestamp. Ignore milliseconds.
  • for date: it’s days from ordinary.
  • for timedelta: its total seconds, Ignore milliseconds.