def get_date_boundaries(parameters): """Return the date boundaries in a set of parameters. Return a tuple with 2 datetime objects, the first one is the lower bound date and the second one is the upper bound date. """ default_date_range = datetime.timedelta(days=7) greater_than = None lower_than = None if not parameters.get("date"): lower_than = timezone.now() greater_than = lower_than - default_date_range else: for param in parameters["date"]: value = isodate.parse_datetime(split_on_operator(param)[1]) if "<" in param and (not lower_than or (lower_than and lower_than > value)): lower_than = value if ">" in param and (not greater_than or (greater_than and greater_than < value)): greater_than = value if not lower_than: # add a lower than that is now lower_than = timezone.now() if not greater_than: # add a greater than that is lower_than minus the date range greater_than = lower_than - default_date_range return (greater_than, lower_than)
def get_date_boundaries(params): """Return the date boundaries in a set of parameters. Return a tuple with 2 datetime objects, the first one is the lower bound date and the second one is the upper bound date. """ default_date_range = datetime.timedelta(days=DEFAULT_RANGE_DAYS) start_date = None end_date = None if not params.get('date'): end_date = timezone.now() start_date = end_date - default_date_range else: for param in params['date']: d = isodate.parse_datetime( split_on_operator(param)[1]).replace(tzinfo=timezone.utc) if param.startswith('<') and (not end_date or end_date < d): end_date = d if param.startswith('>') and (not start_date or start_date > d): start_date = d if not end_date: end_date = timezone.now() if not start_date: start_date = end_date - default_date_range return (start_date, end_date)
def get_date_boundaries(parameters): """Return the date boundaries in a set of parameters. Return a tuple with 2 datetime objects, the first one is the lower bound date and the second one is the upper bound date. """ default_date_range = datetime.timedelta(days=7) greater_than = None lower_than = None if not parameters.get('date'): lower_than = timezone.now() greater_than = lower_than - default_date_range else: for param in parameters['date']: value = isodate.parse_datetime(split_on_operator(param)[1]) if ('<' in param and (not lower_than or (lower_than and lower_than > value))): lower_than = value if ('>' in param and (not greater_than or (greater_than and greater_than < value))): greater_than = value if not lower_than: # add a lower than that is now lower_than = timezone.now() if not greater_than: # add a greater than that is lower_than minus the date range greater_than = lower_than - default_date_range return (greater_than, lower_than)
def get_date_boundaries(params): """Return the date boundaries in a set of parameters. Return a tuple with 2 datetime objects, the first one is the lower bound date and the second one is the upper bound date. """ default_date_range = datetime.timedelta(days=DEFAULT_RANGE_DAYS) start_date = None end_date = None if not params.get('date'): end_date = timezone.now() start_date = end_date - default_date_range else: for param in params['date']: d = isodate.parse_datetime( split_on_operator(param)[1] ).replace(tzinfo=timezone.utc) if param.startswith('<') and (not end_date or end_date < d): end_date = d if param.startswith('>') and (not start_date or start_date > d): start_date = d if not end_date: end_date = timezone.now() if not start_date: start_date = end_date - default_date_range return (start_date, end_date)