Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_no_timezone_different_default():
tz = iso8601.FixedOffset(2, 0, "test offset")
d = iso8601.parse_date("2007-01-01T08:00:00", default_timezone=tz)
assert d == datetime.datetime(2007, 1, 1, 8, 0, 0, 0, tz)
assert d.tzinfo == tz
def test_parse_invalid_date(invalid_date, error_string):
assert isinstance(invalid_date, str) or invalid_date is None # Why? 'cos I've screwed up the parametrize before :)
with pytest.raises(iso8601.ParseError) as exc:
iso8601.parse_date(invalid_date)
assert exc.errisinstance(iso8601.ParseError)
assert str(exc.value).startswith(error_string)
def test_parse_invalid_date(invalid_date, error_string):
assert isinstance(invalid_date, str) or invalid_date is None # Why? 'cos I've screwed up the parametrize before :)
with pytest.raises(iso8601.ParseError) as exc:
iso8601.parse_date(invalid_date)
assert exc.errisinstance(iso8601.ParseError)
assert str(exc.value).startswith(error_string)
def test_parse_no_timezone_different_default():
tz = iso8601.FixedOffset(2, 0, "test offset")
d = iso8601.parse_date("2007-01-01T08:00:00", default_timezone=tz)
assert d == datetime.datetime(2007, 1, 1, 8, 0, 0, 0, tz)
assert d.tzinfo == tz
def convertToISO8601UTC (dateTimeArg):
"""This method assumes that the datetime is local naive time."""
arg = dateTimeArg
if isinstance(arg, (types.StringTypes, unicode)) == True:
try:
arg = iso8601.parse_date(arg)
except:
pass
if isinstance(arg, datetime) == True and arg.tzinfo is not None:
dateUTC = arg - arg.utcoffset()
dateUTC_noTZ = datetime(dateUTC.year, dateUTC.month, dateUTC.day, dateUTC.hour, dateUTC.minute, dateUTC.second, dateUTC.microsecond)
return dateUTC_noTZ
return dateTimeArg
def _clean_date(date: str):
try:
return str(iso8601.parse_date(date).date())
except iso8601.ParseError:
return None
values = self.request.content.get_values(True)
self.logger.debug("_check_create_representation: %s", values)
# TODO: move this to expiration time handler plugin
# but needs to be set to a value even if plugin is disabled
if issubclass(self.resource_type, ExpiringResource):
expiration_time = values.get("expirationTime")
if not expiration_time:
expiration_time = self.now + self.global_config[
"default_lifetime"]
self.fields.append("expirationTime")
else:
if not isinstance(expiration_time, datetime):
try:
expiration_time = parse_date(expiration_time)
except ParseError as e:
raise CSEValueError(
"Illegal value for expirationTime: %s" % (e,))
if expiration_time < self.now + self.global_config["min_lifetime"]:
self.logger.warn("expirationTime is too low. Adjusting")
expiration_time = self.now + self.global_config["min_lifetime"]
self.fields.append("expirationTime")
elif expiration_time > self.now + self.global_config["max_lifetime"]:
self.logger.warn("expirationTime is too high. Adjusting")
expiration_time = self.now + self.global_config["max_lifetime"]
self.fields.append("expirationTime")
values["expirationTime"] = expiration_time
rt_attributes = rt.attributes
ignore_extra = True # todo(rst): check this later with flexContainer
if source not in sources:
sources[source] = {
constants.SOURCES_DATASET_SOURCE: source,
constants.SOURCE_SERIES_AMT: 0,
constants.SOURCE_VALUES_AMT: 0,
constants.SOURCE_FIRST_INDEX: None,
constants.SOURCE_LAST_INDEX: None,
}
sources[source][constants.SOURCE_SERIES_AMT] += 1
index_start = self.fields[field]['metadata'].get(meta_keys.INDEX_START)
# ☢☢☢
if index_start:
index_start = iso8601.parse_date(index_start).date()
first_index = sources[source][constants.SOURCE_FIRST_INDEX]
if first_index is None or first_index > index_start:
sources[source][constants.SOURCE_FIRST_INDEX] = index_start
index_end = self.fields[field]['metadata'].get(meta_keys.INDEX_END)
if index_end:
index_end = iso8601.parse_date(index_end).date()
last_index = sources[source][constants.SOURCE_LAST_INDEX]
if last_index is None or last_index < index_end:
sources[source][constants.SOURCE_LAST_INDEX] = index_end
index_size = self.fields[field]['metadata'].get(meta_keys.INDEX_SIZE) or 0
if index_size:
index_size = int(index_size)
def _make_date_index_continuous(self, target_date, time_delta):
"""Hace el índice de tiempo de los resultados continuo (según
el intervalo de resultados), sin saltos, hasta la fecha
especificada
"""
# Si no hay datos cargados no hay nada que hacer
if not len(self.data):
return
# Caso fecha target > última fecha (rellenar al final)
target_date = iso8601.parse_date(target_date)
last_date = iso8601.parse_date(self.data[-1][0])
delta = time_delta
row_len = len(self.data[0])
while last_date < target_date:
last_date = last_date + delta
date_str = self._format_timestamp(str(last_date.date()))
row = [date_str]
row.extend([None for _ in range(1, row_len)])
self.data.append(row)
# Caso fecha target < primera fecha (rellenar al principio)
first_date = iso8601.parse_date(self.data[0][0])
lead_rows = []
current_date = target_date
while current_date < first_date:
date_str = self._format_timestamp(str(current_date.date()))