Debian Codegraph @

proselint/checks/dates_times/am_pm.py

raw
1 """a.m. / p.m.
2
3 ---
4 layout: post
5 source: Garner's Modern American Usage
6 source_url: http://bit.ly/1T4alrY
7 title: a.m. & p.m.
8 date: 2014-06-10 12:31:19
9 categories: writing
10 ---
11
12 """
13 from proselint.tools import existence_check, memoize
14
15
16 @memoize
17 def check_lowercase_periods(text):
18 """Check the text."""
19 err = "dates_times.am_pm.lowercase_periods"
20 msg = "With lowercase letters, the periods are standard."
21
22 return existence_check(text, [r"\d{1,2} ?[ap]m"], err, msg,
23 ignore_case=False)
24
25
26 @memoize
27 def check_spacing(text):
28 """Check the text."""
29 err = "dates_times.am_pm.spacing"
30 msg = "It's standard to put a space before 'a.m.' or 'p.m.'."
31
32 return existence_check(text, [r"\d{1,2}[ap]\.?m\.?"], err, msg)
33
34
35 @memoize
36 def check_midnight_noon(text):
37 """Check the text."""
38 err = "dates_times.am_pm.midnight_noon"
39 msg = ("12 a.m. and 12 p.m. are wrong and confusing."
40 " Use 'midnight' or 'noon'.")
41
42 return existence_check(text, [r"12 ?[ap]\.?m\.?"], err, msg)
43
44
45 @memoize
46 def check_redundancy(text):
47 """Check the text."""
48 err = "dates_times.am_pm.midnight_noon"
49 msg = ("'a.m.' is always morning; 'p.m.' is always night.")
50
51 list = [
52 r"\d{1,2} ?a\.?m\.? in the morning",
53 r"\d{1,2} ?p\.?m\.? in the evening",
54 r"\d{1,2} ?p\.?m\.? at night",
55 r"\d{1,2} ?p\.?m\.? in the afternoon",
56 ]
57
58 return existence_check(text, list, err, msg, join=True)