| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2f43955 commit fe3daea
43 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -292,7 +292,7 @@ and 10`. | |||
| 292 | 292 | ||
| 293 | 293 | Always create timezone aware datetime objects. For libraries that use protobuf, | |
| 294 | 294 | omitting the timezone may lead to unexpected behavior when the datetime | |
| 295 | - is converted to a protobuf tiemstamp. | ||
| 295 | + is converted to a protobuf timestamp. | ||
| 296 | 296 | ||
| 297 | 297 | ```py | |
| 298 | 298 | import datetime | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -48,7 +48,7 @@ def index(): | |||
| 48 | 48 | entity = datastore.Entity(key=ds.key('visit')) | |
| 49 | 49 | entity.update({ | |
| 50 | 50 | 'user_ip': user_ip, | |
| 51 | - 'timestamp': datetime.datetime.utcnow() | ||
| 51 | + 'timestamp': datetime.datetime.now(tz=datetime.timezone.utc) | ||
| 52 | 52 | }) | |
| 53 | 53 | ||
| 54 | 54 | ds.put(entity) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,7 @@ def create_task(project, queue, location, payload=None, in_seconds=None): | |||
| 60 | 60 | ||
| 61 | 61 | if in_seconds is not None: | |
| 62 | 62 | # Convert "seconds from now" into an rfc3339 datetime string. | |
| 63 | - d = datetime.datetime.utcnow() + datetime.timedelta(seconds=in_seconds) | ||
| 63 | + d = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(seconds=in_seconds) | ||
| 64 | 64 | ||
| 65 | 65 | # Create Timestamp protobuf. | |
| 66 | 66 | timestamp = timestamp_pb2.Timestamp() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,7 +89,7 @@ def get(self): | |||
| 89 | 89 | if code: | |
| 90 | 90 | record = ndb.Key(UserConfirmationRecord, code).get() | |
| 91 | 91 | # 2-hour time limit on confirming. | |
| 92 | - if record and (datetime.datetime.now() - record.timestamp < | ||
| 92 | + if record and (datetime.datetime.now(tz=datetime.timezone.utc) - record.timestamp < | ||
| 93 | 93 | datetime.timedelta(hours=2)): | |
| 94 | 94 | record.confirmed = True | |
| 95 | 95 | record.put() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,7 +54,7 @@ def fetch_times(limit): | |||
| 54 | 54 | @app.route('/') | |
| 55 | 55 | def root(): | |
| 56 | 56 | # Store the current access time in Datastore. | |
| 57 | - store_time(datetime.datetime.now()) | ||
| 57 | + store_time(datetime.datetime.now(tz=datetime.timezone.utc)) | ||
| 58 | 58 | ||
| 59 | 59 | # Fetch the most recent 10 access times from Datastore. | |
| 60 | 60 | times = fetch_times(10) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,7 +75,7 @@ def root(): | |||
| 75 | 75 | # Record and fetch the recent times a logged-in user has accessed | |
| 76 | 76 | # the site. This is currently shared amongst all users, but will be | |
| 77 | 77 | # individualized in a following step. | |
| 78 | - store_time(datetime.datetime.now()) | ||
| 78 | + store_time(datetime.datetime.now(tz=datetime.timezone.utc)) | ||
| 79 | 79 | times = fetch_times(10) | |
| 80 | 80 | ||
| 81 | 81 | return render_template( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,7 +73,7 @@ def root(): | |||
| 73 | 73 | claims = google.oauth2.id_token.verify_firebase_token( | |
| 74 | 74 | id_token, firebase_request_adapter) | |
| 75 | 75 | ||
| 76 | - store_time(claims['email'], datetime.datetime.now()) | ||
| 76 | + store_time(claims['email'], datetime.datetime.now(tz=datetime.timezone.utc)) | ||
| 77 | 77 | times = fetch_times(claims['email'], 10) | |
| 78 | 78 | ||
| 79 | 79 | except ValueError as exc: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,7 +51,7 @@ def signer(): | |||
| 51 | 51 | ||
| 52 | 52 | @pytest.fixture | |
| 53 | 53 | def fake_token(signer): | |
| 54 | - now = calendar.timegm(datetime.datetime.utcnow().utctimetuple()) | ||
| 54 | + now = calendar.timegm(datetime.datetime.now(tz=datetime.timezone.utc).utctimetuple()) | ||
| 55 | 55 | payload = { | |
| 56 | 56 | 'aud': 'example.com', | |
| 57 | 57 | 'azp': '1234567890', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - # Copyright 2015, Google, Inc. | ||
| 1 | + # Copyright 2015 Google, LLC. | ||
| 2 | 2 | # Licensed under the Apache License, Version 2.0 (the "License"); | |
| 3 | 3 | # you may not use this file except in compliance with the License. | |
| 4 | 4 | # You may obtain a copy of the License at | |
@@ -43,7 +43,7 @@ def create_user(ds, username, profile): | |||
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | 45 | def create_post(ds, username, post_content): | |
| 46 | - now = datetime.datetime.utcnow() | ||
| 46 | + now = datetime.datetime.now(tz=datetime.timezone.utc) | ||
| 47 | 47 | key = path_to_key(ds, '{0}.user/{1}.post'.format(username, now)) | |
| 48 | 48 | entity = datastore.Entity(key) | |
| 49 | 49 | ||
@@ -57,7 +57,7 @@ def create_post(ds, username, post_content): | |||
| 57 | 57 | ||
| 58 | 58 | ||
| 59 | 59 | def repost(ds, username, original): | |
| 60 | - now = datetime.datetime.utcnow() | ||
| 60 | + now = datetime.datetime.now(tz=datetime.timezone.utc) | ||
| 61 | 61 | new_key = path_to_key(ds, '{0}.user/{1}.post'.format(username, now)) | |
| 62 | 62 | new = datastore.Entity(new_key) | |
| 63 | 63 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - # Copyright 2015, Google, Inc. | ||
| 1 | + # Copyright 2015 Google, LLC. | ||
| 2 | 2 | # Licensed under the Apache License, Version 2.0 (the "License"); | |
| 3 | 3 | # you may not use this file except in compliance with the License. | |
| 4 | 4 | # You may obtain a copy of the License at | |
@@ -37,7 +37,7 @@ def path_to_key(datastore, path): | |||
| 37 | 37 | ||
| 38 | 38 | def save_page(ds, page, content): | |
| 39 | 39 | with ds.transaction(): | |
| 40 | - now = datetime.datetime.utcnow() | ||
| 40 | + now = datetime.datetime.now(tz=datetime.timezone.utc) | ||
| 41 | 41 | current_key = path_to_key(ds, '{}.page/current.revision'.format(page)) | |
| 42 | 42 | revision_key = path_to_key(ds, '{}.page/{}.revision'.format(page, now)) | |
| 43 | 43 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments