Problem/Motivation
The function "formatDateMonth" in the file "DatGroupFormatter.php" does not work correctly when the event happens in the same month but NOT on the same day.
For example: An event that starts on the first of october and ends the day after, the results in a string are like this:
"vr 31202131 , 01 31202131 1945 tot 02, 01 31202131 2130" for a middle format or
"01 31202131 /10/2021 - 19:45 tot 02/10/2021 - 21:30" for a short format.
When the start- and endtime are in the same day, the result is:
"vr, 01/10/2021 - :1945 tot 2130"
"01/10/2021 - 19:45 tot 21:30"
To help me out, I made a patch that changes line 118 of that file to
" if ($start['month'] == $end['month']) {"
in stead of
" if (($start['month'] == $end['month']) && ($start['day'] == $end['day'])) {"
Could someone look into this, please?
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | patch6.patch | 2.66 KB | ericvl |
Comments
Comment #2
viappidu commentedHi Eric,
Sorry but I'm out sailing (my real job) and cannot look into code right away.
Anyway I have doubts on what you try to achieve. The code, as I intended, is supposed to give you a formatted date difference +1, eg 1/10 to 2/10 = 2 days (with different output formats), 1/10 to 1/10 = 1 day.
Pretty sure it works for different dates on same month (I think I can post you a screenshot of me using it that way)
But maybe I misunderstood your problem. Please try to explain again.
Ps if my memory works right the line you mention is there to cope with the optional end date in the date field. Might be wrong though...
Comment #3
viappidu commentedWait!
You are right!!
Was taking those screenshots from my website and I found out it's missing a day!!
Still think that part of code I added some time ago for the problem I mentioned though it's worth delve into it.
Please attach your patch here. Next week I should have some bad weather days so I might (might) get some time for it.
Comment #4
ericvl@viappidu
This is my patch to the file src/Plugin/Field/FieldFormatter/DateGroupFormatter.php to prevent that the code in the function "formatDateMonth" is called when the month is equal but the day is different:
This way, the function is only called if AND the month AND the day is equial of the starttime and the endtime.
This doesn't solves the problem in the function if the month is equal and the day is not equal e.g. first of october till the second of october but it is a method to circumvent the problem.
Greetings
Comment #5
ericvl@viappidu
Still a remark: I do not mean that the DiffFormatter is not working like you suggested in your first comment.
It is the groupformatter that doesn't work in some conditions.
Just to be sure you understand the issue.
Comment #6
ericvl@viappidu
Another remark:could it have perhaps something to do with the date notation?
Because the standard notation in the US is month/day/year and in Europe day/month/year.
Maybe a tip. I don't know.
Greetings
Comment #7
viappidu commentedYou tickling my curiosity, I'll try to cut an hour today to look at the issue...
(Cannot promise it though)
Comment #8
ericvl@viappidu
I found the reason of the error. Could you look into it?
The reason is the date separator. In my case, it is set to 'tot'. This is Dutch for 'to' in English.
All letters of 'tot' are used as format character to evaluate a date/time.
see https://www.php.net/manual/en/datetime.format.php
Both t's of 'tot' are evaluated to 31 as beeing the number of days in october and
the 'o' of 'tot' is evaluated to 2021 as beeing the year.
So I get twice the string '31202131' added in the result.
Greetings
Eric
Comment #9
ericvl@viappidu
Because I don't hear from you now for a few weeks, I tried to make a patch myself. It is include in this comment. Could you try this out and give me a response if it works for you?
At least, it works here now.
Greetibgs
Eric
Comment #10
viappidu commented@ericvl
just 4 years to answer you...
I never really looked at your issue as I was supposed.
I apologize
Are you still using this module?
I think it might be "slightly" obsolete by now and even I stopped using it a while ago. I am not even sure I still have a working installation where to test it...
Comment #11
ericvlHello,
No, I don't use this module anymore. I'm using drupal/daterange_compact now that has the same features.
Anyway, thanks for answerring.
Greetings
Eric