Psytanium Posted April 6, 2016 Posted April 6, 2016 Hi, What should I modify to set the timestamp or timezone of my store, so the orders date and time and correct ? I'm using osc 2.3.4 Thanks
MrPhil Posted April 6, 2016 Posted April 6, 2016 If you want your calendar and clock to display correctly when formatted in PHP code, you can do a couple of things: In your php.ini file, add date.timezone = 'America/New_York' OR In application_top.php files, add date_default_timezone_set('America/New_York'); Of course, change your timezone (America/New_York) to whatever is appropriate for your store. See http://us3.php.net/manual/en/timezones.php . This assumes you're running PHP 5.1 or higher. I'm not sure that the date.timezone method will be accepted much longer (some servers will give a warning message). This assumes that dates (timestamps) are generated using the standard PHP/Unix UTC timestamp counter. If it's using a timestamp value generated by the database, it's possible that it will reflect not UTC but your server's timezone. In that case, you could either add/subtract 3600 seconds per hour, or use a different timezone to correct the value (try to get one with matching DST rules). You may have some experimentation ahead of you.
Jack_mcs Posted April 6, 2016 Posted April 6, 2016 @@Psytanium If the time of your server is different than your local time, you will need to install this addon. You may still need the change Phil mentioned but that won't affect your database. Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
Psytanium Posted April 10, 2016 Author Posted April 10, 2016 I changed the server time, now the orders time and date work correct, but cannot get this php code to detect and output if store is currently Closed or Opened. <?php /** * Based on the following business hours: * (Note : I setup the hours for each day if they carry-over) * everyday is open from 09:00 AM - 12:00 AM * Sun/Sat open extra from 12:00 AM - 01:00 AM */ $storeSchedule = [ 'Sun' => ['01:00 AM' => '01:00 AM'], 'Mon' => ['01:00 AM' => '11:00 AM'], 'Tue' => ['01:00 AM' => '11:00 AM'], 'Wed' => ['01:00 AM' => '11:00 AM'], 'Thu' => ['01:00 AM' => '11:00 AM'], 'Fri' => ['01:00 AM' => '11:00 AM'], 'Sat' => ['01:00 AM' => '09:00 AM'], ]; // current OR user supplied UNIX timestamp $timestamp = time(); // default status $status = 'Closed <span class="fa fa-power-off" style="color:#9c0000; font-size:14px; margin:0 5px;"></span>'; // get current time object $currentTime = (new DateTime())->setTimestamp($timestamp); // loop through time ranges for current day foreach ($storeSchedule[date('D', $timestamp)] as $startTime => $endTime) { // create time objects from start/end times $startTime = DateTime::createFromFormat('h:i A', $startTime); $endTime = DateTime::createFromFormat('h:i A', $endTime); // check if current time is within a range if (($startTime < $currentTime) && ($currentTime < $endTime)) { $status = 'Opened <span class="fa fa-power-off" style="font-size:14px; margin:0 5px; color:#8ecd58;"></span> +961 9 853 927 <strong>or</strong> +961 9 853 008'; break; } } echo "Now $status"; ?> The PHP code is working but with some hours of difference. I don't know if the problem comes from the code, osc settings or server settings.
MrPhil Posted April 10, 2016 Posted April 10, 2016 Your new question is a totally different topic. Next time, please start a new thread for it in the Programming section. Have you dumped the three time values (start, current, and end time) to see if 1) they are correct values, and 2) are the expected timezone? Are these PHP timestamps (integer seconds count from 1/1/1970)? That's the (integer) value you should be comparing, not formatted times. Note that a raw timestamp is UTC, not the local time, so you may want to convert your start and end times to UTC using a date string-to-timestamp call. That can be jiggered to allow for being open past midnight, too. Your hours look very odd (they don't match the comment)... 12AM is midnight, not noon, right? You're open 10 hours a day on weekdays? Is your server many timezones away from you, or you're an insomniac? Wasn't the point of the whole exercise to be able to use local time? Is your use of timezone setting now giving the correct local time, including any DST? What does 1AM-to-1AM mean... is the store closed? What if someone accesses the store at exactly 1:00 AM -- will they find it open? Finally, I think it would be clearer in your store hours array to use 'start' => '1:00 AM' and 'end' => '11:00 AM'. I hope all my questions allow a lightbulb to go on over your head and help you figure out what went wrong.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.