Skip to content

Commit c59b3f4

Browse files
authored
1 parent 042ceaa commit c59b3f4

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

csirtg_indicator/indicator.py

+42-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def __init__(self, indicator=None, version=PROTOCOL_VERSION, **kwargs):
4343
continue
4444

4545
if k in FIELDS_TIME:
46-
kwargs[k] = parse_timestamp(kwargs[k]).datetime
4746
setattr(self, k, kwargs[k])
4847
continue
4948

@@ -96,6 +95,48 @@ def indicator(self):
9695
def confidence(self):
9796
return self._confidence
9897

98+
def _time_setter(self, v):
99+
if isinstance(v, datetime):
100+
return v
101+
else:
102+
return parse_timestamp(v).to('utc').datetime
103+
104+
@property
105+
def reporttime(self):
106+
return self._reporttime
107+
108+
@reporttime.getter
109+
def reporttime(self):
110+
return self._reporttime
111+
112+
@reporttime.setter
113+
def reporttime(self, v):
114+
self._reporttime = self._time_setter(v)
115+
116+
@property
117+
def lasttime(self):
118+
return self._lasttime
119+
120+
@lasttime.getter
121+
def lasttime(self):
122+
return self._lasttime
123+
124+
@lasttime.setter
125+
def lasttime(self, v):
126+
self._lasttime = self._time_setter(v)
127+
128+
@property
129+
def firsttime(self):
130+
return self._firsttime
131+
132+
@firsttime.getter
133+
def firsttime(self):
134+
return self._firsttime
135+
136+
@firsttime.setter
137+
def firsttime(self, v):
138+
self._firsttime = self._time_setter(v)
139+
99140
@confidence.setter
100141
def confidence(self, v):
101142
self._confidence = float(v)

test/test_timestamps.py

+11
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,14 @@ def test_indicator_timestamps():
2020
assert i['firsttime'] == f
2121
assert i['lasttime'] == l
2222
assert i['reporttime'] == r
23+
24+
25+
def test_indicator_timezones():
26+
t = '2017-03-06T11:41:48-06:00'
27+
a = arrow.get('2017-03-06T17:41:48Z').datetime
28+
29+
i = Indicator('example.com', firsttime=t, lasttime=t, reporttime=t)
30+
31+
assert i.firsttime == a
32+
assert i.lasttime == a
33+
assert i.reporttime == a

0 commit comments

Comments
 (0)