-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this 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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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)
As an idea for the future: |
|
||
const { countryCode, center } = useFeatureContext().feature; | ||
|
||
const openingHours = parseOpeningHours(v, center[0], center[0], { |
There was a problem hiding this comment.
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?
@Dlurak lets merge this PR and feel free to implement this in a followup. It would be very much welcomed :-) |
# Conflicts: # package.json # yarn.lock
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.