diff --git a/admin/views/fdd/rule.html b/admin/views/fdd/rule.html index 5f01acb2..e883b08b 100644 --- a/admin/views/fdd/rule.html +++ b/admin/views/fdd/rule.html @@ -21,7 +21,6 @@ {{'FDD.EXPRESSION' | translate}} {{'FDD.MESSAGE_TEMPLATE' | translate}} {{'SETTING.ACTION' | translate}} - @@ -33,14 +32,13 @@ {{ rule.priority }} {{ rule.channel }} {{ rule.is_enabled==true?'SETTING.ON':'SETTING.OFF' | translate}} - {{ rule.last_run_datetime | date:'yyyy-MM-ddTHH:mm:ss'}} - {{ rule.next_run_datetime | date:'yyyy-MM-ddTHH:mm:ss'}} + {{ rule.last_run_datetime }} + {{ rule.next_run_datetime }} {{'FDD.CLICK_EDIT_FOR_DETAILS' | translate}} {{'FDD.CLICK_EDIT_FOR_DETAILS' | translate}} {{'SETTING.EDIT' | translate}} {{'SETTING.DELETE' | translate}} - diff --git a/myems-api/README.md b/myems-api/README.md index ee33ecef..11f7167b 100644 --- a/myems-api/README.md +++ b/myems-api/README.md @@ -1247,8 +1247,8 @@ Result in JSON | expression | string | JSON string of diagnosed objects, points, values, and recipients | | message_template | string | Plain text template that supports $-substitutions | | is_enabled | boolean | Indicates if this rule is enabled | -| last_run_datetime | float | null, or the number of milliseconds since January 1, 1970, 00:00:00, universal time | -| next_run_datetime | float | null, or the number of milliseconds since January 1, 1970, 00:00:00, universal time | +| last_run_datetime | float | null, or the last run datetime string in local timezone | +| next_run_datetime | float | null, or the next run datetime string in local timezone | ```bash curl -i -X GET {{base_url}}/rules/{id} diff --git a/myems-api/core/rule.py b/myems-api/core/rule.py index e2db14d1..90796428 100644 --- a/myems-api/core/rule.py +++ b/myems-api/core/rule.py @@ -2,7 +2,7 @@ import falcon import json import mysql.connector import uuid -from datetime import timezone +from datetime import datetime, timezone, timedelta import config from core.userlogger import user_logger @@ -33,16 +33,26 @@ class RuleCollection: cursor.close() cnx.disconnect() + timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6]) + if config.utc_offset[0] == '-': + timezone_offset = -timezone_offset + result = list() if rows is not None and len(rows) > 0: for row in rows: - last_run_datetime = None - if row['last_run_datetime_utc'] is not None: - last_run_datetime = row['last_run_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000 + if isinstance(row['last_run_datetime_utc'], datetime): + last_run_datetime_local = row['last_run_datetime_utc'].replace(tzinfo=timezone.utc) + \ + timedelta(minutes=timezone_offset) + last_run_datetime = last_run_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') + else: + last_run_datetime = None - next_run_datetime = None - if row['next_run_datetime_utc'] is not None: - next_run_datetime = row['next_run_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000 + if isinstance(row['next_run_datetime_utc'], datetime): + next_run_datetime_local = row['next_run_datetime_utc'].replace(tzinfo=timezone.utc) + \ + timedelta(minutes=timezone_offset) + next_run_datetime = next_run_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') + else: + next_run_datetime = None meta_result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], "category": row['category'], "fdd_code": row['fdd_code'], "priority": row['priority'], @@ -204,13 +214,23 @@ class RuleItem: if row is None: raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.RULE_NOT_FOUND') - last_run_datetime = None - if row['last_run_datetime_utc'] is not None: - last_run_datetime = row['last_run_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000 + timezone_offset = int(config.utc_offset[1:3]) * 60 + int(config.utc_offset[4:6]) + if config.utc_offset[0] == '-': + timezone_offset = -timezone_offset - next_run_datetime = None - if row['next_run_datetime_utc'] is not None: - next_run_datetime = row['next_run_datetime_utc'].replace(tzinfo=timezone.utc).timestamp() * 1000 + if isinstance(row['last_run_datetime_utc'], datetime): + last_run_datetime_local = row['last_run_datetime_utc'].replace(tzinfo=timezone.utc) + \ + timedelta(minutes=timezone_offset) + last_run_datetime = last_run_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') + else: + last_run_datetime = None + + if isinstance(row['next_run_datetime_utc'], datetime): + next_run_datetime_local = row['next_run_datetime_utc'].replace(tzinfo=timezone.utc) + \ + timedelta(minutes=timezone_offset) + next_run_datetime = next_run_datetime_local.strftime('%Y-%m-%dT%H:%M:%S') + else: + next_run_datetime = None result = {"id": row['id'], "name": row['name'], "uuid": row['uuid'], "category": row['category'], "fdd_code": row['fdd_code'], "priority": row['priority'],