diff --git a/changedetectionio/flask_app.py b/changedetectionio/flask_app.py index 04f9400b..37da7699 100644 --- a/changedetectionio/flask_app.py +++ b/changedetectionio/flask_app.py @@ -38,6 +38,8 @@ from flask_restful import abort, Api from flask_cors import CORS from flask_wtf import CSRFProtect from loguru import logger +from zoneinfo import ZoneInfo + from changedetectionio import html_tools, __version__ from changedetectionio import queuedWatchMetaData @@ -159,21 +161,6 @@ def _jinja2_filter_pagination_slice(arr, skip): return arr -def app_get_system_time(): - from zoneinfo import ZoneInfo # Built-in timezone support in Python 3.9+ - - system_timezone = datastore.data['settings']['application'].get('timezone') - if not system_timezone: - system_timezone = os.environ.get("TZ") - - try: - system_zone = ZoneInfo(system_timezone) - except Exception as e: - logger.warning(f'Warning, unable to use timezone "{system_timezone}" defaulting to UTC- {str(e)}') - system_zone = ZoneInfo("UTC") # Fallback to UTC if the timezone is invalid - - return system_zone - @app.template_filter('format_seconds_ago') def _jinja2_filter_seconds_precise(timestamp): if timestamp == False: @@ -258,9 +245,6 @@ def changedetection_app(config=None, datastore_o=None): # (instead of the global var) app.config['DATASTORE'] = datastore_o - # Just to check (it will output some debug if not) - app_get_system_time() - login_manager = flask_login.LoginManager(app) login_manager.login_view = 'login' app.secret_key = init_app_secret(config['datastore_path']) @@ -968,12 +952,8 @@ def changedetection_app(config=None, datastore_o=None): else: flash("An error occurred, please see below.", "error") - - system_timezone = app_get_system_time() - system_time = datetime.now(system_timezone) - - # Fallback for locale formatting - formatted_system_time = system_time.strftime("%Y-%m-%d %H:%M:%S %Z%z") # Locale-aware time + # Convert to ISO 8601 format, all date/time relative events stored as UTC time + utc_time = datetime.now(ZoneInfo("UTC")).isoformat() output = render_template("settings.html", api_key=datastore.data['settings']['application'].get('api_access_token'), @@ -983,8 +963,7 @@ def changedetection_app(config=None, datastore_o=None): hide_remove_pass=os.getenv("SALTED_PASS", False), min_system_recheck_seconds=int(os.getenv('MINIMUM_SECONDS_RECHECK_TIME', 3)), settings_application=datastore.data['settings']['application'], - system_time=formatted_system_time, - timezone_name=system_timezone + utc_time=utc_time, ) return output diff --git a/changedetectionio/static/js/global-settings.js b/changedetectionio/static/js/global-settings.js index 126c15da..940b9aa1 100644 --- a/changedetectionio/static/js/global-settings.js +++ b/changedetectionio/static/js/global-settings.js @@ -24,5 +24,8 @@ $(document).ready(function () { $(target).toggle(); }); + $(".local-time").each(function (e) { + $(this).text(new Date($(this).data("utc")).toLocaleString()); + }) }); diff --git a/changedetectionio/templates/settings.html b/changedetectionio/templates/settings.html index 50ffebf5..6db71aca 100644 --- a/changedetectionio/templates/settings.html +++ b/changedetectionio/templates/settings.html @@ -79,8 +79,8 @@ When a request returns no content, or the HTML does not contain any text, is this considered a change?
-

Local Time: {{ system_time }}

-

Timezone: {{ timezone_name }}

+

UTC Time from Server: {{ utc_time }}

+

Local Time in Browser:

{% if form.requests.proxy %}