GithubHelp home page GithubHelp logo

Comments (2)

zKoz210 avatar zKoz210 commented on June 2, 2024 1

@kylekatarnls thanks, this is an impressive library

from opening-hours.

kylekatarnls avatar kylekatarnls commented on June 2, 2024

The timezone in format() will have effect if format contains a timezone information (T, P, o, etc.)

$currentRange->end() is a Time instance, it has only the numbers as passed in the array. It's non-dated info (e.g. just like a picture of a wall clock, it's not giving the day nor the timezone)

What you're looking for is more likely nextClose() which is returning as a DateTime object the next moment when the current open period ends so with full context and related to the passed date:

$schedule = \Spatie\OpeningHours\OpeningHours::create([
    'monday'     => ['09:00-12:00', '13:00-18:00'],
    'tuesday'    => ['09:00-12:00', '12:30-18:00'],
    'wednesday'  => ['09:00-12:00'],
    'thursday'   => ['09:00-12:00', '13:00-18:00'],
    'friday'     => ['09:00-12:00', '13:00-20:00'],
    'saturday'   => ['09:00-12:00', '13:00-16:00'],
    'sunday'     => [],
], 'Europe/Moscow', 'America/New_York');

$nowInNewYork = new DateTimeImmutable('2022-08-23 10:45 America/New_York');
$nowInMoscow = $nowInNewYork->setTimezone(new DateTimeZone('Europe/Moscow'));

if ($schedule->isOpenAt($nowInMoscow)) {
    echo $schedule->nextClose($nowInMoscow)->format('H:i') . "\n";
    // More context to make it clear:
    echo $schedule->nextClose($nowInMoscow)->format('Y-m-d H:i e') . "\n";
    // Double-check by switching back to Europe/Moscow timezone
    echo $schedule->nextClose($nowInMoscow)->setTimezone(new DateTimeZone('Europe/Moscow'))->format('Y-m-d H:i e') . "\n";
}

from opening-hours.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.