Skip to content

Commit

Permalink
Use isoformat for mscolab timestamps (#2345)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReimarBauer authored May 14, 2024
1 parent b0032d2 commit 48a15f5
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mslib/mscolab/chat_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_messages(self, op_id, timestamp=None):
if timestamp is None:
timestamp = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)
else:
timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d, %H:%M:%S.%f %z")
timestamp = datetime.datetime.fromisoformat(timestamp)
messages = Message.query \
.filter(Message.op_id == op_id) \
.filter(Message.reply_id.is_(None)) \
Expand Down
2 changes: 1 addition & 1 deletion mslib/mscolab/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def get_all_changes(self, op_id, user, named_version=False):
'comment': change.comment,
'version_name': change.version_name,
'username': change.user.username,
'created_at': change.created_at.strftime("%Y-%m-%d, %H:%M:%S.%f %z")
'created_at': change.created_at.isoformat()
}, changes))

def get_change_content(self, ch_id, user):
Expand Down
2 changes: 1 addition & 1 deletion mslib/mscolab/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def messages():
user = g.user
op_id = request.args.get("op_id", request.form.get("op_id", None))
if fm.is_member(user.id, op_id):
timestamp = request.args.get("timestamp", request.form.get("timestamp", "1970-01-01, 00:00:00.000000 +00:00"))
timestamp = request.args.get("timestamp", request.form.get("timestamp", "1970-01-01T00:00:00+00:00"))
chat_messages = cm.get_messages(op_id, timestamp)
return jsonify({"messages": chat_messages})
return "False"
Expand Down
2 changes: 1 addition & 1 deletion mslib/mscolab/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_message_dict(message):
"message_type": message.message_type,
"reply_id": message.reply_id,
"replies": [],
"time": message.created_at.strftime("%Y-%m-%d, %H:%M:%S.%f %z")
"time": message.created_at.isoformat()
}


Expand Down
2 changes: 1 addition & 1 deletion mslib/msui/mscolab_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def load_all_messages(self):
"token": self.token,
"op_id": self.op_id,
"timestamp": datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
tzinfo=datetime.timezone.utc).isoformat()
}
# returns an array of messages
url = urljoin(self.mscolab_server_url, "messages")
Expand Down
2 changes: 1 addition & 1 deletion mslib/msui/mscolab_version_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def load_all_changes(self):
changes = json.loads(r.text)["changes"]
self.changes.clear()
for change in changes:
created_at = datetime.strptime(change["created_at"], "%Y-%m-%d, %H:%M:%S.%f %z")
created_at = datetime.fromisoformat(change["created_at"])
local_time = utc_to_local_datetime(created_at)
date = local_time.strftime('%d/%m/%Y')
time = local_time.strftime('%I:%M %p')
Expand Down
10 changes: 4 additions & 6 deletions tests/_test_mscolab/test_sockets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ def test_get_messages(self):
assert len(messages) == 2
assert messages[0]["u_id"] == self.user.id
timestamp = datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
tzinfo=datetime.timezone.utc).isoformat()
messages = self.cm.get_messages(1, timestamp)
assert len(messages) == 2
assert messages[0]["u_id"] == self.user.id
timestamp = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
timestamp = datetime.datetime.now(tz=datetime.timezone.utc).isoformat()
messages = self.cm.get_messages(1, timestamp)
assert len(messages) == 0

Expand All @@ -222,8 +222,7 @@ def test_get_messages_api(self):
data = {
"token": token,
"op_id": self.operation.id,
"timestamp": datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
"timestamp": datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc).isoformat()
}
# returns an array of messages
url = urljoin(self.url, 'messages')
Expand Down Expand Up @@ -259,8 +258,7 @@ def test_edit_message(self):
data = {
"token": token,
"op_id": self.operation.id,
"timestamp": datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
"timestamp": datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc).isoformat()
}
# returns an array of messages
url = urljoin(self.url, 'messages')
Expand Down
7 changes: 5 additions & 2 deletions tests/_test_mscolab/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
from mslib.mscolab.conf import mscolab_settings
from mslib.mscolab.models import Operation, MessageType
from mslib.mscolab.seed import add_user, get_user
from mslib.mscolab.utils import get_recent_op_id, get_session_id, get_message_dict, create_files, os_fs_create_dir
from mslib.mscolab.utils import (get_recent_op_id, get_session_id,
get_message_dict, create_files,
os_fs_create_dir)


class Message:
Expand All @@ -46,7 +48,8 @@ class user:
replies = []

class created_at:
def strftime(value):
@staticmethod
def isoformat():
pass


Expand Down

0 comments on commit 48a15f5

Please sign in to comment.