Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlanReleaseDate: Updated date displays to browser's timezone. #1032

Closed
wants to merge 12 commits into from
7 changes: 2 additions & 5 deletions compair/api/assignment_search_enddate.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
assignment_search_enddate_api = Blueprint('assignment_search_enddate_api', __name__)
api = new_restful_api(assignment_search_enddate_api)

##event
on_assignment_get = event.signal('ASSIGNMENT_GET')

def validate(date_text):
try:
if date_text != datetime.strptime(date_text, "%Y-%m-%d").strftime('%Y-%m-%d'):
Expand All @@ -48,7 +45,7 @@ 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')
search_date_assignment_parser.add_argument('compare_localTimeZone', default='America/Vancouver')

args = search_date_assignment_parser.parse_args()

Expand Down Expand Up @@ -76,7 +73,7 @@ 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'), '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 t1.active=TRUE) AND (t2.compare_end >= '" + end_date + "' OR answer_end >= '" + end_date + "' OR self_eval_end >= '" + end_date + "');");
sql_text = str("SELECT JSON_OBJECT('course_name', t1.name,'name', t2.name,'answer_start', date_format(CONVERT_TZ(t2.answer_start, 'UTC','" + compare_localTimeZone + "'), '%%b %%d, %%Y'),'answer_end', date_format(CONVERT_TZ(t2.answer_end, 'UTC','" + compare_localTimeZone + "'), '%%b %%d, %%Y'),'compare_start', date_format(CONVERT_TZ(t2.compare_start, 'UTC','" + compare_localTimeZone + "'), '%%b %%d, %%Y'), 'compare_end', date_format(CONVERT_TZ(t2.compare_end, 'UTC','" + compare_localTimeZone + "'), '%%b %%d, %%Y'), 'self_eval_end', date_format(CONVERT_TZ(t2.self_eval_end, 'UTC','" + compare_localTimeZone + "'), '%%b %%d, %%Y'), 'self_eval_start', date_format(CONVERT_TZ(t2.self_eval_start, 'UTC','" + compare_localTimeZone + "'), '%%b %%d, %%Y')) FROM course as t1, assignment as t2 WHERE (t1.id = t2.course_id) AND (t2.active=TRUE AND t1.active=TRUE) AND (t2.compare_end >= '" + end_date + "' OR answer_end >= '" + end_date + "' OR self_eval_end >= '" + end_date + "');");

result = conn.execute(sql_text)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1 class="col-sm-8">Plan Release Date</h1>
<!--calendar-->
<div ng-app="ubc.ctlt.compair.assignment" ng-controller="AssignmentSearchEndDateController as ctrlEndDate" >
<div class="input-group" style="width:200px" >
<input type="text" class="form-control" uib-datepicker-popup="yyyy-MMM-dd" ng-model="dt" is-open="isDatepickerOpen" ng-change="searchDate();" datepicker-options="datepickerOptions" ng-required="true" close-text="Close" alt-input-formats="altInputFormats"/>
<input type="text" class="form-control" uib-datepicker-popup="yyyy-MMM-dd" ng-model="dt" is-open="isDatepickerOpen" ng-change="searchDate();" datepicker-options="datepickerOptions" ng-required="true" ng-readonly="true" close-text="Close" alt-input-formats="altInputFormats"/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="isDatepickerOpen = !isDatepickerOpen">
<i class="glyphicon glyphicon-calendar"></i>
Expand Down
30 changes: 24 additions & 6 deletions compair/static/script-assignment-search.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
let api_url = "/api/assignment/search/enddate";

const options = { year: 'numeric', month: 'short', day: 'numeric' };
var searchDay = new Date().toLocaleDateString('en-us', options);
let localeLang = 'en-ca';
var searchDay = new Date().toLocaleDateString(localeLang, options);

const d = new Date();
let diff = d.getTimezoneOffset();
let localTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

function formatDateYYMMDD(date) {
var d = new Date(date),
month = '' + (d.getMonth() + 1),
day = '' + d.getDate(),
year = d.getFullYear();

if (month.length < 2)
month = '0' + month;
if (day.length < 2)
day = '0' + day;

return [year, month, day].join('-');
}

function formatDate(date) {
if (date.includes("Invalid Date")){
return searchDay;
}
var d = (new Date(date.toString().replace(/-/g, '\/')) );
return d.toLocaleDateString('en-ca', options);
return d.toLocaleDateString(localeLang, options);
}

function getObjectDate(object)
{
searchDay = formatDate(object);
strURL = api_url.concat('?compare_end=').concat(object).concat('&compare_localTimeZone=').concat(localTimeZone.toString());

console.log(localTimeZone);
if (object.includes("Invalid Date")){
searchDay = new Date().toLocaleDateString(localeLang, options);
}
strURL = api_url.concat('?compare_end=').concat(formatDateYYMMDD(searchDay)).concat('&compare_localTimeZone=').concat(localTimeZone.toString());

getsearchapi(strURL);
}
Expand Down Expand Up @@ -55,7 +74,6 @@ function showsearchapi(search_data) {

var iKey = 0;
for (let key in search_data) {
//tab += `<tr><td colspan="4">${search_data[key]}</td></tr>`;
let obj = JSON.parse(search_data[key])

if (obj.compare_start == null){
Expand Down