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

Implement a new library for opening hours #330

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Dlurak
Copy link
Contributor

@Dlurak Dlurak commented May 15, 2024

As it was discussed in #321 this pr introduces the opening hours library.
The problem with timezones isn't fixed with these changes.
As the library needs not only coordinates and a country but also a state to give accurate results for holidays the lib throws for some opening hours. In those cases we fallback to the old parser.

Copy link

vercel bot commented May 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
osmapp ✅ Ready (Inspect) Visit Preview May 22, 2024 10:16am

Copy link
Owner

@zbycz zbycz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, works fine 👍 This is mergable as is. Please find some comments below.

We can merge it and do a followup later, or you can update this PR.

try {
return parseComplexOpeningHours(value);
} catch {
return parseSimpleOpeningHours(value);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you expect this exception more often? I would say we can discard the simple-opening-hours lib altogether. If there is an exception, just return null and log the exception to sentry.. what do you think?

If we do this it can also simplify the <OpeningHoursRenderer> component to tailor it exactly to the new lib needs.

d.toLocaleTimeString(undefined, { hour: 'numeric', minute: 'numeric' });

export const parseComplexOpeningHours = (value: string) => {
const oh = new OpeningHours(value);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add the feature.countryCode here? would it help to find the holidays?

You can get it by useFeatureContext() in <OpeningHoursRenderer>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though it wouldn't work without a state but I just checked and it works quite good with only the country and coordinates (which are used for sunsets)

@Dlurak
Copy link
Contributor Author

Dlurak commented May 21, 2024

As an idea for the future:
Apple maps has a label "Closes soon"/"Opens Soons". Something like that would be amazing for that project


const { countryCode, center } = useFeatureContext().feature;

const openingHours = parseOpeningHours(v, center[0], center[0], {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is probably a typo center[0], center[0], right?

To prevent mistakes like these, do you think you can change the signature of parseOpeningHours() to accept LonLat type instead of two parameters?

@zbycz
Copy link
Owner

zbycz commented May 22, 2024

As an idea for the future: Apple maps has a label "Closes soon"/"Opens Soons". Something like that would be amazing for that project

@Dlurak lets merge this PR and feel free to implement this in a followup. It would be very much welcomed :-)

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

Successfully merging this pull request may close these issues.

None yet

2 participants