Skip to content

You recently quit your job to start a space logistics company that uses rockets to deliver critical cargo to colonies on demand. Since you're still in the startup phase, you're handling everything yourself, including writing the software to manage complex scheduling and timing across different space colonies.

Before developing a full rocket flight planning and logistics system, you want to create core functions using Python's datetime module to handle dates, times, and durations. These basic functions are essential for your rocket delivery service. In this project, you will make simple reusable functions for working with timestamps, calculating rocket landing times based on launch and travel duration, and figuring out days until a delivery deadline to keep those customers updated!

This project is data-less, but you can test your functions by calling them in the workspace and passing them the required variables.

# Start coding here. Use as many cells as you need.
from datetime import datetime, timedelta

#define a function to convert unix type datetime to datetime string using format
def format_date(timestamp,datetime_format):
    dts=datetime.fromtimestamp(timestamp)
    datetime_str=dts.strftime(datetime_format)
    return datetime_str

#call the format_date function to test
datetime_str=format_date(1514665153,"%d-%m-%Y")
print(f'date as string {datetime_str}')

#define a function to calculate landing date from rocket launch date and travel duration
def calculate_landing_time(rocket_launch_dt, travel_duration):
    landing_date = rocket_launch_dt + timedelta(days=travel_duration)
    landing_date_str=landing_date.strftime('%d-%m-%Y')
    return landing_date_str

#define another function to calculate travel_duration
def days_until_delivery(expected_delivery_dt,current_dt):
    days_until = (expected_delivery_dt - current_dt).days
    return days_until

#calculate travel duration by calling days_until_delivery function
current_datetime = datetime(2023, 2, 5)
delivery_datetime = datetime(2024, 2, 15)
travel_duration = days_until_delivery(delivery_datetime,current_datetime)
print(f'travel duration days {travel_duration}')

#calculate landing time from launch date and travel duration
rocket_launch_dt = datetime(2025, 4, 15)
landing_time = calculate_landing_time(rocket_launch_dt, travel_duration)
print(f'landing time {landing_time}')