@@ -38,32 +38,40 @@ def __str__(self):
3838 """
3939 Transform period to a string.
4040
41- >>> str(period(YEAR, 2014))
42- '2014'
43-
44- >>> str(period(YEAR, '2014-2'))
45- 'year:2014-02'
46- >>> str(period(MONTH, '2014-2'))
47- '2014-02'
48-
49- >>> str(period(YEAR, 2012, size = 2))
50- 'year:2012:2'
51- >>> str(period(MONTH, 2012, size = 2))
52- 'month:2012-01:2'
53- >>> str(period(MONTH, 2012, size = 12))
54- '2012'
55-
56- >>> str(period(YEAR, '2012-3', size = 2))
57- 'year:2012-03:2'
58- >>> str(period(MONTH, '2012-3', size = 2))
59- 'month:2012-03:2'
60- >>> str(period(MONTH, '2012-3', size = 12))
61- 'year:2012-03'
41+ >>> str(Period((DateUnit.YEAR, Instant((2021, 1, 1)), 1)))
42+ '2021'
43+
44+ >>> str(Period((DateUnit.YEAR, Instant((2021, 2, 1)), 1)))
45+ 'year:2021-02'
46+
47+ >>> str(Period((DateUnit.MONTH, Instant((2021, 2, 1)), 1)))
48+ '2021-02'
49+
50+ >>> str(Period((DateUnit.YEAR, Instant((2021, 1, 1)), 2)))
51+ 'year:2021:2'
52+
53+ >>> str(Period((DateUnit.MONTH, Instant((2021, 1, 1)), 2)))
54+ 'month:2021-01:2'
55+
56+ >>> str(Period((DateUnit.MONTH, Instant((2021, 1, 1)), 12)))
57+ '2021'
58+
59+ >>> str(Period((DateUnit.YEAR, Instant((2021, 3, 1)), 2)))
60+ 'year:2021-03:2'
61+
62+ >>> str(Period((DateUnit.MONTH, Instant((2021, 3, 1)), 2)))
63+ 'month:2021-03:2'
64+
65+ >>> str(Period((DateUnit.MONTH, Instant((2021, 3, 1)), 12)))
66+ 'year:2021-03'
67+
6268 """
6369
6470 unit , start_instant , size = self
71+
6572 if unit == DateUnit .ETERNITY :
6673 return 'ETERNITY'
74+
6775 year , month , day = start_instant
6876
6977 # 1 year long period
@@ -73,10 +81,12 @@ def __str__(self):
7381 return str (year )
7482 else :
7583 # rolling year
76- return '{}:{}-{:02d}' .format (DateUnit .YEAR .value , year , month )
84+ return '{}:{}-{:02d}' .format (DateUnit .YEAR , year , month )
85+
7786 # simple month
7887 if unit == DateUnit .MONTH and size == 1 :
7988 return '{}-{:02d}' .format (year , month )
89+
8090 # several civil years
8191 if unit == DateUnit .YEAR and month == 1 :
8292 return '{}:{}:{}' .format (unit , year , size )
0 commit comments