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

Support for all day events #11

Open
iantearle opened this issue Apr 25, 2023 · 5 comments
Open

Support for all day events #11

iantearle opened this issue Apr 25, 2023 · 5 comments

Comments

@iantearle
Copy link

iantearle commented Apr 25, 2023

Would it be possible to support dates where the times are set to 00:00 to 23:59 - this seems to be a popular setting to display an all day event.

It would be nice to have the option to pass in a string to read "all day"

@flack
Copy link
Owner

flack commented Apr 27, 2023

Hi!

I'm not exactly sure what it is you want to show, could you give a more concrete example?

The thing about showing a text like "all day" is also that that would need localization, so we'd need to add some translation framework (but well, if it's only one string I suppose it could be added to the Provider classes)

@iantearle
Copy link
Author

Sure, Sorry;
Given the values:
Start date: 1 April 2023 00:00
End date: 1 April 2023 23:59

Currently the event would appear as "April, 1, 2023 - 00:00 - 23:59"

echo $ranger->format('2023-04-01 00:00', '2023-04-01 23:59');
// April 1, 2023, between 00:00 AM and 11:59 PM

It would be nice to have it read as "April, 1, 2023 - All day"

// April 1, 2023, All day

@flack
Copy link
Owner

flack commented Apr 27, 2023

Ok, thx, I think I get it now. What would

echo $ranger->format('2023-04-01 00:00', '2023-04-02 23:59');

look like? Would that be Apr 1, 2023, 12:00 AM – Apr 2, 2023, 11:59 PM or Apr 1–2, 2023 - All day?

Also, what happens if you use

$ranger->setTimeType(IntlDateFormatter::NONE)

(which is the default setting), does this still show the All Day, or would it just show the date(s)?

@iantearle
Copy link
Author

I think if the event is over multiple days but the timing is 00:00-23:59 it should still say all day, but if that timing deviates it should stipulate the time.

Setting NONE would also hide the All day string.

Incidentally, I don't think it's possible, correct me if I'm wrong, but this may need an additional ticket, but I couldn't work out how to pass a pattern() to IntlDateFormatter?

@flack
Copy link
Owner

flack commented Apr 28, 2023

ok, so roughly speaking, the code would look something like this:

function allday($start, $end)
{
    $ranger = new Ranger('en_US');
    $ranger->setTimeType(IntlDateFormatter::MEDIUM);
    $suffix = '';
    if (str_ends_with($start, ' 00:00') && str_ends_with($end, ' 23:59')) {
        $ranger->setTimeType(IntlDateFormatter::NONE);
        $start = explode(' ', $start)[0];
        $end = explode(' ', $end)[0];
        $suffix = ', All day';
    }
    return $ranger->format($start, $end) . $suffix;
}

echo allday('2023-04-01 00:00', '2023-04-02 23:59');

right?

ofc this example code only works with exactly one input format and doesn't account for time format settings. I wonder how to best go about integrating that. Maybe I should change some functions from private to protected, then this could be easily implemented in a Ranger subclass. Another option might by to add FormatPreprocessor / FormatPostprocessor interfaces/hooks or similar so that users cann supply ther own custom logic, not sure how messy that would be..

For the pattern, yes, that is currently not supported. I remember vaguely looking into it at some point and it seemed complicated to do, but I don't remember why exactly. Skimming the code currently it actually looks relatively simple (but I'm probably missing something). In any case, that would be a separate ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants