Pendulum
Here are all the snippets available using this library:
days_between_dates.py
import pendulum
def days_between_dates(date1: str, date2: str) -> int:
"""
Calculates the difference in days between two dates.
Args:
date1: first date in YYYY-MM-DD format
date2: second date in YYYY-MM-DD format
Returns:
The difference in days between the two dates.
"""
dt1 = pendulum.parse(date1)
dt2 = pendulum.parse(date2)
# Calculate the difference in days between the two dates
difference = dt2.diff(dt1)
return difference.in_days()
weeks_in_interval.py
import pendulum
def weeks_in_interval(start_date: str, end_date: str) -> list[pendulum.DateTime]:
"""
Generate a list of weeks within the interval between start_date and end_date
Args:
start_date: The start date of the interval.
end_date: The end date of the interval.
Returns:
A list of weeks within the interval.
"""
start_date = pendulum.parse(start_date)
end_date = pendulum.parse(end_date)
# Create an interval between the start and end dates
interval = pendulum.interval(start_date, end_date)
# Generate a list of weeks within the interval
weeks_list = [week for week in interval.range("weeks")]
return weeks_list