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