diff --git a/compair/api/assignment.py b/compair/api/assignment.py index 40d37569..2aa93a0f 100644 --- a/compair/api/assignment.py +++ b/compair/api/assignment.py @@ -36,6 +36,7 @@ def non_blank_text(value): new_assignment_parser.add_argument('answer_end', required=True, nullable=False) new_assignment_parser.add_argument('compare_start', default=None) new_assignment_parser.add_argument('compare_end', default=None) +new_assignment_parser.add_argument('compare_localTimeZone', default='UTC') new_assignment_parser.add_argument('self_eval_start', default=None) new_assignment_parser.add_argument('self_eval_end', default=None) new_assignment_parser.add_argument('self_eval_instructions', type=non_blank_text, default=None) diff --git a/compair/api/assignment_search_enddate.py b/compair/api/assignment_search_enddate.py index 94da5412..eec61962 100644 --- a/compair/api/assignment_search_enddate.py +++ b/compair/api/assignment_search_enddate.py @@ -4,6 +4,8 @@ from sqlalchemy import create_engine import json from flask import jsonify +import pytz + from bouncer.constants import READ, EDIT, CREATE, DELETE, MANAGE from flask import Blueprint, current_app @@ -46,14 +48,27 @@ def get(self): search_date_assignment_parser = RequestParser() search_date_assignment_parser.add_argument('compare_start', default=datetime.now().strftime("%Y-%m-%d")) search_date_assignment_parser.add_argument('compare_end', default=datetime.now().strftime("%Y-%m-%d")) + search_date_assignment_parser.add_argument('compare_localTimeZone', default='UTC') + args = search_date_assignment_parser.parse_args() - end_date = datetime.now().strftime("%Y-%m-%d") + end_date = datetime.now().strftime("%Y-%m-%d 00:00:00") start_date = datetime.now().strftime("%Y-%m-%d") + compare_localTimeZone = 'UTC' + if (args['compare_localTimeZone']): + compare_localTimeZone = str(args['compare_localTimeZone']) if validate(args['compare_end']): - end_date = str(args['compare_end']) + end_date = str(args['compare_end']) + ' 00:00:00' + + ##convert this to UTC + local = pytz.timezone(compare_localTimeZone) + naive = datetime.strptime(end_date, "%Y-%m-%d %H:%M:%S") + local_dt = local.localize(naive, is_dst=None) + utc_dt = local_dt.astimezone(pytz.utc) + end_date = str(utc_dt) + if validate(args['compare_start']): start_date = str(args['compare_start']) @@ -61,7 +76,8 @@ def get(self): engine = create_engine(db_url, pool_size=5, pool_recycle=3600) conn = engine.connect() - sql_text = str("SELECT JSON_OBJECT('course_name', t1.name,'name', t2.name,'answer_start', date_format(t2.answer_start, '%%M %%d, %%Y'),'answer_end', date_format(t2.answer_end, '%%M %%d, %%Y'),'compare_start', date_format(t2.compare_start, '%%M %%d, %%Y'), 'compare_end', date_format(t2.compare_end, '%%M %%d, %%Y')) FROM course as t1, assignment as t2 WHERE (t1.id = t2.course_id) AND (t2.active=1) AND (t2.compare_end >= '" + end_date + "' OR answer_end >= '" + end_date + "');"); + sql_text = str("SELECT JSON_OBJECT('course_name', t1.name,'name', t2.name,'answer_start', date_format(t2.answer_start, '%%M %%d, %%Y'),'answer_end', date_format(t2.answer_end, '%%M %%d, %%Y'),'compare_start', date_format(t2.compare_start, '%%M %%d, %%Y'), 'compare_end', date_format(t2.compare_end, '%%M %%d, %%Y'), 'self_eval_end', date_format(t2.self_eval_end, '%%M %%d, %%Y'), 'self_eval_start', date_format(t2.self_eval_start, '%%M %%d, %%Y')) FROM course as t1, assignment as t2 WHERE (t1.id = t2.course_id) AND (t2.active=TRUE) AND (t2.compare_end >= '" + end_date + "' OR answer_end >= '" + end_date + "' OR self_eval_end >= '" + end_date + "');"); + result = conn.execute(sql_text) final_result = [list(i) for i in result] diff --git a/compair/static/script-assignment-search.js b/compair/static/script-assignment-search.js index 2c0c1839..24b25be9 100644 --- a/compair/static/script-assignment-search.js +++ b/compair/static/script-assignment-search.js @@ -3,6 +3,10 @@ let api_url = "/api/assignment/search/enddate"; const options = { year: 'numeric', month: 'short', day: 'numeric' }; var searchDay = new Date().toLocaleDateString('en-us', options); +const d = new Date(); +let diff = d.getTimezoneOffset(); +let localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone; + function formatDate(date) { var d = (new Date(date.toString().replace(/-/g, '\/')) ); return d.toLocaleDateString('en-ca', options); @@ -11,7 +15,9 @@ function formatDate(date) { function getObjectDate(object) { searchDay = formatDate(object); - strURL = api_url.concat('?compare_end=').concat(object); + strURL = api_url.concat('?compare_end=').concat(object).concat('&compare_localTimeZone=').concat(localTimeZone.toString()); + + console.log(localTimeZone); getsearchapi(strURL); } @@ -51,7 +57,7 @@ function showsearchapi(search_data) { for (let key in search_data) { //tab += `