Skip to content

Commit

Permalink
fix DateTime elements have seconds precision, optimized for fractions (
Browse files Browse the repository at this point in the history
  • Loading branch information
ReimarBauer authored Apr 15, 2024
1 parent ba18d01 commit e71d9f3
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 19 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 %z")
timestamp = datetime.datetime.strptime(timestamp, "%Y-%m-%d, %H:%M:%S.%f %z")
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 %z")
'created_at': change.created_at.strftime("%Y-%m-%d, %H:%M:%S.%f %z")
}, 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 +00:00"))
timestamp = request.args.get("timestamp", request.form.get("timestamp", "1970-01-01, 00:00:00.000000 +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 %z")
"time": message.created_at.strftime("%Y-%m-%d, %H:%M:%S.%f %z")
}


Expand Down
3 changes: 2 additions & 1 deletion mslib/msui/mscolab_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ def load_all_messages(self):
data = {
"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 %z")
"timestamp": datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
}
# 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 %z")
created_at = datetime.strptime(change["created_at"], "%Y-%m-%d, %H:%M:%S.%f %z")
local_time = utc_to_local_datetime(created_at)
date = local_time.strftime('%d/%m/%Y')
time = local_time.strftime('%I:%M %p')
Expand Down
5 changes: 0 additions & 5 deletions tests/_test_mscolab/test_files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
import time
import fs
import pytest

Expand Down Expand Up @@ -172,8 +171,6 @@ def test_get_all_changes(self):
with self.app.test_client():
flight_path, operation = self._create_operation(flight_path="V11")
assert self.fm.save_file(operation.id, "content1", self.user)
# we need to wait to get an updated created_at
time.sleep(1)
assert self.fm.save_file(operation.id, "content2", self.user)
all_changes = self.fm.get_all_changes(operation.id, self.user)
# the newest change is on index 0, because it has a recent created_at time
Expand All @@ -186,9 +183,7 @@ def test_get_change_content(self):
with self.app.test_client():
flight_path, operation = self._create_operation(flight_path="V12", content='initial')
assert self.fm.save_file(operation.id, "content1", self.user)
time.sleep(1)
assert self.fm.save_file(operation.id, "content2", self.user)
time.sleep(1)
assert self.fm.save_file(operation.id, "content3", self.user)
all_changes = self.fm.get_all_changes(operation.id, self.user)
previous_change = self.fm.get_change_content(all_changes[2]["id"], self.user)
Expand Down
4 changes: 0 additions & 4 deletions tests/_test_mscolab/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
import time
import pytest
import json
import io
Expand Down Expand Up @@ -234,7 +233,6 @@ def test_get_all_changes(self):
with self.app.test_client() as test_client:
operation, token = self._create_operation(test_client, self.userdata)
fm, user = self._save_content(operation, self.userdata)
time.sleep(1)
fm.save_file(operation.id, "content2", user)
# the newest change is on index 0, because it has a recent created_at time
response = test_client.get('/get_all_changes', data={"token": token,
Expand All @@ -252,8 +250,6 @@ def test_get_change_content(self):
with self.app.test_client() as test_client:
operation, token = self._create_operation(test_client, self.userdata)
fm, user = self._save_content(operation, self.userdata)
# we need to wait to get an updated created_at
time.sleep(1)
fm.save_file(operation.id, "content2", user)
all_changes = fm.get_all_changes(operation.id, user)
response = test_client.get('/get_change_content', data={"token": token,
Expand Down
11 changes: 7 additions & 4 deletions tests/_test_mscolab/test_sockets_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ def test_get_messages(self):
assert messages[0]["text"] == "message from 1"
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 %z")
timestamp = datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
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 %z")
timestamp = datetime.datetime.now(tz=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
messages = self.cm.get_messages(1, timestamp)
assert len(messages) == 0

Expand All @@ -221,7 +222,8 @@ 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 %z")
"timestamp": datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
}
# returns an array of messages
url = urljoin(self.url, 'messages')
Expand Down Expand Up @@ -257,7 +259,8 @@ 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 %z")
"timestamp": datetime.datetime(1970, 1, 1,
tzinfo=datetime.timezone.utc).strftime("%Y-%m-%d, %H:%M:%S.%f %z")
}
# returns an array of messages
url = urljoin(self.url, 'messages')
Expand Down

0 comments on commit e71d9f3

Please sign in to comment.