projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Change settings in flake8 and black.
[python_utils.git]
/
dateparse
/
dateparse_utils.py
diff --git
a/dateparse/dateparse_utils.py
b/dateparse/dateparse_utils.py
index bf1f10abb0e483a1998bd1035f9e50f9a6eef004..54a47366b6f6493ca7766d6ff72e52a0ac87cf54 100755
(executable)
--- a/
dateparse/dateparse_utils.py
+++ b/
dateparse/dateparse_utils.py
@@
-24,12
+24,7
@@
import decorator_utils
from dateparse.dateparse_utilsLexer import dateparse_utilsLexer # type: ignore
from dateparse.dateparse_utilsListener import dateparse_utilsListener # type: ignore
from dateparse.dateparse_utilsParser import dateparse_utilsParser # type: ignore
from dateparse.dateparse_utilsLexer import dateparse_utilsLexer # type: ignore
from dateparse.dateparse_utilsListener import dateparse_utilsListener # type: ignore
from dateparse.dateparse_utilsParser import dateparse_utilsParser # type: ignore
-from datetime_utils import (
- TimeUnit,
- date_to_datetime,
- datetime_to_date,
- n_timeunits_from_base,
-)
+from datetime_utils import TimeUnit, date_to_datetime, datetime_to_date, n_timeunits_from_base
logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)
@@
-65,9
+60,7
@@
class RaisingErrorListener(antlr4.DiagnosticErrorListener):
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
raise ParseException(msg)
def syntaxError(self, recognizer, offendingSymbol, line, column, msg, e):
raise ParseException(msg)
- def reportAmbiguity(
- self, recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs
- ):
+ def reportAmbiguity(self, recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs):
pass
def reportAttemptingFullContext(
pass
def reportAttemptingFullContext(
@@
-75,9
+68,7
@@
class RaisingErrorListener(antlr4.DiagnosticErrorListener):
):
pass
):
pass
- def reportContextSensitivity(
- self, recognizer, dfa, startIndex, stopIndex, prediction, configs
- ):
+ def reportContextSensitivity(self, recognizer, dfa, startIndex, stopIndex, prediction, configs):
pass
pass
@@
-435,7
+426,14
@@
class DateParser(dateparse_utilsListener):
micros = self.time.microsecond
self.datetime = datetime.datetime(
micros = self.time.microsecond
self.datetime = datetime.datetime(
- year, month, day, hour, minute, second, micros, tzinfo=self.time.tzinfo
+ year,
+ month,
+ day,
+ hour,
+ minute,
+ second,
+ micros,
+ tzinfo=self.time.tzinfo,
)
# Apply resudual adjustments to times here when we have a
)
# Apply resudual adjustments to times here when we have a
@@
-550,9
+548,7
@@
class DateParser(dateparse_utilsListener):
else:
raise ParseException(f'Invalid Unit: "{unit}"')
else:
raise ParseException(f'Invalid Unit: "{unit}"')
- def exitDeltaPlusMinusExpr(
- self, ctx: dateparse_utilsParser.DeltaPlusMinusExprContext
- ) -> None:
+ def exitDeltaPlusMinusExpr(self, ctx: dateparse_utilsParser.DeltaPlusMinusExprContext) -> None:
try:
n = ctx.nth()
if n is None:
try:
n = ctx.nth()
if n is None:
@@
-574,17
+570,13
@@
class DateParser(dateparse_utilsListener):
else:
self.context['delta_unit'] = unit
else:
self.context['delta_unit'] = unit
- def exitDeltaNextLast(
- self, ctx: dateparse_utilsParser.DeltaNextLastContext
- ) -> None:
+ def exitDeltaNextLast(self, ctx: dateparse_utilsParser.DeltaNextLastContext) -> None:
try:
txt = ctx.getText().lower()
except Exception:
raise ParseException(f'Bad next/last: {ctx.getText()}')
if 'month' in self.context or 'day' in self.context or 'year' in self.context:
try:
txt = ctx.getText().lower()
except Exception:
raise ParseException(f'Bad next/last: {ctx.getText()}')
if 'month' in self.context or 'day' in self.context or 'year' in self.context:
- raise ParseException(
- 'Next/last expression expected to be relative to today.'
- )
+ raise ParseException('Next/last expression expected to be relative to today.')
if txt[:4] == 'next':
self.context['delta_int'] = +1
self.context['day'] = self.now_datetime.day
if txt[:4] == 'next':
self.context['delta_int'] = +1
self.context['day'] = self.now_datetime.day
@@
-613,9
+605,7
@@
class DateParser(dateparse_utilsListener):
if 'time_delta_before_after' not in self.context:
raise ParseException(f'Bad Before/After: {ctx.getText()}')
if 'time_delta_before_after' not in self.context:
raise ParseException(f'Bad Before/After: {ctx.getText()}')
- def exitDeltaTimeFraction(
- self, ctx: dateparse_utilsParser.DeltaTimeFractionContext
- ) -> None:
+ def exitDeltaTimeFraction(self, ctx: dateparse_utilsParser.DeltaTimeFractionContext) -> None:
try:
txt = ctx.getText().lower()[:4]
if txt == 'quar':
try:
txt = ctx.getText().lower()[:4]
if txt == 'quar':
@@
-629,9
+619,7
@@
class DateParser(dateparse_utilsListener):
except Exception:
raise ParseException(f'Bad time fraction {ctx.getText()}')
except Exception:
raise ParseException(f'Bad time fraction {ctx.getText()}')
- def exitDeltaBeforeAfter(
- self, ctx: dateparse_utilsParser.DeltaBeforeAfterContext
- ) -> None:
+ def exitDeltaBeforeAfter(self, ctx: dateparse_utilsParser.DeltaBeforeAfterContext) -> None:
try:
txt = ctx.getText().lower()
except Exception:
try:
txt = ctx.getText().lower()
except Exception:
@@
-639,9
+627,7
@@
class DateParser(dateparse_utilsListener):
else:
self.context['delta_before_after'] = txt
else:
self.context['delta_before_after'] = txt
- def exitDeltaTimeBeforeAfter(
- self, ctx: dateparse_utilsParser.DeltaBeforeAfterContext
- ) -> None:
+ def exitDeltaTimeBeforeAfter(self, ctx: dateparse_utilsParser.DeltaBeforeAfterContext) -> None:
try:
txt = ctx.getText().lower()
except Exception:
try:
txt = ctx.getText().lower()
except Exception:
@@
-803,9
+789,7
@@
class DateParser(dateparse_utilsListener):
special = ctx.specialDate().getText().lower()
self.context['special'] = special
except Exception:
special = ctx.specialDate().getText().lower()
self.context['special'] = special
except Exception:
- raise ParseException(
- f'Bad specialDate expression: {ctx.specialDate().getText()}'
- )
+ raise ParseException(f'Bad specialDate expression: {ctx.specialDate().getText()}')
try:
mod = ctx.thisNextLast()
if mod is not None:
try:
mod = ctx.thisNextLast()
if mod is not None:
@@
-889,9
+873,7
@@
class DateParser(dateparse_utilsListener):
self.context['month'] = d.month
self.context['day'] = d.day
self.context['month'] = d.month
self.context['day'] = d.day
- def exitSpecialTimeExpr(
- self, ctx: dateparse_utilsParser.SpecialTimeExprContext
- ) -> None:
+ def exitSpecialTimeExpr(self, ctx: dateparse_utilsParser.SpecialTimeExprContext) -> None:
try:
txt = ctx.specialTime().getText().lower()
except Exception:
try:
txt = ctx.specialTime().getText().lower()
except Exception:
@@
-916,9
+898,7
@@
class DateParser(dateparse_utilsListener):
except Exception:
pass
except Exception:
pass
- def exitTwelveHourTimeExpr(
- self, ctx: dateparse_utilsParser.TwelveHourTimeExprContext
- ) -> None:
+ def exitTwelveHourTimeExpr(self, ctx: dateparse_utilsParser.TwelveHourTimeExprContext) -> None:
try:
hour = ctx.hour().getText()
while not hour[-1].isdigit():
try:
hour = ctx.hour().getText()
while not hour[-1].isdigit():