Created
December 14, 2023 11:13
-
-
Save Dminor7/eeda54719df840271f0626fcec6f4b84 to your computer and use it in GitHub Desktop.
This script defines a function generate_intervals that takes a start datetime, end datetime, and an interval in minutes. It yields tuples representing the start and end of each interval. The main part of the script sets the desired start and end datetime, and then it prints the intervals using a loop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pendulum | |
def generate_intervals(start_datetime, end_datetime, interval_minutes=30): | |
current_datetime = start_datetime | |
while current_datetime <= end_datetime: | |
yield current_datetime, current_datetime.add(minutes=interval_minutes) | |
current_datetime = current_datetime.add(minutes=interval_minutes) | |
# Set your desired start and end datetime | |
start_datetime = pendulum.datetime(2023, 12, 12, 0, 0, 0, tz="UTC") | |
end_datetime = pendulum.datetime(2023, 12, 12, 23, 30, 0, tz="UTC") | |
# Generate intervals | |
for interval_start, interval_end in generate_intervals(start_datetime, end_datetime): | |
print(f"({interval_start.to_iso8601_string()}, {interval_end.to_iso8601_string()})") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment