forked from 6tail/lunar-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolarYear.py
More file actions
54 lines (41 loc) · 1.1 KB
/
SolarYear.py
File metadata and controls
54 lines (41 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
from . import SolarMonth
class SolarYear:
"""
阳历年
"""
MONTH_COUNT = 12
def __init__(self, year):
self.__year = year
@staticmethod
def fromDate(date):
return SolarYear(date.year)
@staticmethod
def fromYear(year):
return SolarYear(year)
def getYear(self):
return self.__year
def toString(self):
return str(self.__year)
def toFullString(self):
return "%d年" % self.__year
def __str__(self):
return self.toString()
def getMonths(self):
"""
获取本年的阳历月列表
:return: 阳历月列表
"""
months = []
m = SolarMonth.fromYm(self.__year, 1)
months.append(m)
for i in range(1, SolarYear.MONTH_COUNT):
months.append(m.next(i))
return months
def next(self, years):
"""
获取往后推几年的阳历年,如果要往前推,则月数用负数
:param years: 年数
:return: 阳历年
"""
return SolarYear.fromYear(self.__year + years)