@@ -189,11 +189,12 @@ def test_year_property(self):
189189 # unset year
190190 assert Undate (month = 12 , day = 31 ).year == "XXXX"
191191
192- # NOTE: no longer supported to inistalize undate with no date information
192+ # NOTE: no longer supported to initialize undate with no date information
193193 # force method to hit conditional for date precision
194- # some_century = Undate()
195- # some_century.precision = DatePrecision.CENTURY
196- # assert some_century.year is None
194+ some_century = Undate (year = "X" )
195+ some_century .initial_values ["year" ] = None
196+ some_century .precision = DatePrecision .CENTURY
197+ assert some_century .year is None
197198
198199 def test_month_property (self ):
199200 # one, two digit month
@@ -233,7 +234,8 @@ def test_eq(self):
233234 assert Undate (2022 ) == Undate (2022 )
234235 assert Undate (2022 , 10 ) == Undate (2022 , 10 )
235236 assert Undate (2022 , 10 , 1 ) == Undate (2022 , 10 , 1 )
236- assert Undate (month = 2 , day = 7 ) == Undate (month = 2 , day = 7 )
237+ # dates without a known year cannot known to be equal
238+ assert not Undate (month = 2 , day = 7 ) == Undate (month = 2 , day = 7 )
237239
238240 # something we can't convert for comparison should return NotImplemented
239241 assert Undate (2022 ).__eq__ ("not a date" ) == NotImplemented
@@ -259,6 +261,8 @@ def test_not_eq(self):
259261 # partially unknown dates should NOT be considered equal
260262 assert Undate ("19XX" ) != Undate ("19XX" )
261263 assert Undate (1980 , "XX" ) != Undate (1980 , "XX" )
264+ # same dates with unknown years should not be considered equal
265+ assert Undate (month = 2 , day = 7 ) != Undate (month = 2 , day = 7 )
262266
263267 testdata_lt_gt = [
264268 # dates to test for gt/lt comparison: earlier date, later date
@@ -307,7 +311,23 @@ def test_lte(self, earlier, later):
307311 assert earlier <= later
308312 assert later >= earlier
309313
314+ def test_gt_lt_unknown_years (self ):
315+ # unknown years cannot be compared on either side...
316+ year100 = Undate (100 )
317+ some_january = Undate (month = 1 )
318+ assert not year100 < some_january
319+ assert not year100 <= some_january
320+ assert not year100 > some_january
321+ assert not year100 >= some_january
322+ assert not some_january < year100
323+ assert not some_january <= year100
324+ assert not some_january > year100
325+ assert not some_january >= year100
326+
310327 def test_lt_notimplemented (self ):
328+ # unsupported type should bail out and return NotImplemented
329+ assert Undate (2022 ).__lt__ ("foo" ) == NotImplemented
330+
311331 # how to compare mixed precision where dates overlap?
312332 # if the second date falls *within* earliest/latest,
313333 # then it is not clearly less; not implemented?
@@ -340,6 +360,9 @@ def test_lt_notimplemented(self):
340360 def test_contains (self , date1 , date2 ):
341361 assert date1 in date2
342362
363+ # unsupported type should bail out and return NotImplemented
364+ assert Undate (2022 ).__contains__ ("foo" ) == NotImplemented
365+
343366 testdata_not_contains = [
344367 # dates not in range
345368 (Undate (1980 ), Undate (2020 )),
@@ -359,6 +382,9 @@ def test_contains(self, date1, date2):
359382 (Undate (1980 , "XX" ), Undate (1980 , "XX" )),
360383 # - partially unknown month to unknown month
361384 (Undate (1801 , "1X" ), Undate (1801 , "XX" )),
385+ # fully unknown year
386+ (Undate (month = 6 , day = 1 ), Undate (2022 )),
387+ (Undate (1950 ), Undate (day = 31 )),
362388 ]
363389
364390 @pytest .mark .parametrize ("date1,date2" , testdata_not_contains )
@@ -514,6 +540,7 @@ def test_partiallyknownyear_duration(self):
514540 assert Undate ("XXX" , calendar = "Hebrew" ).duration ().days == UnInt (353 , 385 )
515541
516542 def test_known_year (self ):
543+ # known OR partially known
517544 assert Undate (2022 ).known_year is True
518545 assert Undate (month = 2 , day = 5 ).known_year is False
519546 # partially known year is not known
@@ -535,6 +562,34 @@ def test_is_known_day(self):
535562 assert Undate (month = 1 , day = "X5" ).is_known ("day" ) is False
536563 assert Undate (month = 1 , day = "XX" ).is_known ("day" ) is False
537564
565+ def test_unknown_year (self ):
566+ # fully unknown year
567+ assert Undate (month = 2 , day = 5 ).unknown_year is True
568+ # known or partially known years = all false for unknown
569+ assert Undate (2022 ).unknown_year is False
570+ # partially known year is not unknown
571+ assert Undate ("19XX" ).unknown_year is False
572+ # fully known string year should be known
573+ assert Undate ("1900" ).unknown_year is False
574+
575+ def test_is_unknown_month (self ):
576+ # fully unknown month
577+ assert Undate (2022 ).is_unknown ("month" ) is True
578+ assert Undate (day = 10 ).is_unknown ("month" ) is True
579+ assert Undate (2022 , 2 ).is_unknown ("month" ) is False
580+ assert Undate (2022 , "5" ).is_unknown ("month" ) is False
581+ assert Undate (2022 , "1X" ).is_unknown ("month" ) is False
582+ assert Undate (2022 , "XX" ).is_unknown ("month" ) is False
583+
584+ def test_is_unknown_day (self ):
585+ # fully unknown day
586+ assert Undate (1984 ).is_unknown ("day" ) is True
587+ assert Undate (month = 5 ).is_unknown ("day" ) is True
588+ assert Undate (month = 1 , day = 3 ).is_unknown ("day" ) is False
589+ assert Undate (month = 1 , day = "5" ).is_unknown ("day" ) is False
590+ assert Undate (month = 1 , day = "X5" ).is_unknown ("day" ) is False
591+ assert Undate (month = 1 , day = "XX" ).is_unknown ("day" ) is False
592+
538593 def test_parse (self ):
539594 assert Undate .parse ("1984" , "EDTF" ) == Undate (1984 )
540595 assert Undate .parse ("1984-04" , "EDTF" ) == Undate (1984 , 4 )
@@ -545,7 +600,10 @@ def test_parse(self):
545600
546601 assert Undate .parse ("1984" , "ISO8601" ) == Undate (1984 )
547602 assert Undate .parse ("1984-04" , "ISO8601" ) == Undate (1984 , 4 )
548- assert Undate .parse ("--12-31" , "ISO8601" ) == Undate (month = 12 , day = 31 )
603+ # dates with unknown year are not equal; compare repr string
604+ assert repr (Undate .parse ("--12-31" , "ISO8601" )) == repr (
605+ Undate (month = 12 , day = 31 )
606+ )
549607
550608 # unsupported format
551609 with pytest .raises (ValueError , match = "Unsupported format" ):
0 commit comments