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 7566c75 commit 8568176
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 3 additions & 7 deletions met-api/src/met_api/services/project_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +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
from met_api.utils.datetime import convert_and_format_to_utc_str


class ProjectService:
Expand Down Expand Up @@ -69,14 +69,10 @@ 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 = get_local_formatted_date_time(engagement.start_date)
end_date_utc = get_local_formatted_date_time(engagement.end_date)
start_date_utc = convert_and_format_to_utc_str(engagement.start_date)
end_date_utc = convert_and_format_to_utc_str(engagement.end_date)
print('----start_date_utc----', start_date_utc)
print('----end_date_utc----', end_date_utc)
start_date_utc = engagement.start_date.isoformat()
end_date_utc = engagement.end_date.isoformat()
print('----start_date_utc-ISO---', start_date_utc)
print('----end_date_utc--ISO--', end_date_utc)

epic_comment_period_payload = {
'isMet': 'true',
Expand Down
16 changes: 16 additions & 0 deletions met-api/src/met_api/utils/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,19 @@ def get_local_formatted_date_time(date_val: datetime, dt_format: str = '%Y-%m-%d
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)

def convert_and_format_to_utc_str(date_val: datetime, dt_format='%Y-%m-%d %H:%M:%S', timezone_override=None):
"""Convert a datetime object to UTC and format it as a string."""
tz_name = timezone_override or current_app.config['LEGISLATIVE_TIMEZONE']
tz_local = pytz.timezone(tz_name)

# Assume the input datetime is in the local time zone
date_val = tz_local.localize(date_val)

# Convert to UTC
date_val_utc = date_val.astimezone(pytz.UTC)

# Format as a string
utc_datetime_str = date_val_utc.strftime(dt_format)

return utc_datetime_str

0 comments on commit 8568176

Please sign in to comment.