Rename SealedDate.__str__ to partial_isoformat

Django uses `str(date)` for backends other than PostgreSQL, so do not
break "YYYY-MM-DD" formatting, just in case.
This commit is contained in:
Adeodato Simó 2023-10-21 16:55:24 -03:00
parent a9c605ea97
commit 46d80d56a5
No known key found for this signature in database
GPG key ID: CDF447845F1A986F
2 changed files with 6 additions and 6 deletions

View file

@ -14,14 +14,14 @@ class SealedDateTest(unittest.TestCase):
def test_day_seal(self):
sealed = sealed_date.SealedDate.from_datetime(self.dt)
self.assertEqual(self.dt, sealed)
self.assertEqual("2023-10-20", str(sealed))
self.assertEqual("2023-10-20", sealed.partial_isoformat())
def test_month_seal(self):
sealed = sealed_date.MonthSeal.from_datetime(self.dt)
self.assertEqual(self.dt, sealed)
self.assertEqual("2023-10", str(sealed))
self.assertEqual("2023-10", sealed.partial_isoformat())
def test_year_seal(self):
sealed = sealed_date.YearSeal.from_datetime(self.dt)
self.assertEqual(self.dt, sealed)
self.assertEqual("2023", str(sealed))
self.assertEqual("2023", sealed.partial_isoformat())

View file

@ -12,7 +12,7 @@ class SealedDate(datetime): # TODO: migrate from DateTimeField to DateField
def has_month(self) -> bool:
return True
def __str__(self):
def partial_isoformat(self) -> str:
return self.strftime("%Y-%m-%d")
@classmethod
@ -26,7 +26,7 @@ class MonthSeal(SealedDate):
def has_day(self) -> bool:
return False
def __str__(self):
def partial_isoformat(self) -> str:
return self.strftime("%Y-%m")
@ -35,5 +35,5 @@ class YearSeal(SealedDate):
def has_month(self) -> bool:
return False
def __str__(self):
def partial_isoformat(self) -> str:
return self.strftime("%Y")