def toSolarDate(self):
def _calcDays(yearInfo, month, day, isLeapMonth):<EOL><INDENT>isLeapMonth = int(isLeapMonth)<EOL>res = <NUM_LIT:0><EOL>ok = False<EOL>for _month, _days, _isLeapMonth in self._enumMonth(yearInfo):<EOL><INDENT>if (_month, _isLeapMonth) == (month, isLeapMonth):<EOL><INDENT>if <NUM_LIT:1> <= day <= _days:<EOL><INDENT>res += day - <NUM_LIT:1><EOL>return res<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>res += _days<EOL><DEDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>offset = <NUM_LIT:0><EOL>start_year = <NUM_LIT><EOL>end_year = start_year + len(yearInfos)<EOL>if start_year < <NUM_LIT> or self.year >= end_year:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(start_year, end_year))<EOL><DEDENT>yearIdx = self.year - <NUM_LIT><EOL>for i in range(yearIdx):<EOL><INDENT>offset += yearDays[i]<EOL><DEDENT>offset += _calcDays(yearInfos[yearIdx], self.month, self.day, self.isLeapMonth)<EOL>return self._startDate + datetime.timedelta(days=offset)<EOL>
>>> LunarDate(1900, 1, 1).toSolarDate()
datetime.date(1900, 1, 31)
>>> LunarDate(2008, 9, 4).toSolarDate()
datetime.date(2008, 10, 2)
>>> LunarDate(1976, 8, 8, 1).toSolarDate()
datetime.date(1976, 10, 1)
>>> LunarDate(2004, 1, 30).toSolarDate()
Traceback (most recent call last):
...
ValueError: day out of range
>>> LunarDate(2004, 13, 1).toSolarDate()
Traceback (most recent call last):
...
ValueError: month out of range
>>> LunarDate(2100, 1, 1).toSolarDate()
Traceback (most recent call last):
...
ValueError: year out of range [1900, 2100)
>>>