Skip to content

Commit 066de1e

Browse files
committed
When editing interim meeting request show duration as HH:MM instead of HH:MM:SS. Fixes ietf-tools#2226. Commit ready for merge.
- Legacy-Id: 13337
1 parent 7542e8d commit 066de1e

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

ietf/meeting/forms.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import codecs
3+
import datetime
34

45
from django import forms
56
from django.db.models import Q
@@ -33,6 +34,32 @@ class GroupModelChoiceField(forms.ModelChoiceField):
3334
def label_from_instance(self, obj):
3435
return obj.acronym
3536

37+
class CustomDurationField(DurationField):
38+
'''Custom DurationField to display as HH:MM (no seconds)'''
39+
def prepare_value(self, value):
40+
if isinstance(value, datetime.timedelta):
41+
return duration_string(value)
42+
return value
43+
44+
def duration_string(duration):
45+
'''Custom duration_string to return HH:MM (no seconds)'''
46+
days = duration.days
47+
seconds = duration.seconds
48+
microseconds = duration.microseconds
49+
50+
minutes = seconds // 60
51+
seconds = seconds % 60
52+
53+
hours = minutes // 60
54+
minutes = minutes % 60
55+
56+
string = '{:02d}:{:02d}'.format(hours, minutes)
57+
if days:
58+
string = '{} '.format(days) + string
59+
if microseconds:
60+
string += '.{:06d}'.format(microseconds)
61+
62+
return string
3663
# -------------------------------------------------
3764
# Forms
3865
# -------------------------------------------------
@@ -160,7 +187,7 @@ def save(self, *args, **kwargs):
160187
class InterimSessionModelForm(forms.ModelForm):
161188
date = DatepickerDateField(date_format="yyyy-mm-dd", picker_settings={"autoclose": "1"}, label='Date', required=False)
162189
time = forms.TimeField(widget=forms.TimeInput(format='%H:%M'), required=True)
163-
requested_duration = DurationField(required=True)
190+
requested_duration = CustomDurationField(required=True)
164191
end_time = forms.TimeField(required=False)
165192
remote_instructions = forms.CharField(max_length=1024, required=True)
166193
agenda = forms.CharField(required=False, widget=forms.Textarea, strip=False)

0 commit comments

Comments
 (0)