Skip to content

Commit 7dd558b

Browse files
committed
Format user dates in BR timezone
1 parent a409cbe commit 7dd558b

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

apps/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from authlib.integrations.flask_client import OAuth
1818
from flask_mail import Mail
1919
from flask_caching import Cache
20+
from datetime import timedelta
2021

2122

2223
db = SQLAlchemy()
@@ -94,6 +95,17 @@ def create_app(config):
9495
app = Flask(__name__)
9596
app.config.from_object(config)
9697

98+
# UTC to UTC-3
99+
@app.template_filter("br_datetime")
100+
def br_datetime(value, fmt="%d/%m/%Y %H:%M"):
101+
if not value:
102+
return ""
103+
try:
104+
local = value - timedelta(hours=3)
105+
return local.strftime(fmt)
106+
except Exception:
107+
return str(value)
108+
97109
register_extensions(app)
98110
register_blueprints(app)
99111
# configure_database(app)

apps/templates/pages/users.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ <h3 class="card-title">Current users ({{'All' if current_user.category == "admin
9393
{% if user.last_login %}data-order="{{ user.last_login.isoformat() }}"{% else %}data-order=""{% endif %}
9494
title="{% if user.last_login %}{{ user.last_login.isoformat() }}{% else %}—{% endif %}"
9595
>
96-
{% if user.last_login %}{{ user.last_login.strftime('%d/%m/%Y %H:%M') }}{% else %}&mdash;{% endif %}
96+
{% if user.last_login %}{{ user.last_login|br_datetime }}{% else %}&mdash;{% endif %}
9797
</td>
9898

9999
<td
100100
{% if user.created_at %}data-order="{{ user.created_at.isoformat() }}"{% else %}data-order=""{% endif %}
101101
title="{% if user.created_at %}{{ user.created_at.isoformat() }}{% else %}—{% endif %}"
102102
>
103-
{% if user.created_at %}{{ user.created_at.strftime('%d/%m/%Y %H:%M') }}{% else %}&mdash;{% endif %}
103+
{% if user.created_at %}{{ user.created_at|br_datetime }}{% else %}&mdash;{% endif %}
104104
</td>
105105

106106
<td><a href="{{url_for('home_blueprint.edit_user', user_id=user.id)}}" class="btn btn-outline-dark" role="button" aria-pressed="true"><i class="fa fa-pen"></i> Edit</a></td>

0 commit comments

Comments
 (0)