MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / escape_timedelta

Function escape_timedelta

pymysql/converters.py:99–116  ·  view source on GitHub ↗
(obj, mapping=None)

Source from the content-addressed store, hash-verified

97
98
99def escape_timedelta(obj, mapping=None):
100 # timedelta normalizes a negative value so that seconds/microseconds are
101 # non-negative and the sign lives entirely in days, so the signed magnitude
102 # must be reconstructed before it is split into hours/minutes/seconds --
103 # otherwise a negative TIME comes out with complemented sub-hour fields.
104 sign = ""
105 if obj.days < 0:
106 sign = "-"
107 obj = abs(obj)
108
109 micros = obj.microseconds
110 minutes, seconds = divmod(obj.seconds, 60)
111 hours, minutes = divmod(minutes, 60)
112 hours += obj.days * 24
113
114 if micros:
115 return f"'{sign}{hours:02d}:{minutes:02d}:{seconds:02d}.{micros:06d}'"
116 return f"'{sign}{hours:02d}:{minutes:02d}:{seconds:02d}'"
117
118
119def escape_time(obj, mapping=None):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected