Skip to content

Commit

Permalink
Fix timezone handling in history endpoint and tests (#1647)
Browse files Browse the repository at this point in the history
* Fix timezone handling in history endpoint and tests

* changelog

* lint

* Update times in test responses

---------

Co-authored-by: Jens W. Klein <jk@kleinundpartner.at>
  • Loading branch information
davisagli and jensens committed Jul 14, 2023
1 parent 8249653 commit 24f25d7
Show file tree
Hide file tree
Showing 40 changed files with 90 additions and 88 deletions.
1 change: 1 addition & 0 deletions news/1647.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix timezone of dates for revisions in the `@history` service. @davisagli
11 changes: 4 additions & 7 deletions src/plone/restapi/services/history/get.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime as dt
from datetime import timezone
from plone.app.layout.viewlets.content import ContentHistoryViewlet
from plone.restapi.bbb import safe_text
from plone.restapi.interfaces import ISerializeToJson
Expand Down Expand Up @@ -71,13 +72,9 @@ def reply(self):
# Versioning entries use a timestamp,
# workflow ISO formatted string
if not isinstance(item["time"], str):
# Note that isoformat does not add the Z at the end of the string, The lack of the
# timezone specifier causes Intl (and derivative libraries) in the browser not to
# use local time, which is considered a bug in applications. Therefore we add the Z
# to the end to make sure that the date will be interpreted properly by the client.
item["time"] = dt.fromtimestamp(int(item["time"])).strftime(
"%Y-%m-%dT%H:%M:%SZ"
)
item["time"] = dt.fromtimestamp(
int(item["time"]), tz=timezone.utc
).isoformat(timespec="seconds")

# The create event has an empty 'action', but we like it to say
# 'Create', alike the transition_title
Expand Down
5 changes: 4 additions & 1 deletion src/plone/restapi/services/locking/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Locking
"""
from datetime import datetime
from datetime import timezone
from plone import api
from plone.locking.interfaces import ILockable

Expand All @@ -20,7 +21,9 @@ def creation_date(timestamp):
# timezone specifier causes Intl (and derivative libraries) in the browser not to
# use local time, which is considered a bug in applications. Therefore we add the Z
# to the end to make sure that the date will be interpreted properly by the client.
return datetime.utcfromtimestamp(timestamp).strftime("%Y-%m-%dT%H:%M:%SZ")
return datetime.fromtimestamp(timestamp, tz=timezone.utc).isoformat(
timespec="seconds"
)


def lock_info(obj):
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/collection.resp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Content-Type: application/json
"UID": "SomeUUID000000000000000000000002",
"allow_discussion": false,
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand Down Expand Up @@ -96,7 +96,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {
"@id": "http://localhost:55001/plone/doc1",
"@type": "Document",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Content-Type: application/json
"UID": "SomeUUID000000000000000000000002",
"allow_discussion": false,
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand Down Expand Up @@ -96,7 +96,7 @@ Content-Type: application/json
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand All @@ -112,7 +112,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {
"@id": "http://localhost:55001/plone/collection",
"@type": "Collection",
Expand Down Expand Up @@ -178,7 +178,7 @@ Content-Type: application/json
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand All @@ -194,7 +194,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {
"@id": "http://localhost:55001/plone/doc2",
"@type": "Document",
Expand Down Expand Up @@ -262,7 +262,7 @@ Content-Type: application/json
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand All @@ -278,7 +278,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down Expand Up @@ -316,7 +316,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {
"@id": "http://localhost:55001/plone/doc1",
"@type": "Document",
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/content_get.resp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Content-Type: application/json
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"admin"
],
Expand All @@ -50,7 +50,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone/folder",
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/content_get_folder.resp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Content-Type: application/json
"UID": "SomeUUID000000000000000000000002",
"allow_discussion": false,
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand Down Expand Up @@ -79,7 +79,7 @@ Content-Type: application/json
"language": "",
"layout": "listing_view",
"lock": {},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"nextPreviousEnabled": false,
"next_item": {},
"parent": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Content-Type: application/json
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"admin"
],
Expand All @@ -50,7 +50,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone/folder",
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/content_post.resp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Location: http://localhost:55001/plone/folder/my-document
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"admin"
],
Expand All @@ -51,7 +51,7 @@ Location: http://localhost:55001/plone/folder/my-document
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone/folder",
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/document.resp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Content-Type: application/json
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand All @@ -50,7 +50,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/event.resp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Content-Type: application/json
"contact_name": null,
"contact_phone": null,
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand All @@ -57,7 +57,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"open_end": false,
"parent": {
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/expansion.resp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Content-Type: application/json
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand All @@ -50,7 +50,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/expansion_expanded.resp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Content-Type: application/json
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand All @@ -57,7 +57,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Content-Type: application/json
"actor": "test_user_1_",
"comments": "",
"review_state": "private",
"time": "1995-07-31T17:30:00",
"time": "1995-07-31T17:30:00+00:00",
"title": "Private"
}
],
Expand All @@ -261,7 +261,7 @@ Content-Type: application/json
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand All @@ -277,7 +277,7 @@ Content-Type: application/json
"locked": false,
"stealable": true
},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/file.resp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Content-Type: application/json
"UID": "SomeUUID000000000000000000000002",
"allow_discussion": false,
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand All @@ -52,7 +52,7 @@ Content-Type: application/json
"language": "",
"layout": "file_view",
"lock": {},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/folder.resp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Content-Type: application/json
"UID": "SomeUUID000000000000000000000002",
"allow_discussion": false,
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand Down Expand Up @@ -65,7 +65,7 @@ Content-Type: application/json
"language": "",
"layout": "listing_view",
"lock": {},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"nextPreviousEnabled": false,
"next_item": {},
"parent": {
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/history_get.resp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Content-Type: application/json
},
"comments": "Initial version",
"may_revert": true,
"time": "1995-07-31T17:30:00Z",
"time": "1995-07-31T17:30:00+00:00",
"transition_title": "Edited",
"type": "versioning",
"version": 0
Expand All @@ -29,7 +29,7 @@ Content-Type: application/json
"comments": "",
"review_state": "private",
"state_title": "Private",
"time": "1995-07-31T18:30:00Z",
"time": "1995-07-31T18:30:00+00:00",
"transition_title": "Create",
"type": "workflow"
}
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/image.resp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Content-Type: application/json
"UID": "SomeUUID000000000000000000000002",
"allow_discussion": false,
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand Down Expand Up @@ -111,7 +111,7 @@ Content-Type: application/json
"language": "",
"layout": "image_view",
"lock": {},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down
4 changes: 2 additions & 2 deletions src/plone/restapi/tests/http-examples/link.resp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Content-Type: application/json
"allow_discussion": false,
"changeNote": "",
"contributors": [],
"created": "1995-07-31T13:45:00",
"created": "1995-07-31T13:45:00+00:00",
"creators": [
"test_user_1_"
],
Expand All @@ -47,7 +47,7 @@ Content-Type: application/json
"language": "",
"layout": "link_redirect_view",
"lock": {},
"modified": "1995-07-31T17:30:00",
"modified": "1995-07-31T17:30:00+00:00",
"next_item": {},
"parent": {
"@id": "http://localhost:55001/plone",
Expand Down

0 comments on commit 24f25d7

Please sign in to comment.