GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 088f5b...e3eaab )
by Jason
01:34
created

expand_datestring_without_day()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 13
rs 9.4285
1
import re
2
from datetime import timedelta
3
4
from shoop.utils.dates import parse_date
5
6
7
def expand_datestring_without_day(date):
8
    """Expand date string YYYY-MM with day.
9
10
    For example; 2016-02 will become 2016-02-01.
11
12
    Args:
13
        string - Date string that will be checked.
14
    Returns:
15
        string - Expanded date string with "-01" appended, or original given string.
16
    """
17
    if re.match("^[0-9]{4}-[0-9]{2}$", date):
18
        return "%s-01" % date
19
    return date
20
21
22
def get_start_and_end_from_request(request):
23
    """Get start and end dates from request.
24
25
    Returns:
26
        date, date or None, None
27
    """
28
    start = getattr(request, request.method).get("start", None)
29
    if start:
30
        start = expand_datestring_without_day(start)
31
    end = getattr(request, request.method).get("end", None)
32
    if end:
33
        end = expand_datestring_without_day(end)
34
    if "days" in getattr(request, request.method):
35
        days = getattr(request, request.method).get("days", None)
36
    else:
37
        days = getattr(request, request.method).get("quantity", None)
38
    if start and (end or days):
39
        start_date = parse_date(start)
40
        if end:
41
            end_date = parse_date(end)
42
        else:
43
            end_date = start_date + timedelta(days=int(days))
44
    else:
45
        return None, None
46
    return start_date, end_date
47
48
49
def get_persons_from_request(request):
50
    """Get person count from request.
51
52
    Returns:
53
        int
54
    """
55
    persons = int(getattr(request, request.method).get("persons", 1))
56
    return persons
57
58
59
def daterange(start_date, end_date):
60
    """Taken from http://stackoverflow.com/a/1060330/1489738."""
61
    for n in range(int ((end_date - start_date).days)):
62
        yield start_date + timedelta(n)
63