當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。