Skip to content

Instantly share code, notes, and snippets.

@RussellLuo
Created May 24, 2018 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RussellLuo/5fd82374aae5e78d5e10a907b7880b08 to your computer and use it in GitHub Desktop.
Save RussellLuo/5fd82374aae5e78d5e10a907b7880b08 to your computer and use it in GitHub Desktop.
Returns a list of time tuples that represents a series of timespans between a time range.
# -*- coding: utf-8 -*-
def time_span_range(begin, end, span):
"""Returns a list of time tuples that represents a series of timespans between a time range.
:param begin: begin time
:param end: end time
:param span: span of each timespan
"""
s_end = begin
while True:
s_begin = s_end
s_end = s_begin + span
if s_end >= end:
break
yield s_begin, s_end
yield s_begin, end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment