本文整理汇总了Python中aniso8601.parse_datetime方法的典型用法代码示例。如果您正苦于以下问题:Python aniso8601.parse_datetime方法的具体用法?Python aniso8601.parse_datetime怎么用?Python aniso8601.parse_datetime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aniso8601
的用法示例。
在下文中一共展示了aniso8601.parse_datetime方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_dataset_create_date
# 需要导入模块: import aniso8601 [as 别名]
# 或者: from aniso8601 import parse_datetime [as 别名]
def test_get_dataset_create_date(self, fixture_working_dir_dataset_populated_scoped):
"""Test getting a dataset's create date"""
im = InventoryManager(fixture_working_dir_dataset_populated_scoped[0])
ds = im.create_dataset("default", "default", "create-on-test-ds", "gigantum_object_v1",
description="my first dataset",
author=GitAuthor(name="default", email="test@test.com"))
query = """
{
dataset(name: "create-on-test-ds", owner: "default") {
createdOnUtc
}
}
"""
r = fixture_working_dir_dataset_populated_scoped[2].execute(query)
assert 'errors' not in r
d = r['data']['dataset']['createdOnUtc']
# using aniso8601 to parse because built-in datetime doesn't parse the UTC offset properly (configured for js)
create_on = aniso8601.parse_datetime(d)
assert create_on.microsecond == 0
assert create_on.tzname() == "+00:00"
assert (datetime.datetime.now(datetime.timezone.utc) - create_on).total_seconds() < 5
示例2: _parse_timestamp
# 需要导入模块: import aniso8601 [as 别名]
# 或者: from aniso8601 import parse_datetime [as 别名]
def _parse_timestamp(timestamp):
"""
Parse a given timestamp value, raising ValueError if None or Flasey
"""
if timestamp:
try:
return aniso8601.parse_datetime(timestamp)
except AttributeError:
# raised by aniso8601 if raw_timestamp is not valid string
# in ISO8601 format
try:
return datetime.utcfromtimestamp(timestamp)
except:
# relax the timestamp a bit in case it was sent in millis
return datetime.utcfromtimestamp(timestamp/1000)
raise ValueError('Invalid timestamp value! Cannot parse from either ISO8601 string or UTC timestamp.')
示例3: parse_value
# 需要导入模块: import aniso8601 [as 别名]
# 或者: from aniso8601 import parse_datetime [as 别名]
def parse_value(value):
if isinstance(value, datetime.datetime):
return value
if not isinstance(value, str):
raise GraphQLError(
f"DateTime cannot represent non-string value: {repr(value)}"
)
try:
return parse_datetime(value)
except ValueError:
raise GraphQLError(f"DateTime cannot represent value: {repr(value)}")
示例4: test_get_dataset_modified_on
# 需要导入模块: import aniso8601 [as 别名]
# 或者: from aniso8601 import parse_datetime [as 别名]
def test_get_dataset_modified_on(self, fixture_working_dir_dataset_populated_scoped):
"""Test getting a dataset's modified date"""
im = InventoryManager(fixture_working_dir_dataset_populated_scoped[0])
ds = im.create_dataset("default", "default", "modified-on-test-ds", "gigantum_object_v1",
description="my first dataset",
author=GitAuthor(name="default", email="test@test.com"))
modified_query = """
{
dataset(name: "modified-on-test-ds", owner: "default") {
modifiedOnUtc
}
}
"""
r = fixture_working_dir_dataset_populated_scoped[2].execute(modified_query)
assert 'errors' not in r
d = r['data']['dataset']['modifiedOnUtc']
# using aniso8601 to parse because built-in datetime doesn't parse the UTC offset properly (configured for js)
modified_on_1 = aniso8601.parse_datetime(d)
assert modified_on_1.microsecond == 0
assert modified_on_1.tzname() == "+00:00"
time.sleep(3)
with open(os.path.join(ds.root_dir, '.gigantum', 'dummy.txt'), 'wt') as testfile:
testfile.write("asdfasdf")
ds.git.add_all()
ds.git.commit("testing")
DatasetCacheController().clear_all()
r = fixture_working_dir_dataset_populated_scoped[2].execute(modified_query)
assert 'errors' not in r
d = r['data']['dataset']['modifiedOnUtc']
modified_on_2 = aniso8601.parse_datetime(d)
assert modified_on_2.microsecond == 0
assert modified_on_2.tzname() == "+00:00"
assert (datetime.datetime.now(datetime.timezone.utc) - modified_on_1).total_seconds() < 10
assert (datetime.datetime.now(datetime.timezone.utc) - modified_on_2).total_seconds() < 10
assert modified_on_2 > modified_on_1
示例5: test_get_labbook
# 需要导入模块: import aniso8601 [as 别名]
# 或者: from aniso8601 import parse_datetime [as 别名]
def test_get_labbook(self, fixture_working_dir):
"""Test listing labbooks"""
flush_redis_repo_cache()
im = InventoryManager(fixture_working_dir[0])
lb = im.create_labbook('default', 'default', 'labbook1', description="my test description",
author=GitAuthor(name="tester", email="tester@test.com"))
# Get LabBooks for a single user - Don't get the ID field since it is a UUID
query = """
{
labbook(name: "labbook1", owner: "default") {
isDeprecated
schemaVersion
name
sizeBytes
description
creationDateUtc
activeBranchName
}
}
"""
r = fixture_working_dir[2].execute(query)
assert 'errors' not in r
assert r['data']['labbook']['schemaVersion'] == 2
assert r['data']['labbook']['isDeprecated'] == False
assert int(r['data']['labbook']['sizeBytes']) > 10000
assert int(r['data']['labbook']['sizeBytes']) < 40000
assert r['data']['labbook']['activeBranchName'] == 'master'
assert r['data']['labbook']['name'] == 'labbook1'
d = r['data']['labbook']['creationDateUtc']
n = aniso8601.parse_datetime(d)
assert (datetime.datetime.now(tz=datetime.timezone.utc) - n).total_seconds() < 5
assert n.microsecond == 0
assert n.tzname() in ["+00:00"]
示例6: test_get_labbook_create_date
# 需要导入模块: import aniso8601 [as 别名]
# 或者: from aniso8601 import parse_datetime [as 别名]
def test_get_labbook_create_date(self, fixture_working_dir, snapshot):
"""Test getting a labbook's create date"""
# Create labbooks
im = InventoryManager(fixture_working_dir[0])
lb = im.create_labbook('default', 'default', 'labbook1', description="my test description")
query = """
{
labbook(name: "labbook1", owner: "default") {
creationDateUtc
}
}
"""
r = fixture_working_dir[2].execute(query)
assert 'errors' not in r
d = r['data']['labbook']['creationDateUtc']
# using aniso8601 to parse because built-in datetime doesn't parse the UTC offset properly (configured for js)
create_on = aniso8601.parse_datetime(d)
assert create_on.microsecond == 0
assert create_on.tzname() in ["+00:00"]
# wait, add another commit, and remove the buildinfo file to test the fallback method for getting create date
time.sleep(4)
lb.write_readme("##Summary\nThis is my readme!!")
r = fixture_working_dir[2].execute(query)
assert 'errors' not in r
d = r['data']['labbook']['creationDateUtc']
create_on_fallback = aniso8601.parse_datetime(d)
assert create_on_fallback.microsecond == 0
assert create_on_fallback.tzname() in ["+00:00"]
# Because there can be 1 second of drift between normal and fallback methods, be safe and check they are not 2
# seconds apart.
assert abs((create_on - create_on_fallback).seconds) < 2
示例7: test_get_labbook_modified_on
# 需要导入模块: import aniso8601 [as 别名]
# 或者: from aniso8601 import parse_datetime [as 别名]
def test_get_labbook_modified_on(self, fixture_working_dir, snapshot):
"""Test getting a labbook's modifed date"""
# Create labbooks
im = InventoryManager(fixture_working_dir[0])
lb = im.create_labbook('default', 'default', 'labbook1', description="my test description")
modified_query = """
{
labbook(name: "labbook1", owner: "default") {
modifiedOnUtc
}
}
"""
r = fixture_working_dir[2].execute(modified_query)
assert 'errors' not in r
d = r['data']['labbook']['modifiedOnUtc']
# using aniso8601 to parse because built-in datetime doesn't parse the UTC offset properly (configured for js)
modified_on_1 = aniso8601.parse_datetime(d)
assert modified_on_1.microsecond == 0
assert modified_on_1.tzname() in ["+00:00"]
time.sleep(2)
lb.write_readme("##Summary\nThis is my readme!!")
flush_redis_repo_cache()
r = fixture_working_dir[2].execute(modified_query)
assert 'errors' not in r
d = r['data']['labbook']['modifiedOnUtc']
modified_on_2 = aniso8601.parse_datetime(d)
# On a local machine, this might take only 3 seconds! But on CI it can go very slow for unknown reasons
assert (datetime.datetime.now(tz=datetime.timezone.utc) - modified_on_1).total_seconds() < 40
assert (datetime.datetime.now(tz=datetime.timezone.utc) - modified_on_2).total_seconds() < 40
assert modified_on_2 > modified_on_1
示例8: test_timestamp_parsing
# 需要导入模块: import aniso8601 [as 别名]
# 或者: from aniso8601 import parse_datetime [as 别名]
def test_timestamp_parsing():
parser = LogParser()
parser.read(StringIO(data.INITIAL_GAME))
parser.flush()
assert parser.games[0].packets[0].ts == time(2, 59, 14, 608862)
# Test with an initial datetime
parser2 = LogParser()
parser2._current_date = datetime(2015, 1, 1)
parser2.read(StringIO(data.INITIAL_GAME))
parser2.flush()
assert parser2.games[0].packets[0].ts == datetime(2015, 1, 1, 2, 59, 14, 608862)
# Same test, with timezone
parser2 = LogParser()
parser2._current_date = parse_datetime("2015-01-01T02:58:00+0200")
parser2.read(StringIO(data.INITIAL_GAME))
parser2.flush()
ts = parser2.games[0].packets[0].ts
assert ts.year == 2015
assert ts.hour == 2
assert ts.second == 14
assert ts.tzinfo
assert ts.utcoffset() == timedelta(hours=2)
示例9: __getattr__
# 需要导入模块: import aniso8601 [as 别名]
# 或者: from aniso8601 import parse_datetime [as 别名]
def __getattr__(self, attr):
# converts timestamp str to datetime.datetime object
if 'timestamp' in attr:
return aniso8601.parse_datetime(self.get(attr))
return self.get(attr)