PuzzleTechHub / myus

A public hassle free puzzlehunt hosting tool
https://www.puzzlehuntmy.us/
MIT License
1 stars 9 forks source link

Add calender or examples for start-date/time and end-date/time #39

Open TheOriginalSoni opened 9 months ago

TheOriginalSoni commented 9 months ago

Right now the hunt creation option just takes a start-date (and maybe also time). What format is not known (probably MM/DD/YYYY ugh)

lavaloid commented 9 months ago

<input type="datetime-local" /> has a native calendar support: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local

madjaqk commented 9 months ago

First, per Django docs, by default the DateTimeField will accept ISO-8601 strings, so YYYY-MM-DD (and optional time). DateTimeField takes an optional input_formats argument to list additional valid formats.

I haven't used it, but I think SplitDateTimeWidget will do what you want. Update the HuntForm definition in views.py to include the line start_time = forms.DateTimeField(widget=forms.SplitDateTimeWidget)?

I have no idea how any of this handles time zones, though.

There should also be third-party packages with date time picker widgets that are either more attractive or more user-friendly, but all I've found in minutes of Googling is stuff that hasn't been touched in years and broke several Django major versions ago.

madjaqk commented 9 months ago

The default SplitDateTimeWidget doesn't seem to be good enough—it just produces two text fields with appropriate validations but no calendar pop-up or similar.

image image

Here's the generated HTML:

  <tr>
    <th><label>Start time:</label></th>
    <td>
      <input type="text" name="start_time_0" id="id_start_time_0"><input type="text" name="start_time_1" id="id_start_time_1">
    </td>
  </tr>
  <tr>
    <th><label>End time:</label></th>
    <td>
      <input type="text" name="end_time_0" id="id_end_time_0"><input type="text" name="end_time_1" id="id_end_time_1">
    </td>
  </tr>
madjaqk commented 9 months ago

The second error is odd, because the field is marked as non-required in the form definition, but whatever.

madjaqk commented 9 months ago
class HuntForm(forms.ModelForm):
    start_time = forms.DateTimeField(widget=forms.DateTimeInput(attrs={"type": "datetime-local"}), required=False)

...makes the input display correctly, but it looks like the time comes through as UTC, not the user's local time. Also, this StackOverflow answer suggests this will break once editing existing hunts is implemented.

The Django docs on time zones seem they like they should be able to help, but I don't know. It's possible the only solution is to ask for the user to specify the time zone when selecting the date/time, in which case the above isn't going to be sufficient.

TheOriginalSoni commented 9 months ago

I think outputting all times in UTC or making everyone input things in UTC is acceptable enough. Timezones are a complicated mess and this feels like an easy way out for now.

It's the standard timezone and will be easier to note "All timezones are in UTC" and punt implementing clever date-time conversions for the future. I'm personally okay if we never implement it either.