Closed tn3rb closed 1 year ago
Issue successfully reproduced locally, will proceed to work on the bug fix
@tn3rb In the process of this bug fix, I will make this field required
Because currently, if you omit this field, but specify time, e.g. 1.5 hours
, nothing will happen i.e. Submit
button works without asking for that earlier
/later
but nothing actually happens to time. Not great UX, imho.
Summary of my understanding of GraphQL implementation on EE:
eventEspressoData
eventEspressoData
following DDD paradigmprintDataNode()
It looks like bug is caused by this utility function
@tn3rb bug happens for both operations, earlier
and later
so I'll be fixing both
Further inspection of the source code reveals the following
The functions are not isomorphic even though date-fns supports subtraction function, e.g. subHours. Perhaps it is worthwhile to make it so.
Both functions use the same rounding logic which causes the bug:
Positive decimals will be rounded using Math.floor, decimals less than zero will be rounded using Math.ceil.
Due to non-accurate representation of floating numbers in JS, I'll be using the following logic
5 % 1; // 0
or 5.23 % 1; // 0.23000000000000043
Function add
is used only by misc.ts
so scope for change is minimal but adjustment of unit tests might be necessary
Same goes for sub
function which is only used by misc.ts
Inspecting unit tests suggest that ability to support fractions was never intended
Apparently, the value of 0.5
is not supported
Edit: when trying to set value of 0.5
the warning above is shown and the value is changed to 1
TODOs
0.5
value on input fieldEdit: TODO for field validation is now tracked via #1196
thank you for the thorough description of the issue 🙇🏻
re: earlier/later
input
I will make this field required
is/was there a default set in the submit handler for that functionality?
ie: if the default was later
then maybe we can simply set that as the default for the input, then remove the null
option, so that the input will always have a value
There is no default currently. When editor loads, it looks like this:
We could set it to later
by default but that might lead to some users overlooking it and changing event to a wrong time.
Using simple console.log
I can see that function receives a Date
object for its argument date
After quick chat with @tn3rb on Slack, it became obvious that support for floats leads to not-so-trivial rounding rules. For example, if shifting date by 5.23
days, how do you round that? Do you round it as 5 days 6 hours or as 5 days, 5 hours, 31 minutes, 12 seconds? While technically feasible, it will require time to write this logic, write unit tests, do the actual testing, etc. From a business point of view, it is not entirely clear how valuable it is to support ability to shift date by 5.23
so instead a different approach will be taken. Support for floats will be removed and each unit will be presented as a standalone field. Wireframe follows:
After further code review, I have decided to finish the feature since it was actually 80% complete. The logic for calculating time is as follows:
Date
object using date-fns
function
steps to reproduce
1.5
hours
later