Skip to content

Commit 79d1baf

Browse files
committed
Fix date issues
1 parent 3f91a68 commit 79d1baf

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

templates/admin/editcontest.html

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
{% block main %}
66
<h1>Edit Contest</h1>
77
<form autocomplete="off" method="post" id="edit" name="edit">
8-
<input class="form-control form-group" type="text" id="name" name="name" placeholder="Name" value="{{ data["name"] }}" required>
8+
<input class="form-control form-group" type="text" id="name" name="name" placeholder="Name" value="{{ data['name'] }}" required>
99
<div style="position: relative;">
1010
<textarea class="form-control form-group md-preview" id="description" name="description" rows="20" placeholder="Description" required>{{ data["description"] }}</textarea>
1111
<div id="description-out" class="md-preview"></div>
1212
</div>
13-
<input class="form-control form-group dtl" type="text" id="start" name="start" placeholder="Start Date & Time" value="{{ data["start"] }}" required>
14-
<input class="form-control form-group dtl" type="text" id="end" name="end" placeholder="End Date & Time" value="{{ data["end"] }}" required>
13+
<input class="form-control form-group dtl" type="datetime-local" id="start" name="start" placeholder="Start Date & Time" value="{{ data['start'] }}" required>
14+
<input class="form-control form-group dtl" type="datetime-local" id="end" name="end" placeholder="End Date & Time" value="{{ data['end'] }}" required>
1515
<input class="btn btn-primary" type="submit" id="submit" name="submit" value="Edit">
1616
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
1717
</form>
@@ -20,10 +20,19 @@ <h1>Edit Contest</h1>
2020
var product = converter.makeHtml(document.getElementById('description').value);
2121
$('#description-out').html(product);
2222
$('#description').css('height', $('#description-out').css('height'));
23-
});
2423

25-
$(".dtl").focus(function() {
26-
$(this).attr("type", "datetime-local");
24+
document.querySelectorAll(".dtl").forEach(function (e) {
25+
var split = e.getAttribute("value").split(" ");
26+
var date_split = split[0].split("-");
27+
var final = date_split[1] + "/" + date_split[2] + "/" + date_split[0] + " " + split[1];
28+
var parsed = new Date(final + " UTC").toString().split(" ");
29+
e.value = parsed[3] + "-" + getMonthFromString(parsed[1]) + "-" + parsed[2] + "T" + parsed[4];
30+
31+
function getMonthFromString(mon){
32+
var str = (new Date(Date.parse(mon +" 1, 2012")).getMonth() + 1).toString();
33+
return str.length == 2 ? str : "0" + str;
34+
}
35+
});
2736
});
2837

2938
$('#description').bind('input propertychange', function() {

0 commit comments

Comments
 (0)