tudat-team / tudat

A C++ platform to perform astrodynamics and space research.
BSD 3-Clause "New" or "Revised" License
17 stars 28 forks source link

Support for DateTime time interval arithmetic #186

Closed alopezrivera closed 10 months ago

alopezrivera commented 1 year ago

Rationale

Tudat DateTime objects are useful for date input in programs/applications using tudat or tudatpy.

For many applications, such as for example porkchop mission design plots, it is commonplace to use as inputs

It would be very convenient to facilitate this type of input with tudat DateTime objects.

Request

A syntax for time intervals in Tudat which can be added or subtracted from tudat DateTime objects.

Sketch:

from tudatpy.kernel.astro.time_conversion import DateTime, TimeSpan

earliest_departure_time = DateTime(2005,  4,  30)
latest_departure_time   = DateTime(2005, 10,   7)

earliest_arrival_time = earliest_departure_time + TimeSpan(2, 'months')
latest_arrival_time = earliest_departure_time + TimeSpan(6, 'months')
DominicDirkx commented 10 months ago

This functionality has been added, although in a slightly different form. Since months and years are never the same length, there are now two functions, one to add a number of seconds, and one to add a number of days (86400 seconds):

from tudatpy.kernel.astro.time_conversion import DateTime, TimeSpan

earliest_departure_time = DateTime(2005,  4,  30)
latest_departure_time   = DateTime(2005, 10,   7)

earliest_arrival_time = add_seconds_to_datetime( earliest_departure_time, 2.0 * 30.0 * 86400 )
latest_arrival_time = add_seconds_to_datetime( earliest_departure_time, 6.0 * 30.0 * 86400 )

earliest_arrival_time_alt = add_days_to_datetime( earliest_departure_time, 2.0 * 86400 )
latest_arrival_time_alt = add_days_to_datetime( earliest_departure_time, 6.0 * 86400 )