Problem/Motivation
If you have a date range configured to only store dates, and you use the daterange_duration widget, you get sort of confusing UI behavior.
A) If you define a date with the start as '2020-08-18' and say you want the duration to be '1 day', the widget (which was written to assume datetime, not just date) thinks the duration is an offset, and saves the end time as 2020-08-19. This isn't what users (the non-nerds who don't count from 0) expect. ;) If I say "1 day" I'd expect the start and end on the same day. If I say "2 days", starting today, I'd expect it to end tomorrow. Etc.
B) The widget settings still let you pick a duration granularity less than 1 day, which makes no sense for fields of this type.
Steps to reproduce
- Install core's datetime_range module.
- Install datetime_extras.
- Configure a node type with a daterange field, and select 'Date only' for the field storage setting.
- Configure the node type's form display mode to use the 'Daterange duration' widget.
- Create a node of this type and experience the weirdness.
Proposed resolution
For date-only range fields:
A) Always remove 1 day from the specified duration when computing the end date. When computing the default value for the widget, always add a day. That way, we always treat the 'duration' as the quantity of days in the range, not an 'offset' from the 1st day.
B) Enforce that the duration granularity is 1-day minimum, hide hours, minutes + seconds from the widget settings.
Remaining tasks
- Do it.
- Add test coverage for date-only ranges.
- Upload patch.
- Reviews / refinements.
- RTBC.
- Commit.
User interface changes
UI makes more sense for date-only ranges, where the 'duration' is a quantity of days in the range, not an offset from the starting date.
API changes
TBD, hopefully none.
Data model changes
None. We're not storing anything differently, just tweaking the UI of the widget.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3165990-7.patch | 16.69 KB | dww |
| #7 | 3165990-7.test-only.patch | 5.53 KB | dww |
Issue fork datetime_extras-3165990
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
dwwThis solves (and tests) point A.
Working on point B next.
Comment #3
dwwNot sure what the bot's problem is there. :/ If you click through to Jenkins, it looks like things actually worked.
Fixing the CS bug, and trying again. /shrug
Comment #4
dwwThanks to @mixologic in Slack, it seems the "Build successful" result is from our drupalci.yml saying we're supposed to halt-on-fail for phpcs failures, and we've got that one line that doesn't pass. Trying again with that line fixed.
Meanwhile, this fixes point B about the settings form for date-only fields. It's quite yucky, since we really need different default settings values depending on datetime vs. date-only, but
defaultSettings()ispublic static. Alas. No tests for this part (yet).Comment #6
dwwWee, progress!
Let's try exactly #4 again with a fix to drupalci.yml to stop failing runs on phpcs troubles.
But let's also fix the CS problem. ;)
Comment #7
dwwOh right, except we can't fix that phpcs "bug" since it *needs* to be
/** @noRector */for that to work. See #3137619: Fix @noRector comments to actually workSo here's #6 without that change...
Comment #11
sickness29 commentedThanks @dww, merged
Comment #13
dwwFor anyone else coming here wondering what happened, this was committed to 8.x-1.x, but the commit message didn't follow any of our conventions so there's no issue NID in the history, and therefore, no link from this issue. But it's this one:
https://git.drupalcode.org/project/datetime_extras/-/commit/bd726657071c...
That commit is included in the 8.x-1.2 release. Phew. 😉