Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BC dates in Python

Tags:

python

date

I'm setting out to build an app with Python that will need to handle BC dates extensively (store and retrieve in DB, do calculations). Most dates will be of various uncertainties, like "around 2000BC".

I know Python's datetime library only handles dates from 1 AD.

So far I only found FlexiDate. Are there any other options?

EDIT: The best approach would probably be to store them as strings (have String as the basic data type) and -as suggested- have a custom datetime class which can make some numerical sense of it. For the majority it looks like dates will only consist of a year. There are some interesting problems to solve like "early 500BC", "between 1600BC and 1500BC", "before 1800BC".

like image 428
Roger Avatar asked Apr 07 '13 01:04

Roger


People also ask

How do you write dates in Python?

Use strftime() function of a datetime class The format codes are standard directives for mentioning in which format you want to represent datetime. For example, the %d-%m-%Y %H:%M:%S codes convert date to dd-mm-yyyy hh:mm:ss format.

What does date () do in Python?

The date class is used to instantiate date objects in Python. When an object of this class is instantiated, it represents a date in the format YYYY-MM-DD. Constructor of this class needs three mandatory arguments year, month and date.

Is there a date format in Python?

A date in Python is not a data type of its own, but we can import a module named datetime to work with dates as date objects.

What is the current date in Python?

today() method to get the current local date. By the way, date. today() returns a date object, which is assigned to the today variable in the above program. Now, you can use the strftime() method to create a string representing date in different formats.


1 Answers

Astronomers and aerospace engineers have to deal with BC dates and a continuous time line, so that's the google context for your search.

Astropy's Time class will work for you (and even more precisely and completely than you hoped). pip install astropy and you're on your way.

If you roll your own, you should review some of the formulas in Vallado's chapter on dates. There are lots of obscure fudge factors required to convert dates from Julian to Gregorian etc.

like image 145
hobs Avatar answered Sep 30 '22 10:09

hobs