fspc / Yellow-Bike-Database

Yellow Bike Project Hours and Transaction Database for Community Bike Shops
GNU General Public License v3.0
7 stars 1 forks source link

Add test for mysql server time zone support #34

Closed fspc closed 7 years ago

fspc commented 7 years ago

Since the correction of Issue #25, it would be a good idea to test whether the mysql server provides time zone support. There is already a great example of how to do that at line 14 in json/shop.php (needs to be committed, deleted in the past) for the still unexposed "interface to shop opening/closing to provide web interface and/or apps with a json web service" feature:

        $query = "SELECT @@global.time_zone as gt;";
        $sql = mysql_query($query, $YBDB) or die(mysql_error());
        $timezone = mysql_fetch_assoc($sql);
        if ($timezone['gt'] === "SYSTEM") {

            $dest_tz = new DateTimeZone(TIMEZONE);
            $dt = new DateTime(date('Y-m-d H:i:s') . " " . exec('date +%Z'));
            $dt->setTimeZone($dest_tz);
            $current_date = $dt->format('Y-m-d');   

        //'use global timezone from mysql rather than system timezone'  
        } else {                

            $dest_tz = new DateTimeZone(TIMEZONE);
            $dt = new DateTime(date('Y-m-d') . " " . $timezone['gt']); 
            $dt->setTimeZone($dest_tz);
            $current_date = $dt->format('Y-m-d');               

        }

        // check sign_out button
        // also need to check sign_in_button
        $query = "SELECT shop_id, time_in, time_out FROM shop_hours " . 
                    "WHERE shop_id IN (SELECT MAX(shop_id) FROM shops WHERE date='" . $current_date . "');";
        $sql = mysql_query($query, $YBDB) or die(mysql_error());
        while ( $result = mysql_fetch_assoc($sql) ) {
            // shop is open
            if ( $result['time_out'] === '0000-00-00 00:00:00' ) {
                $open = true;   
                break;
            }       
        }