I would like to iterate over days (or better construct an array) of BC dates as I do with typical dates:
from calendar import monthrange
import datetime
for y in range(2010, 2020):
for m in range(1,13):
for d in range(1, monthrange(y, m)[1]+1):
print(datetime.date(year=y,month=m,day=d))
I am aware that this is not possible in pure python datetime library (because of datetime definition) thus I went through this question asked earlier and realized there might be two main options to achieve my task:
- datautil parsed object (from datautil.date import parse) (looks deprecated)
- Astropy object (from astropy.time import Time)
Fiddling with an datautil object (python3's package name is python-dateutil (instead of datautil) and the import differs a bit) confuses me even more as it seems to me the BC date ability is no longer perserved / or it is completely different library:
from dateutil.parser import parse
parse(-200-01-01) # is an AD date object: datetime.datetime(200, 1, 1, 0, 0)
parse(u'200BC') # reports: ValueError: ('Unknown string format:', '200BC')
Speaking about astropy - the only mention about negative dates is in FITS section, but I have absolutely no clue how to use the object. Docs is very sparse, without examples and I did not manage to get it working.
My limited knowledge does not allow me to find anywhere in the documentation, if my approach of creating BC date object in python 3+ is possible and if I am somehow able to iterate over days here.
The only "workaround" (monthrange replacement) I can think of is a function last_day_month submitted by JK elsewhere. But for now, can you suggest any way, how can I build a range of days and iterate over them?