From 281e568edfc37ea7ee510ec59afcbd73ece3f031 Mon Sep 17 00:00:00 2001
From: Patrick Jentsch
Date: Wed, 8 Sep 2021 12:56:51 +0200
Subject: [PATCH] Use ISO 8601 as the default datetime format
---
app/events/sqlalchemy.py | 4 ++--
app/models.py | 12 ++++++------
.../js/nopaque/RessourceDisplays/CorpusDisplay.js | 8 ++++----
.../js/nopaque/RessourceDisplays/JobDisplay.js | 8 ++++----
4 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/app/events/sqlalchemy.py b/app/events/sqlalchemy.py
index 256b6453..27c8e233 100644
--- a/app/events/sqlalchemy.py
+++ b/app/events/sqlalchemy.py
@@ -96,9 +96,9 @@ def ressource_after_update_handler(mapper, connection, ressource):
if not history.has_changes():
continue
new_value = history.added[0]
- # DateTime attributes must be converted to a timestamp
+ # DateTime attributes must be converted to a string
if isinstance(new_value, datetime):
- new_value = new_value.timestamp()
+ new_value = new_value.isoformat()
jsonpatch.append(
{
'op': 'replace',
diff --git a/app/models.py b/app/models.py
index 2dc22a5e..ba1f7955 100644
--- a/app/models.py
+++ b/app/models.py
@@ -157,8 +157,8 @@ class User(UserMixin, db.Model):
'role_id': self.role_id,
'confirmed': self.confirmed,
'email': self.email,
- 'last_seen': self.last_seen.timestamp(),
- 'member_since': self.member_since.timestamp(),
+ 'last_seen': self.last_seen.isoformat(),
+ 'member_since': self.member_since.isoformat(),
'settings': {'dark_mode': self.setting_dark_mode,
'job_status_mail_notifications':
self.setting_job_status_mail_notifications,
@@ -433,9 +433,9 @@ class Job(db.Model):
'url': self.url,
'id': self.id,
'user_id': self.user_id,
- 'creation_date': self.creation_date.timestamp(),
+ 'creation_date': self.creation_date.isoformat(),
'description': self.description,
- 'end_date': self.end_date.timestamp() if self.end_date else None,
+ 'end_date': self.end_date.isoformat() if self.end_date else None,
'service': self.service,
'service_args': self.service_args,
'service_version': self.service_version,
@@ -557,11 +557,11 @@ class Corpus(db.Model):
'url': self.url,
'id': self.id,
'user_id': self.user_id,
- 'creation_date': self.creation_date.timestamp(),
+ 'creation_date': self.creation_date.isoformat(),
'current_nr_of_tokens': self.current_nr_of_tokens,
'description': self.description,
'status': self.status,
- 'last_edited_date': self.last_edited_date.timestamp(),
+ 'last_edited_date': self.last_edited_date.isoformat(),
'max_nr_of_tokens': self.max_nr_of_tokens,
'title': self.title,
}
diff --git a/app/static/js/nopaque/RessourceDisplays/CorpusDisplay.js b/app/static/js/nopaque/RessourceDisplays/CorpusDisplay.js
index 72fbd734..827fa02b 100644
--- a/app/static/js/nopaque/RessourceDisplays/CorpusDisplay.js
+++ b/app/static/js/nopaque/RessourceDisplays/CorpusDisplay.js
@@ -91,13 +91,13 @@ class CorpusDisplay extends RessourceDisplay {
}
}
- setCreationDate(creationDateTimestamp) {
- let creationDate = new Date(creationDateTimestamp * 1000).toLocaleString("en-US");
+ setCreationDate(iso8601CreationDate) {
+ let creationDate = new Date(iso8601CreationDate).toLocaleString("en-US");
for (let element of this.displayElement.querySelectorAll('.corpus-creation-date')) {this.setElement(element, creationDate);}
}
- setLastEditedDate(endDateTimestamp) {
- let endDate = new Date(endDateTimestamp * 1000).toLocaleString("en-US");
+ setLastEditedDate(iso8601LastEditedDate) {
+ let endDate = new Date(iso8601LastEditedDate).toLocaleString("en-US");
for (let element of this.displayElement.querySelectorAll('.corpus-end-date')) {this.setElement(element, endDate);}
}
}
diff --git a/app/static/js/nopaque/RessourceDisplays/JobDisplay.js b/app/static/js/nopaque/RessourceDisplays/JobDisplay.js
index a1dd3690..dfe42904 100644
--- a/app/static/js/nopaque/RessourceDisplays/JobDisplay.js
+++ b/app/static/js/nopaque/RessourceDisplays/JobDisplay.js
@@ -63,13 +63,13 @@ class JobDisplay extends RessourceDisplay {
}
}
- setCreationDate(creationDateTimestamp) {
- let creationDate = new Date(creationDateTimestamp * 1000).toLocaleString("en-US");
+ setCreationDate(iso8601CreationDate) {
+ let creationDate = new Date(iso8601CreationDate).toLocaleString("en-US");
for (let element of this.displayElement.querySelectorAll('.job-creation-date')) {this.setElement(element, creationDate);}
}
- setEndDate(endDateTimestamp) {
- let endDate = new Date(endDateTimestamp * 1000).toLocaleString("en-US");
+ setEndDate(iso8601EndDate) {
+ let endDate = new Date(iso8601EndDate).toLocaleString("en-US");
for (let element of this.displayElement.querySelectorAll('.job-end-date')) {this.setElement(element, endDate);}
}