[System][Plugin] Allow military timezone names for datetime

This commit is contained in:
Ferdinand Thiessen 2020-11-02 13:32:44 +01:00
parent 56a0a8e06a
commit 22499b7ece
7 changed files with 18 additions and 7 deletions

View File

@ -1,4 +1,4 @@
from flaschengeist.hook import Hook
from flaschengeist.utils.hook import Hook
from flaschengeist.models.user import User, Role

View File

@ -1,7 +1,7 @@
from flask import current_app
from werkzeug.exceptions import NotFound, BadRequest
from flaschengeist.hook import Hook
from flaschengeist.utils.hook import Hook
from flaschengeist.models.user import User, Role
from flaschengeist.database import db
from flaschengeist import logger

View File

@ -1,7 +1,7 @@
import pkg_resources
from werkzeug.exceptions import MethodNotAllowed
from flaschengeist.hook import HookCall
from flaschengeist.utils.hook import HookCall
send_message_hook = HookCall("send_message")
"""Hook decorator for sending messages, register to send the message

View File

@ -7,17 +7,16 @@ from http.client import NO_CONTENT
from datetime import datetime, timezone
from flask import Blueprint, jsonify, request
from werkzeug.exceptions import Forbidden, BadRequest
from backports.datetime_fromisoformat import MonkeyPatch
from flaschengeist import logger
from flaschengeist.models.session import Session
from flaschengeist.utils.datetime import from_iso_format
from flaschengeist.decorator import login_required
from flaschengeist.controller import userController
from flaschengeist.plugins import Plugin, update_user_hook
from . import balance_controller, permissions, models
MonkeyPatch.patch_fromisoformat()
balance_bp = Blueprint("balance", __name__)
@ -36,6 +35,7 @@ class BalancePlugin(Plugin):
def install(self):
from flaschengeist.database import db
db.create_all()
@ -115,13 +115,13 @@ def get_balance(userid, current_session: Session):
start = request.args.get("from")
if start:
start = datetime.fromisoformat(start).replace(tzinfo=timezone.utc)
start = from_iso_format(start)
else:
start = datetime.fromtimestamp(0, tz=timezone.utc)
end = request.args.get("to")
if end:
end = datetime.fromisoformat(end).replace(tzinfo=timezone.utc)
end = from_iso_format(end)
else:
end = datetime.now(tz=timezone.utc)

View File

View File

@ -0,0 +1,11 @@
import datetime
from backports.datetime_fromisoformat import MonkeyPatch
MonkeyPatch.patch_fromisoformat()
def from_iso_format(date_str):
"""Z-suffix aware version of `datetime.datetime.fromisoformat`"""
time = datetime.datetime.fromisoformat(date_str.replace('Z', '+00:00'))
if time.tzinfo:
return time.astimezone(tzinfo=datetime.timezone.utc)
return time.replace(tzinfo=datetime.timezone.utc)