Skip to content
Snippets Groups Projects
Commit a16c3dff authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

V1.3.4: Fix all time variables to use the timezone configured for WordPress

parent 6e53cb95
No related branches found
No related tags found
No related merge requests found
......@@ -226,18 +226,25 @@ class OrdernumberHelper {
}
return self::randomString ($alphabet, $len);
}
public function getDateTime($utime) {
$time = new DateTime();
$time->setTimestamp($utime);
return $time;
}
public function setupDateTimeReplacements (&$reps, $details, $nrtype) {
$utime = microtime(true);
$reps["[year]"] = date ("Y", $utime);
$reps["[year2]"] = date ("y", $utime);
$reps["[month]"] = date("m", $utime);
$reps["[day]"] = date("d", $utime);
$reps["[hour]"] = date("H", $utime);
$reps["[hour12]"] = date("h", $utime);
$reps["[ampm]"] = date("a", $utime);
$reps["[minute]"] = date("i", $utime);
$reps["[second]"] = date("s", $utime);
$time = $this->getDateTime($utime);
$reps["[year]"] = $time->format ("Y");
$reps["[year2]"] = $time->format ("y");
$reps["[month]"] = $time->format("m");
$reps["[day]"] = $time->format("d");
$reps["[hour]"] = $time->format("H");
$reps["[hour12]"] = $time->format("h");
$reps["[ampm]"] = $time->format("a");
$reps["[minute]"] = $time->format("i");
$reps["[second]"] = $time->format("s");
$milliseconds = (int)(1000*($utime - (int)$utime));
$millisecondsstring = sprintf('%03d', $milliseconds);
$reps["[decisecond]"] = $millisecondsstring[0];
......
......@@ -12,6 +12,44 @@ if ( !defined( 'ABSPATH' ) ) {
if (!class_exists( 'OrdernumberHelper' ))
require_once (dirname(__FILE__) . '/library/ordernumber_helper.php');
/**
* Returns the timezone string for a site, even if it's set to a UTC offset
*
* Adapted from http://www.php.net/manual/en/function.timezone-name-from-abbr.php#89155
*
* @return string valid PHP timezone string
*/
function wp_get_timezone_string() {
// if site timezone string exists, return it
if ( $timezone = get_option( 'timezone_string' ) )
return $timezone;
// get UTC offset, if it isn't set then return UTC
if ( 0 === ( $utc_offset = get_option( 'gmt_offset', 0 ) ) )
return 'UTC';
// adjust UTC offset from hours to seconds
$utc_offset *= 3600;
// attempt to guess the timezone string from the UTC offset
if ( $timezone = timezone_name_from_abbr( '', $utc_offset, 0 ) ) {
return $timezone;
}
// last try, guess timezone string manually
$is_dst = date( 'I' );
foreach ( timezone_abbreviations_list() as $abbr ) {
foreach ( $abbr as $city ) {
if ( $city['dst'] == $is_dst && $city['offset'] == $utc_offset )
return $city['timezone_id'];
}
}
// fallback to UTC
return 'UTC';
}
class OrdernumberHelperWooCommerce extends OrdernumberHelper {
public static $ordernumber_counter_prefix = '_ordernumber_counter_';
......@@ -31,6 +69,14 @@ class OrdernumberHelperWooCommerce extends OrdernumberHelper {
}
return $helper;
}
public function getDateTime($utime) {
$time = new DateTime();
$time->setTimestamp($utime);
$time->setTimezone(new DateTimeZone(wp_get_timezone_string()));
return $time;
}
/**
* HELPER FUNCTIONS, WooCommerce-specific
......
......@@ -78,6 +78,9 @@ The Advanced Ordernumbers for WooCommerce plugin supports some invoicing plugins
== Changelog ==
= 1.3.4 =
* Fix all time variables to use the timezone configured for WordPress
= 1.3.3 =
* Fix issue with order tracking (which assumed order IDs were entered)
* Add filter woocommerce_order_id_from_number(ordernumber) that returns the order ID given the order number
......
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment