MCPcopy
hub / github.com/django/django / template_localtime

Function template_localtime

django/utils/timezone.py:146–161  ·  view source on GitHub ↗

Check if value is a datetime and converts it to local time if necessary. If use_tz is provided and is not None, that will force the value to be converted (or not), overriding the value of settings.USE_TZ. This function is designed for use by the template engine.

(value, use_tz=None)

Source from the content-addressed store, hash-verified

144
145
146def template_localtime(value, use_tz=None):
147 """
148 Check if value is a datetime and converts it to local time if necessary.
149
150 If use_tz is provided and is not None, that will force the value to
151 be converted (or not), overriding the value of settings.USE_TZ.
152
153 This function is designed for use by the template engine.
154 """
155 should_convert = (
156 isinstance(value, datetime)
157 and (settings.USE_TZ if use_tz is None else use_tz)
158 and not is_naive(value)
159 and getattr(value, "convert_to_local_time", True)
160 )
161 return localtime(value) if should_convert else value
162
163
164# Utilities

Callers 2

resolveMethod · 0.90
render_value_in_contextFunction · 0.90

Calls 2

is_naiveFunction · 0.85
localtimeFunction · 0.70

Tested by

no test coverage detected