Converts the value into a unix time (seconds since unix epoch). For example: convert.time(datetime.now()) # '1409810596' :param arg: The time. :type arg: datetime.datetime or int
(arg)
| 173 | |
| 174 | |
| 175 | def time(arg): |
| 176 | """Converts the value into a unix time (seconds since unix epoch). |
| 177 | |
| 178 | For example: |
| 179 | convert.time(datetime.now()) |
| 180 | # '1409810596' |
| 181 | |
| 182 | :param arg: The time. |
| 183 | :type arg: datetime.datetime or int |
| 184 | """ |
| 185 | # handle datetime instances. |
| 186 | if _has_method(arg, "timestamp"): |
| 187 | arg = arg.timestamp() |
| 188 | |
| 189 | if isinstance(arg, float): |
| 190 | arg = int(arg) |
| 191 | |
| 192 | return str(arg) |
| 193 | |
| 194 | |
| 195 | def _has_method(arg, method): |
nothing calls this directly
no test coverage detected