Simple quarter support for python datetime.date
- Install via pip (
pip install datetime-quarter
) - or via git (
git clone "https://github.com/BetaS/datetime-quarter"
) - Check availability in your project like below
from datequarter import DateQuarter
sample = DateQuarter(2019, 4)
print(sample) # 2019 4Q
item = DateQuarter(2019, 4) # 2019 4Q
item = DateQuarter(2018, 8) # 2019 4Q
for convinienceitem = DateQuarter.from_date(datetime.date(2019, 12, 31)) # 2019 4Q
DateQuarter(2019, 4)+1 # 2020 1Q
DateQuarter(2019, 4)-4 # 2018 4Q
DateQuarter(2019, 4) - DateQuarter(2019, 1) # 3Q
DateQuarter(2019, 1) - DateQuarter(2019, 4) # -3Q
DateQuarter(2019, 1) > DateQuarter(2019, 4) # False
DateQuarter(2019, 1) < DateQuarter(2019, 4) # True
DateQuarter(2019, 1) == DateQuarter(2019, 4) # False
DateQuarter(2019, 1) != DateQuarter(2019, 4) # True
- also support
>=
and<=
datetime.date(2019, 12, 31) in DateQuarter(2019, 1) # False
datetime.date(2019, 12, 31) in DateQuarter(2019, 4) # True
- also support
>
,>=
and vice versa
DateQuarter(2019, 1).start_date() # datetime.date(2019, 1, 1)
DateQuarter(2019, 1).end_date() # datetime.date(2019, 3, 31)
quarter = DateQuarter(2019, 1)
for day in quarter.days():
print(day) # [datetime.date(2019, 1, 1), ..., datetime.date(2019, 3, 31)]
start = DateQuarter(2019, 1)
end = DateQuarter(2019, 4)
for quarter in DateQuarter.between(start, end):
print(quarter) # [DateQuarter(2019, 1), DateQuarter(2019, 2) , DateQuarter(2019,3)]
- also it support reversed case