Comments (2)
Indeed, I can reproduce. I see the timezone feature was introduced for isOpenAt
#16, so only for the input. At this moment the library had no nextOpen
/ nextClose
method (no date to output).
I will investigate if we can fix it without causing breaking changes for users who might have a different usage.
Honestly I'm not keen on this timezone feature being embedded directly in spatie/opening-hours, you can get basically the same by just calling ->setTimezone()
on input/output and would have a greater and less ambiguous control this way and give OpeningHours
only the responsibility to check the times while ensuring the date timezones match the times of the definition:
$openingHours = \Spatie\OpeningHours\OpeningHours::create([
'monday' => ['09:00-12:00', '13:00-18:00'],
]); // Don't pass any timezone
function nextOpen(DateTimeImmutable $date): DateTimeImmutable {
global $openingHours;
$timezone = $date->getTimezone();
return $openingHours
->nextOpen($date->setTimezone(new DateTimeZone('America/New_York')))
->setTimezone($timezone); // Set back original timezone
}
$nextOpen = nextOpen(new DateTimeImmutable('2022-07-24 20:00 UTC'));
Basically you could even have a UTC input, opening-hours for a business in New York and let's say a remote user in Oslo:
$systemTimezone = 'UTC'; // Should always be UTC anyway :p
$businessSchedule = [
'monday' => ['09:00-12:00', '13:00-18:00'],
];
$businessTimezone = 'America/New_York'; // The one to use to read the schedule above
$userTimezone = 'Europe/Oslo'; // Coming from the browser
$openingHours = \Spatie\OpeningHours\OpeningHours::create($businessSchedule); // Don't pass any timezone
$now = new \DateTimeImmutable('now', new \DateTimeZone($systemTimezone));
$nexOpen = $openingHours->nextOpen($date->setTimezone(new \DateTimeZone($businessTimezone)));
$nextOpenForUser = $nextOpen->setTimezone(new \DateTimeZone($userTimezone));
echo 'You can call us after ' . $nextOpenForUser->format('H:i') . ' (local time)';
This last case makes me think using the same timezone for input and output would not actually be generally wanted, so I wonder if the implementation of the timezone for nextOpen
/ nextClose
method should only transform the input or also change back to original timezone the output.
from opening-hours.
Published in 2.12.0
You'll find some documentation about it on https://github.com/spatie/opening-hours#openinghourscreatearray-data-timezone--null-toutputtimezone--null-spatieopeninghoursopeninghours
from opening-hours.
Related Issues (20)
- several advanced features HOT 4
- Github URL update HOT 2
- [Question/Feature Request] How to get all days of the current week including days resulting from exceptions? HOT 3
- [Bug] nextOpen calculates the wrong date for a regular day with exceptions HOT 3
- timezone is set on passed object when getting hours for a specific date HOT 2
- Free time slots during the day ? HOT 1
- Timezone not working in currentOpenRange HOT 2
- I want to add schedule for specific date HOT 1
- Locale? HOT 1
- GitHub repository link not working HOT 2
- Support for holidays HOT 5
- Overflow support does not seem to work for createAndMergeOverlappingRanges HOT 2
- diffInOpenMinutes() does not work if only one day is configured as open HOT 6
- Date period in exceptions or start and end date for a set of days of the week in regular time HOT 4
- Exceptions with date ranges HOT 5
- [Feature request] createFromStructuredData method
- How to destroy OpeningHours object or update it ? HOT 1
- How to create an exception using datetime with seconds HOT 2
- Adding seconds precision to exceptions HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opening-hours.