Skip to content

Commit

Permalink
added date conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
saravanpa-aot committed Sep 29, 2023
1 parent e1b4600 commit f17ac21
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
3 changes: 3 additions & 0 deletions met-api/src/met_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ class _Config(): # pylint: disable=too-few-public-methods
EPIC_MILESTONE = os.getenv('EPIC_MILESTONE')
EPIC_KC_CLIENT_ID = os.getenv('EPIC_KC_CLIENT_ID')

# legislative timezone for future effective dating
LEGISLATIVE_TIMEZONE = os.getenv('LEGISLATIVE_TIMEZONE', 'America/Vancouver')


class DevConfig(_Config): # pylint: disable=too-few-public-methods
"""Dev Config."""
Expand Down
2 changes: 1 addition & 1 deletion met-api/src/met_api/services/engagement_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def edit_engagement(data: dict):

has_epic_fields_getting_updated = 'end_date' in data or 'start_date' in data
if has_epic_fields_getting_updated:
ProjectService.update_project_info(updated_engagement.engagement_id)
ProjectService.update_project_info(updated_engagement.id)

if survey_block:
EngagementService._save_or_update_eng_block(engagement_id, survey_block)
Expand Down
11 changes: 8 additions & 3 deletions met-api/src/met_api/services/project_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from met_api.services.email_verification_service import EmailVerificationService
from met_api.services.rest_service import RestService
from met_api.utils import notification
from met_api.utils.datetime import get_local_formatted_date_time


class ProjectService:
Expand All @@ -27,7 +28,7 @@ def update_project_info(eng_id: str) -> EngagementModel:
engagement_metadata: EngagementMetadataModel
engagement, engagement_metadata = ProjectService._get_engagement_and_metadata(eng_id)

if project_id := engagement_metadata.project_id:
if not (project_id := engagement_metadata.project_id):
# EPIC is not interested in the data without project Id.So Skip the process.
return

Expand Down Expand Up @@ -64,9 +65,13 @@ def _get_engagement_and_metadata(eng_id: str):

@staticmethod
def _construct_epic_payload(engagement, project_id):
print('----engagement.start_date----',engagement.start_date)
print('----engagement.end_date----', engagement.end_date)
site_url = notification.get_tenant_site_url(engagement.tenant_id)
start_date_utc = engagement.start_date.isoformat()
end_date_utc = engagement.end_date.isoformat()
start_date_utc = get_local_formatted_date_time(engagement.start_date)
end_date_utc = get_local_formatted_date_time(engagement.end_date)
print('----start_date_utc----', start_date_utc)
print('----end_date_utc----', end_date_utc)
epic_comment_period_payload = {
'isMet': 'true',
# metURL is the public url using slug
Expand Down
23 changes: 21 additions & 2 deletions met-api/src/met_api/utils/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Datetime object helper."""
from datetime import datetime

import pytz
from flask import current_app

from datetime import datetime


def local_datetime():
Expand All @@ -29,3 +30,21 @@ def utc_datetime():
utcmoment = datetime.utcnow().replace(tzinfo=pytz.utc)
now = utcmoment.astimezone(pytz.timezone('UTC'))
return now


def get_local_time(date_val: datetime, timezone_override=None):
"""Return local time value."""
tz_name = timezone_override or current_app.config['LEGISLATIVE_TIMEZONE']
tz_local = pytz.timezone(tz_name)
date_val = date_val.astimezone(tz_local)
return date_val


def get_local_formatted_date_time(date_val: datetime, dt_format: str = '%Y-%m-%d %H:%M:%S'):
"""Return formatted local time."""
return get_local_time(date_val).strftime(dt_format)


def get_local_formatted_date(date_val: datetime, dt_format: str = '%Y-%m-%d'):
"""Return formatted local time."""
return get_local_time(date_val).strftime(dt_format)

0 comments on commit f17ac21

Please sign in to comment.