Renamed the parameter period_spec to spec in the period parser.

This commit is contained in:
依瑪貓 2020-07-08 08:13:47 +08:00
parent 39d65e1381
commit 56ae1bb29a

View File

@ -32,7 +32,7 @@ class PeriodParser:
"""The period parser. """The period parser.
Args: Args:
period_spec (str): The period specification. spec (str): The period specification.
Attributes: Attributes:
spec (str): The currently-using period specification. spec (str): The currently-using period specification.
@ -48,10 +48,10 @@ class PeriodParser:
description = None description = None
error = None error = None
def __init__(self, period_spec): def __init__(self, spec):
self.spec = period_spec self.spec = spec
# A specific month # A specific month
m = re.match("^([0-9]{4})-([0-9]{2})$", period_spec) m = re.match("^([0-9]{4})-([0-9]{2})$", spec)
if m is not None: if m is not None:
year = int(m.group(1)) year = int(m.group(1))
month = int(m.group(2)) month = int(m.group(2))
@ -64,7 +64,7 @@ class PeriodParser:
self.description = self.get_month_text(year, month) self.description = self.get_month_text(year, month)
return return
# From a specific month # From a specific month
m = re.match("^([0-9]{4})-([0-9]{2})-$", period_spec) m = re.match("^([0-9]{4})-([0-9]{2})-$", spec)
if m is not None: if m is not None:
year = int(m.group(1)) year = int(m.group(1))
month = int(m.group(2)) month = int(m.group(2))
@ -78,7 +78,7 @@ class PeriodParser:
"Since %s") % self.get_month_text(year, month) "Since %s") % self.get_month_text(year, month)
return return
# A specific year # A specific year
m = re.match("^([0-9]{4})$", period_spec) m = re.match("^([0-9]{4})$", spec)
if m is not None: if m is not None:
year = int(m.group(1)) year = int(m.group(1))
try: try:
@ -96,14 +96,14 @@ class PeriodParser:
self.description = str(year) self.description = str(year)
return return
# All time # All time
if period_spec == "-": if spec == "-":
self.start = date(2000, 1, 1) self.start = date(2000, 1, 1)
self.end = self.get_month_last_day(localdate()) self.end = self.get_month_last_day(localdate())
self.description = gettext("All") self.description = gettext("All")
return return
# A specific date # A specific date
m = re.match("^([0-9]{4})-([0-9]{2})-([0-9]{2})$", m = re.match("^([0-9]{4})-([0-9]{2})-([0-9]{2})$",
period_spec) spec)
if m is not None: if m is not None:
try: try:
self.start = date( self.start = date(
@ -117,7 +117,7 @@ class PeriodParser:
# A specific date period # A specific date period
m = re.match(("^([0-9]{4})-([0-9]{2})-([0-9]{2})" m = re.match(("^([0-9]{4})-([0-9]{2})-([0-9]{2})"
"-([0-9]{4})-([0-9]{2})-([0-9]{2})$"), "-([0-9]{4})-([0-9]{2})-([0-9]{2})$"),
period_spec) spec)
if m is not None: if m is not None:
try: try:
self.start = date( self.start = date(