Skip to content

Commit

Permalink
[frontend/accessibility] Applying utc timezone to min and max and fix…
Browse files Browse the repository at this point in the history
… string handling in accessibility.html
  • Loading branch information
AlexandreDoneux committed May 17, 2024
1 parent 8ba784c commit 6ae1b50
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
16 changes: 12 additions & 4 deletions inginious/frontend/accessible_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def parse_date(date, default=None):
raise Exception("Empty date given to AccessibleTime")

if date == "0001-01-01 00:00:00":
return datetime.min
return datetime.min.replace(tzinfo=timezone.utc)
if date == "9999-12-31 23:59:59":
return datetime.max.replace(microsecond=0)
return datetime.max.replace(microsecond=0, tzinfo=timezone.utc)

for format_type in ["%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d %H", "%Y-%m-%d", "%d/%m/%Y %H:%M:%S",
"%d/%m/%Y %H:%M", "%d/%m/%Y %H", "%d/%m/%Y"]:
Expand All @@ -46,8 +46,8 @@ def __init__(self, period):
Can be a boolean, None or string if using the legacy format "start/soft_end/end"
"""

self.max = datetime.max.replace(microsecond=0)
self.min = datetime.min.replace()
self.max = datetime.max.replace(microsecond=0, tzinfo=timezone.utc)
self.min = datetime.min.replace(tzinfo=timezone.utc)

if not isinstance(period, (dict, str, bool, type(None))): # add None check
raise Exception("Wrong period given to AccessibleTime")
Expand Down Expand Up @@ -178,3 +178,11 @@ def get_string_dict(self):
"soft_end": self.string_date(self._soft_end),
"end": self.string_date(self._end)
}

def string_max(self):
""" Returns the max date as a string """
return self.string_date(self.max)

def string_min(self):
""" Returns the min date as a string """
return self.string_date(self.min)
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<script>
const timezone = "{{user_manager.session_timezone()}}" !== "None" ? "{{user_manager.session_timezone()}}" : Intl.DateTimeFormat().resolvedOptions().timeZone;
js_datetime_format = "{{available_datetime_formats[user_manager.session_datetime_format()]}}";
special_dates = ["{{at.string_min()}}", "{{at.string_max()}}"]

// Feed modal
$("#edit_task_modal").on('show.bs.modal', function (event) {
Expand All @@ -108,7 +109,6 @@
var accessibility = dispenser_config[taskid]["accessibility"];
var value;

special_dates = ["{{ at.min }}", "{{ at.max }}"]
function isSpecialDate(date) {
return special_dates.includes(date);
}
Expand All @@ -125,7 +125,7 @@
$("#accessibility_end").val(end_date);

} else {
if (Object.values(accessibility).some(date => date == "{{ at.min }}")) {
if (Object.values(accessibility).some(date => date == special_dates[0])) {
value = 'true';
} else {
value = 'false';
Expand All @@ -151,14 +151,14 @@
$("#task_" + taskid + " .accessibility").hide();
if($(this).val() == "true") {
$("#task_" + taskid + " .accessibility-always").show();
dispenser_config[taskid]["accessibility"]["start"] = "{{ at.min }}";
dispenser_config[taskid]["accessibility"]["soft_end"] = "{{ at.max }}";
dispenser_config[taskid]["accessibility"]["end"] = "{{ at.max }}";
dispenser_config[taskid]["accessibility"]["start"] = special_dates[0];
dispenser_config[taskid]["accessibility"]["soft_end"] = special_dates[1];
dispenser_config[taskid]["accessibility"]["end"] = special_dates[1];
} else if($(this).val() == "false") {
$("#task_" + taskid + " .accessibility-never").show();
dispenser_config[taskid]["accessibility"]["start"] = "{{ at.max }}";
dispenser_config[taskid]["accessibility"]["soft_end"] = "{{ at.max }}";
dispenser_config[taskid]["accessibility"]["end"] = "{{ at.max }}";
dispenser_config[taskid]["accessibility"]["start"] = special_dates[1];
dispenser_config[taskid]["accessibility"]["soft_end"] = special_dates[1];
dispenser_config[taskid]["accessibility"]["end"] = special_dates[1];
} else {
$("#task_" + taskid + " .accessibility-custom").show();

Expand All @@ -170,9 +170,9 @@
soft_end = soft_end !== "" ? moment(soft_end, js_datetime_format).tz(timezone).clone().utc().format('YYYY-MM-DD HH:mm:ss') : "";
end = end !== "" ? moment(end, js_datetime_format).tz(timezone).clone().utc().format('YYYY-MM-DD HH:mm:ss') : "";

dispenser_config[taskid]["accessibility"]["start"] = start == "" ? "{{ at.min }}" : start;
dispenser_config[taskid]["accessibility"]["soft_end"] = soft_end == "" ? "{{ at.max }}" : soft_end;
dispenser_config[taskid]["accessibility"]["end"] = end == "" ? "{{ at.max }}" : end;
dispenser_config[taskid]["accessibility"]["start"] = start == "" ? special_dates[0] : start;
dispenser_config[taskid]["accessibility"]["soft_end"] = soft_end == "" ? special_dates[1] : soft_end;
dispenser_config[taskid]["accessibility"]["end"] = end == "" ? special_dates[1] : end;
}
} else {
let id = $(this).attr("id");
Expand All @@ -181,17 +181,17 @@
var start = $("#edit_task_modal").find("#accessibility_start").val()
$("#task_" + taskid + " .accessibility-custom-start").text(start);
start = start !== "" ? moment(start, js_datetime_format).tz(timezone).clone().utc().format('YYYY-MM-DD HH:mm:ss') : "";
dispenser_config[taskid]["accessibility"]["start"] = start == "" ? "{{ at.min }}" : start;
dispenser_config[taskid]["accessibility"]["start"] = start == "" ? special_dates[0] : start;
} else if(id == "accessibility_end") {
var end = $("#edit_task_modal").find("#accessibility_end").val()
$("#task_" + taskid + " .accessibility-custom-end").text(end);
end = end !== "" ? moment(end, js_datetime_format).tz(timezone).clone().utc().format('YYYY-MM-DD HH:mm:ss') : "";
dispenser_config[taskid]["accessibility"]["end"] = end == "" ? "{{ at.max }}" : end;
dispenser_config[taskid]["accessibility"]["end"] = end == "" ? special_dates[1] : end;
} else {
var soft_end = $("#edit_task_modal").find("#accessibility_soft_end").val()
$("#task_" + taskid + " .accessibility-custom-soft-end").text(soft_end);
soft_end = soft_end !== "" ? moment(soft_end, js_datetime_format).tz(timezone).clone().utc().format('YYYY-MM-DD HH:mm:ss') : "";
dispenser_config[taskid]["accessibility"]["soft_end"] = soft_end == "" ? "{{ at.max }}" : soft_end;
dispenser_config[taskid]["accessibility"]["soft_end"] = soft_end == "" ? special_dates[1] : soft_end;
}
}
});
Expand All @@ -210,14 +210,14 @@
$("#task_" + taskid + " .accessibility").hide();
if(value == "true") {
$("#task_" + taskid + " .accessibility-always").show();
dispenser_config[taskid]["accessibility"]["start"] = "{{ at.min }}";
dispenser_config[taskid]["accessibility"]["soft_end"] = "{{ at.max }}";
dispenser_config[taskid]["accessibility"]["end"] = "{{ at.max }}";
dispenser_config[taskid]["accessibility"]["start"] = special_dates[0];
dispenser_config[taskid]["accessibility"]["soft_end"] = special_dates[1];
dispenser_config[taskid]["accessibility"]["end"] = special_dates[1];
} else if(value== "false") {
$("#task_" + taskid + " .accessibility-never").show();
dispenser_config[taskid]["accessibility"]["start"] = "{{ at.max }}";
dispenser_config[taskid]["accessibility"]["soft_end"] = "{{ at.max }}";
dispenser_config[taskid]["accessibility"]["end"] = "{{ at.max }}";
dispenser_config[taskid]["accessibility"]["start"] = special_dates[1];
dispenser_config[taskid]["accessibility"]["soft_end"] = special_dates[1];
dispenser_config[taskid]["accessibility"]["end"] = special_dates[1];
} else {
$("#task_" + taskid + " .accessibility-custom").show();

Expand All @@ -229,9 +229,9 @@
soft_end = soft_end !== "" ? moment(soft_end, js_datetime_format).tz(timezone).clone().utc().format('YYYY-MM-DD HH:mm:ss') : "";
end = end !== "" ? moment(end, js_datetime_format).tz(timezone).clone().utc().format('YYYY-MM-DD HH:mm:ss') : "";

dispenser_config[taskid]["accessibility"]["start"] = start == "" ? "{{ at.min }}" : start;
dispenser_config[taskid]["accessibility"]["soft_end"] = soft_end == "" ? "{{ at.max }}" : soft_end;
dispenser_config[taskid]["accessibility"]["end"] = end == "" ? "{{ at.max }}" : end;
dispenser_config[taskid]["accessibility"]["start"] = start == "" ? special_dates[0] : start;
dispenser_config[taskid]["accessibility"]["soft_end"] = soft_end == "" ? special_dates[1] : soft_end;
dispenser_config[taskid]["accessibility"]["end"] = end == "" ? special_dates[1] : end;
}
} else {
if (id == "accessibility_start")
Expand All @@ -250,9 +250,9 @@
end = end !== "" ? moment(end, js_datetime_format).tz(timezone).clone().utc().format('YYYY-MM-DD HH:mm:ss') : "";

if ($("input[value='custom']").is(":checked")) {
dispenser_config[taskid]["accessibility"]["start"] = start == "" ? "{{ at.min }}" : start;
dispenser_config[taskid]["accessibility"]["soft_end"] = soft_end == "" ? "{{ at.max }}" : soft_end;
dispenser_config[taskid]["accessibility"]["end"] = end == "" ? "{{ at.max }}" : end;
dispenser_config[taskid]["accessibility"]["start"] = start == "" ? special_dates[0] : start;
dispenser_config[taskid]["accessibility"]["soft_end"] = soft_end == "" ? special_dates[1] : soft_end;
dispenser_config[taskid]["accessibility"]["end"] = end == "" ? special_dates[1] : end;
}
}
});
Expand Down

0 comments on commit 6ae1b50

Please sign in to comment.