Fix countdown back bug

This commit is contained in:
cuom1999 2021-12-10 16:36:55 -06:00
parent 16974ab3dc
commit fea5e46cda
7 changed files with 20 additions and 19 deletions

View file

@ -24,5 +24,7 @@ def seconds(timedelta):
@registry.filter
@registry.render_with('time-remaining-fragment.html')
def as_countdown(timedelta):
return {'countdown': timedelta}
def as_countdown(time):
time_now = datetime.datetime.now(datetime.timezone.utc)
initial = abs(time - time_now)
return {'countdown': time, 'initial': initial}

View file

@ -183,8 +183,7 @@ if (!Date.now) {
}
function count_down(label) {
var initial = parseInt(label.attr('data-secs'));
var start = Date.now();
var end_time = new Date(label.attr('data-secs'));
function format(num) {
var s = "0" + num;
@ -192,7 +191,7 @@ function count_down(label) {
}
var timer = setInterval(function () {
var time = Math.round(initial - (Date.now() - start) / 1000);
var time = Math.round((end_time - Date.now()) / 1000);
if (time <= 0) {
clearInterval(timer);
setTimeout(function() {

View file

@ -289,7 +289,7 @@
{% if request.participation.spectate %}
{{ _('spectating') }}
{% elif request.participation.end_time %}
<div id="contest-time-remaining" data-secs="{{ request.participation.time_remaining|seconds }}">
<div id="contest-time-remaining" data-secs="{{request.participation.end_time}}">
{{ request.participation.time_remaining|timedelta("localized") }}
</div>
{% else %}

View file

@ -153,7 +153,7 @@
<a href="{{ url('contest_view', contest.key) }}">{{ contest.name }}</a>
</div>
<div class="time">
{{ _('Ends in %(countdown)s.', countdown=contest.time_before_end|as_countdown) }}
{{ _('Ends in %(countdown)s.', countdown=contest.end_time|as_countdown) }}
</div>
</div>
{% endfor %}
@ -171,7 +171,7 @@
<a href="{{ url('contest_view', contest.key) }}">{{ contest.name }}</a>
</div>
<div class="time">
{{ _('Starting in %(countdown)s.', countdown=contest.time_before_start|as_countdown) }}
{{ _('Starting in %(countdown)s.', countdown=contest.start_time|as_countdown) }}
</div>
</div>
{% endfor %}

View file

@ -30,26 +30,26 @@
{{- contest.start_time|utc|date('Y-m-d\TH:i:s') }}" class="date">
{%- if contest.is_in_contest(request.user) and not request.participation.live -%}
{% if request.participation.spectate %}
{{- _('Spectating, contest ends in %(countdown)s.', countdown=contest.time_before_end|as_countdown) -}}
{{- _('Spectating, contest ends in %(countdown)s.', countdown=contest.end_time|as_countdown) -}}
{% elif request.participation.end_time %}
{{- _('Participating virtually, %(countdown)s remaining.', countdown=request.participation.time_remaining|as_countdown) -}}
{{- _('Participating virtually, %(countdown)s remaining.', countdown=request.participation.end_time|as_countdown) -}}
{% else %}
{{- _('Participating virtually.') -}}
{% endif %}
{%- else -%}
{% if contest.start_time > now %}
{{- _('Starting in %(countdown)s', countdown=contest.time_before_start|as_countdown) -}}
{{- _('Starting in %(countdown)s', countdown=contest.start_time|as_countdown) -}}
{% elif contest.end_time < now %}
{{- _('Contest is over.') -}}
{% else %}
{%- if has_joined -%}
{% if live_participation.ended %}
{{- _('Your time is up! Contest ends in %(countdown)s.', countdown=contest.time_before_end|as_countdown) -}}
{{- _('Your time is up! Contest ends in %(countdown)s.', countdown=contest.end_time|as_countdown) -}}
{% else %}
{{- _('You have %(countdown)s remaining.', countdown=live_participation.time_remaining|as_countdown) -}}
{{- _('You have %(countdown)s remaining.', countdown=live_participation.end_time|as_countdown) -}}
{% endif %}
{%- else -%}
{{ _('Contest ends in %(countdown)s.', countdown=contest.time_before_end|as_countdown) }}
{{ _('Contest ends in %(countdown)s.', countdown=contest.end_time|as_countdown) }}
{%- endif -%}
{% endif %}
{%- endif -%}

View file

@ -252,7 +252,7 @@
{% if contest.time_limit %}
<span class="time">{{ _('Window ends in %(countdown)s', countdown=participation.time_remaining|as_countdown)}}
{% elif contest.time_before_end %}
<span class="time">{{ _('Ends in %(countdown)s', countdown=contest.time_before_end|as_countdown) }}</span>
<span class="time">{{ _('Ends in %(countdown)s', countdown=contest.end_time|as_countdown) }}</span>
{% endif %}
{{ time_left(contest) }}
{% endif %}
@ -301,7 +301,7 @@
{% if contest.start_time %}
<br>
{% if contest.time_before_end %}
<span class="time">{{ _('Ends in %(countdown)s', countdown=contest.time_before_end|as_countdown) }}</span>
<span class="time">{{ _('Ends in %(countdown)s', countdown=contest.end_time|as_countdown) }}</span>
{% endif %}
{{ time_left(contest) }}
{% endif %}
@ -336,7 +336,7 @@
{% if contest.start_time %}
<br>
{% if contest.time_before_start %}
<span class="time">{{ _('Starting in %(countdown)s.', countdown=contest.time_before_start|as_countdown) }}</span>
<span class="time">{{ _('Starting in %(countdown)s.', countdown=contest.start_time|as_countdown) }}</span>
{% endif %}
{{ time_left(contest) }}
{% endif %}

View file

@ -1,3 +1,3 @@
<span data-secs="{{ countdown|seconds }}" class="time-remaining">
{{ countdown|timedelta("localized") }}
<span data-secs="{{ countdown }}" class="time-remaining">
{{ initial|timedelta("localized") }}
</span>