Skip to main content

Preprocessing

DateConvertor

The DateConvertor class is used for converting dates into time steps. This is necessary whenever we would like to perform arithmetic operations on dates, such as finding the mean date within a set. In this implementation, time steps are computed by calculating the days that have elapsed from 1 AD to the input date.

Importing the Class

DateConvertor is located in GeoJikuu's preprocessing.conversion_tools module:

from geojikuu.preprocessing.conversion_tools import DateConvertor

Creating a DateConvertor Object

Creating a DateConvertor object requires passing in a Python datetime input format and a Python datetime output format. For example, if we wanted to convert dates in the same format as "10/05/1995" and we wanted our inverse conversion outputs to be in the same format as "05/10/1995":

date_convertor = DateConvertor(date_format_in="%d/%m/%Y", date_format_out="%m/%d/%Y")

Converting Date to Days

Converting a date to days is as simple as passing a date to the object's date_to_days() function. Keep in mind that the provided date must match the input format defined when the object was created:
date_convertor.date_to_days(date="10/05/1995")
Output: 728422

Converting Days to Date

Converting days to date is just as simple, although this time the days_to_date() function is called. Here we see that the output is in the date format that was defined when the object was created:
date_convertor.days_to_date(days=728422)
Output: '05/10/1995'