Completed
Pull Request — master (#349)
by Tomaz
07:18 queued 04:45
created

GetWeekBoundariesTimestampsAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %
Metric Value
wmc 2
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 2
1
import time
2
import datetime
3
4
from st2common.util import isotime
5
from st2actions.runners.pythonrunner import Action
6
7
8
class GetWeekBoundariesTimestampsAction(Action):
9
    def run(self, date=None):
10
        if date:
11
            dt = isotime.parse(date)
12
        else:
13
            dt = datetime.datetime.utcnow()
14
15
        start_dt = (dt - datetime.timedelta(days=dt.weekday()))
16
        end_dt = (start_dt + datetime.timedelta(days=6))
17
        start_dt = start_dt.replace(hour=0, minute=0, second=0, microsecond=0)
18
        end_dt = end_dt.replace(hour=23, minute=59, second=59, microsecond=0)
19
20
        start_timestamp = int(time.mktime(start_dt.timetuple()))
21
        end_timestamp = int(time.mktime(end_dt.timetuple()))
22
23
        return start_timestamp, end_timestamp
24