| 1 |
"""Dates. |
| 2 |
|
| 3 |
--- |
| 4 |
layout: post |
| 5 |
source: Garner's Modern American Usage |
| 6 |
source_url: http://bit.ly/1T4alrY |
| 7 |
title: dates |
| 8 |
date: 2014-06-10 12:31:19 |
| 9 |
categories: writing |
| 10 |
--- |
| 11 |
|
| 12 |
Dates. |
| 13 |
|
| 14 |
""" |
| 15 |
import calendar |
| 16 |
|
| 17 |
from proselint.tools import existence_check, memoize |
| 18 |
|
| 19 |
|
| 20 |
@memoize |
| 21 |
def check_decade_apostrophes_short(text): |
| 22 |
"""Check the text for dates of the form X0's.""" |
| 23 |
err = "dates_times.dates" |
| 24 |
msg = "Apostrophes aren't needed for decades." |
| 25 |
|
| 26 |
regex = r"\d0\'s" |
| 27 |
|
| 28 |
return existence_check( |
| 29 |
text, [regex], err, msg, excluded_topics=["50 Cent"]) |
| 30 |
|
| 31 |
|
| 32 |
@memoize |
| 33 |
def check_decade_apostrophes_long(text): |
| 34 |
"""Check the text for dates of the form XXX0's.""" |
| 35 |
err = "dates_times.dates" |
| 36 |
msg = "Apostrophes aren't needed for decades." |
| 37 |
|
| 38 |
regex = r"\d\d\d0\'s" |
| 39 |
return existence_check(text, [regex], err, msg) |
| 40 |
|
| 41 |
|
| 42 |
@memoize |
| 43 |
def check_dash_and_from(text): |
| 44 |
"""Check the text.""" |
| 45 |
err = "dates_times.dates" |
| 46 |
msg = "When specifying a date range, write 'from X to Y'." |
| 47 |
|
| 48 |
regex = r"[fF]rom \d+[^ \t\n\r\f\va-zA-Z0-9_\.]\d+" |
| 49 |
return existence_check(text, [regex], err, msg) |
| 50 |
|
| 51 |
|
| 52 |
def check_month_year_comma(text): |
| 53 |
"""Check the text.""" |
| 54 |
err = "dates_times.dates" |
| 55 |
msg = "When specifying a month and year, no comma is needed." |
| 56 |
|
| 57 |
regex = r"(?:" + "|".join(calendar.month_name[1:]) + r"), \d{3,}" |
| 58 |
return existence_check(text, [regex], err, msg) |
| 59 |
|
| 60 |
|
| 61 |
@memoize |
| 62 |
def check_month_of_year(text): |
| 63 |
"""Check the text.""" |
| 64 |
err = "dates_times.dates" |
| 65 |
msg = "When specifying a month and year, 'of' is unnecessary." |
| 66 |
|
| 67 |
regex = r"(?:" + "|".join(calendar.month_name[1:]) + r") of \d{3,}" |
| 68 |
return existence_check(text, [regex], err, msg) |