File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -365,7 +365,7 @@ def __contains__(self, other: object) -> bool:
365365
366366 @classmethod
367367 def to_undate (cls , other : object ) -> "Undate" :
368- """Converted arbitrary object to Undate, if possible. Raises TypeError
368+ """Convert arbitrary object to Undate, if possible. Raises TypeError
369369 if conversion is not possible.
370370
371371 Currently suppports:
@@ -377,6 +377,9 @@ def to_undate(cls, other: object) -> "Undate":
377377 return other
378378 case datetime .date () | datetime .datetime ():
379379 return Undate (other .year , other .month , other .day )
380+ case Date ():
381+ # handle conversion from internal Date class
382+ return Undate (other .year , other .month , other .day )
380383
381384 case _:
382385 raise TypeError (f"Conversion from { type (other )} is not supported" )
Original file line number Diff line number Diff line change 44
55from undate import Undate , UndateInterval , Calendar
66from undate .converters .base import BaseCalendarConverter
7- from undate .date import DatePrecision , Timedelta
7+ from undate .date import Date , DatePrecision , Timedelta
88
99
1010class TestUndate :
@@ -152,6 +152,14 @@ def test_to_undate(self):
152152 assert isinstance (undate_from_dt , Undate )
153153 assert undate_from_dt == Undate (now .year , now .month , now .day )
154154
155+ # from internal Date object
156+ y2k = Date (2000 )
157+ y2k_to_undate = Undate .to_undate (y2k )
158+ assert isinstance (y2k_to_undate , Undate )
159+ assert int (y2k_to_undate .year ) == y2k .year
160+ assert y2k_to_undate .month is None
161+ assert y2k_to_undate .day is None
162+
155163 # unsupported type
156164 with pytest .raises (TypeError ):
157165 Undate .to_undate ("foo" )
You can’t perform that action at this time.
0 commit comments