From 7800a157bf1b4526aaa240fce504f3264340160c Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Wed, 19 Aug 2020 08:24:42 +0200 Subject: [PATCH] Convert Rdate object to keep working --- relational/rtypes.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/relational/rtypes.py b/relational/rtypes.py index 419f2f5..c6bf33c 100644 --- a/relational/rtypes.py +++ b/relational/rtypes.py @@ -63,19 +63,25 @@ def cast(value: str, guesses: Set) -> CastValue: return value -class Rdate(datetime.date): +class Rdate: '''Represents a date''' def __init__(self, date): '''date: A string representing a date''' - if not isinstance(date, Rstring): - date = Rstring(date) + r = _date_regexp.match(date) + if not r: + raise ValueError(f'{date} is not a valid date') - self.intdate = date.getDate() - self.day = self.intdate.day - self.month = self.intdate.month - self.weekday = self.intdate.weekday() - self.year = self.intdate.year + year = int(r.group(1)) + month = int(r.group(3)) + day = int(r.group(5)) + d = datetime.date(year, month, day) + + self.intdate = d + self.day = d.day + self.month = d.month + self.weekday = d.weekday() + self.year = d.year def __hash__(self): return self.intdate.__hash__()