Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TheOriginalSoni opened this issue Feb 19, 2024 · 6 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@TheOriginalSoni
Copy link
Collaborator

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)

  • Find out what the timezone expected is -> Switch to UTC if needed
  • Add an example for start and end date (and time, if it's supported)
  • If possible, add a "Calender" looking scrolling/pop up thing to select date/time instead of typing it.
@TheOriginalSoni TheOriginalSoni added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Feb 19, 2024
@lavaloid
Copy link
Collaborator

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

@madjaqk
Copy link
Contributor

madjaqk commented Feb 19, 2024

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
Copy link
Contributor

madjaqk commented Feb 20, 2024

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
Copy link
Contributor

madjaqk commented Feb 20, 2024

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

@madjaqk
Copy link
Contributor

madjaqk commented Feb 20, 2024

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
Copy link
Collaborator Author

TheOriginalSoni commented Feb 20, 2024

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.

madjaqk added a commit to madjaqk/myus that referenced this issue Mar 7, 2024
… a calendar datepicker on modern browsers) for hunt start/end times
madjaqk added a commit to madjaqk/myus that referenced this issue Mar 8, 2024
… a calendar datepicker on modern browsers) for hunt start/end times
TheOriginalSoni added a commit that referenced this issue Apr 24, 2024
#39: Use datetime-local inputs for hunt start/end times
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants