Skip to content

Commit

Permalink
Add time module with basic functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
devin-ai-integration[bot] committed Aug 31, 2024
1 parent 0a7b921 commit 8515c71
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions modules/time/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import datetime

def get_current_time():
"""
Returns the current time as a datetime object.
"""
return datetime.datetime.now()

def format_time(time=None, format_string="%Y-%m-%d %H:%M:%S"):
"""
Formats a given time or the current time if none is provided.
Args:
time (datetime, optional): The time to format. Defaults to current time.
format_string (str, optional): The format string. Defaults to "%Y-%m-%d %H:%M:%S".
Returns:
str: The formatted time string.
"""
if time is None:
time = get_current_time()
return time.strftime(format_string)

def time_difference(time1, time2):
"""
Calculates the difference between two times.
Args:
time1 (datetime): The first time.
time2 (datetime): The second time.
Returns:
timedelta: The time difference.
"""
return abs(time2 - time1)

0 comments on commit 8515c71

Please sign in to comment.