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.
# Import datetime and timedelta
from datetime import datetime, timedelta
# Define a format_date function
def format_date(timestamp, datetime_format):
dt = datetime.fromtimestamp(timestamp)
return dt.strftime(datetime_format)
print(format_date(1514665153, "%d-%m-%Y"))
# Define a function to estimate landing time
def calculate_landing_time(rocket_launch_dt, travel_duration):
dur = timedelta(days=travel_duration)
landing_date = rocket_launch_dt + dur
return landing_date.strftime('%d-%m-%Y')
print(calculate_landing_time(datetime(2023, 2, 15), 20))
# Define a function to calculate the days until a package arrives
def days_until_delivery(expected_delivery_dt, current_dt):
time_diff = expected_delivery_dt - current_dt
return time_diff.days
days_until_delivery(datetime(2023, 2, 15), datetime(2023, 2, 5))