当前位置: 首页>>代码示例>>Python>>正文


Python aniso8601.parse_datetime方法代码示例

本文整理汇总了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 
开发者ID:gigantum,项目名称:gigantum-client,代码行数:26,代码来源:test_dataset_queries.py

示例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.') 
开发者ID:johnwheeler,项目名称:flask-ask,代码行数:19,代码来源:core.py

示例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)}") 
开发者ID:graphql-python,项目名称:graphene,代码行数:13,代码来源:datetime.py

示例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 
开发者ID:gigantum,项目名称:gigantum-client,代码行数:43,代码来源:test_dataset_queries.py

示例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"] 
开发者ID:gigantum,项目名称:gigantum-client,代码行数:36,代码来源:test_labbook_queries.py

示例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 
开发者ID:gigantum,项目名称:gigantum-client,代码行数:37,代码来源:test_labbook_queries.py

示例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 
开发者ID:gigantum,项目名称:gigantum-client,代码行数:36,代码来源:test_labbook_queries.py

示例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) 
开发者ID:HearthSim,项目名称:python-hslog,代码行数:29,代码来源:test_main.py

示例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) 
开发者ID:johnwheeler,项目名称:flask-ask,代码行数:7,代码来源:models.py


注:本文中的aniso8601.parse_datetime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。