Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/rest_framework/utils/humanize_datetime.py: 29%
15 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1"""
2Helper functions that convert strftime formats into more readable representations.
3"""
4from rest_framework import ISO_8601
7def datetime_formats(formats):
8 format = ', '.join(formats).replace(
9 ISO_8601,
10 'YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z]'
11 )
12 return humanize_strptime(format)
15def date_formats(formats):
16 format = ', '.join(formats).replace(ISO_8601, 'YYYY-MM-DD')
17 return humanize_strptime(format)
20def time_formats(formats):
21 format = ', '.join(formats).replace(ISO_8601, 'hh:mm[:ss[.uuuuuu]]')
22 return humanize_strptime(format)
25def humanize_strptime(format_string):
26 # Note that we're missing some of the locale specific mappings that
27 # don't really make sense.
28 mapping = {
29 "%Y": "YYYY",
30 "%y": "YY",
31 "%m": "MM",
32 "%b": "[Jan-Dec]",
33 "%B": "[January-December]",
34 "%d": "DD",
35 "%H": "hh",
36 "%I": "hh", # Requires '%p' to differentiate from '%H'.
37 "%M": "mm",
38 "%S": "ss",
39 "%f": "uuuuuu",
40 "%a": "[Mon-Sun]",
41 "%A": "[Monday-Sunday]",
42 "%p": "[AM|PM]",
43 "%z": "[+HHMM|-HHMM]"
44 }
45 for key, val in mapping.items():
46 format_string = format_string.replace(key, val)
47 return format_string