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 59 60 61 62 63 64 65 66 67 68
|
"""Dates.
---
layout: post
source: Garner's Modern American Usage
source_url: http://bit.ly/1T4alrY
title: dates
date: 2014-06-10 12:31:19
categories: writing
---
Dates.
"""
import calendar
from proselint.tools import existence_check, memoize
@memoize
def check_decade_apostrophes_short(text):
"""Check the text for dates of the form X0's."""
err = "dates_times.dates"
msg = "Apostrophes aren't needed for decades."
regex = r"\d0\'s"
return existence_check(
text, [regex], err, msg, excluded_topics=["50 Cent"])
@memoize
def check_decade_apostrophes_long(text):
"""Check the text for dates of the form XXX0's."""
err = "dates_times.dates"
msg = "Apostrophes aren't needed for decades."
regex = r"\d\d\d0\'s"
return existence_check(text, [regex], err, msg)
@memoize
def check_dash_and_from(text):
"""Check the text."""
err = "dates_times.dates"
msg = "When specifying a date range, write 'from X to Y'."
regex = r"[fF]rom \d+[^ \t\n\r\f\va-zA-Z0-9_\.]\d+"
return existence_check(text, [regex], err, msg)
def check_month_year_comma(text):
"""Check the text."""
err = "dates_times.dates"
msg = "When specifying a month and year, no comma is needed."
regex = r"(?:" + "|".join(calendar.month_name[1:]) + r"), \d{3,}"
return existence_check(text, [regex], err, msg)
@memoize
def check_month_of_year(text):
"""Check the text."""
err = "dates_times.dates"
msg = "When specifying a month and year, 'of' is unnecessary."
regex = r"(?:" + "|".join(calendar.month_name[1:]) + r") of \d{3,}"
return existence_check(text, [regex], err, msg)
|