public function testHasTimezone() { $this->if($asserter = new sut($generator = new asserter\generator()))->exception(function () use($asserter) { $asserter->hasSize(rand(0, PHP_INT_MAX)); })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Instance of \\dateTime is undefined')->if($asserter->setWith($dateTime = new \DateTime('now', $timezone = new \DateTimezone('Europe/Paris'))))->then->exception(function () use(&$line, &$requiredTimezone, $asserter) { $line = __LINE__; $asserter->hasTimezone($requiredTimezone = new \DateTimezone('Europe/London')); })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Timezone is %s instead of %s'), $timezone->getName(), $requiredTimezone->getName()))->object($asserter->hasTimezone($dateTime->getTimezone()))->isIdenticalTo($asserter); }
/** * Returns {@see \DateTimezone} by timezone. * * @param string|\DateTimezone $timezone * @return \DateTimezone|null */ protected function calculateTimezone($timezone) { if (!isset($timezone)) { return null; } $key = $timezone instanceof \DateTimeZone ? $timezone->getName() : $timezone; // lazy loading if (!isset(static::$timezonesInstances[$key])) { static::$timezonesInstances[$key] = is_string($timezone) ? new \DateTimezone($timezone) : $timezone; } return static::$timezonesInstances[$key]; }
/** * Underscore (JS) templates for dialog windows. */ public function render_templates() { $data = $this->get_month_choices(); $description = __('Schedule your changes to publish (go live) at a future date.', 'customize-snapshots'); ?> <script type="text/html" id="tmpl-snapshot-preview-link"> <a href="#" target="frontend-preview" id="snapshot-preview-link" class="dashicons dashicons-welcome-view-site" title="<?php esc_attr_e('View on frontend', 'customize-snapshots'); ?> "> <span class="screen-reader-text"><?php esc_html_e('View on frontend', 'customize-snapshots'); ?> </span> </a> </script> <script type="text/html" id="tmpl-snapshot-schedule-button"> <a href="javascript:void(0)" id="snapshot-schedule-button" role="button" aria-controls="snapshot-schedule" aria-pressed="false" class="dashicons dashicons-calendar-alt"></a> </script> <script type="text/html" id="tmpl-snapshot-schedule"> <div id="snapshot-schedule"> <div class="snapshot-schedule-title"> <h3> <?php esc_html_e('Snapshot Scheduling', 'customize-snapshots'); ?> <span class="reset-time">(<a href="#" title="<?php esc_attr_e('Reset scheduled date to original or current date', 'customize-snapshots'); ?> "><?php esc_html_e('Reset', 'customize-snapshots'); ?> </a>)</span> </h3> <p class="snapshot-schedule-description"> <?php echo esc_html($description); ?> </p> <?php $edit_snapshot_text = __('Edit Snapshot', 'customize-snapshots'); ?> <a href="{{ data.editLink }}" class="dashicons dashicons-edit snapshot-edit-link" target="_blank" title="<?php echo esc_attr($edit_snapshot_text); ?> " aria-expanded="false"><span class="screen-reader-text"><?php echo esc_html($edit_snapshot_text); ?> </span></a> </div> <div class="snapshot-schedule-control date-inputs clear"> <label> <span class="screen-reader-text"><?php esc_html_e('Month', 'customize-snapshots'); ?> </span> <# _.defaults( data, <?php echo wp_json_encode($data); ?> ); data.input_id_post_date = 'input-' + String( Math.random() ); data.input_id_post_date_gmt = 'input-' + String( Math.random() ); #> <select id="{{ data.input_id }}" class="date-input month" data-date-input="month"> <# _.each( data.month_choices, function( choice ) { #> <# if ( _.isObject( choice ) && ! _.isUndefined( choice.text ) && ! _.isUndefined( choice.value ) ) { text = choice.text; value = choice.value; } #> <option value="{{ value }}" <# if (choice.value == data.month) { #> selected="selected" <# } #>> {{ text }} </option> <# } ); #> </select> </label> <label> <span class="screen-reader-text"><?php esc_html_e('Day', 'customize-snapshots'); ?> </span> <input type="number" size="2" maxlength="2" autocomplete="off" class="date-input day" data-date-input="day" min="1" max="31" value="{{ data.day }}" /> </label> <span class="time-special-char">,</span> <label> <span class="screen-reader-text"><?php esc_html_e('Year', 'customize-snapshots'); ?> </span> <input type="number" size="4" maxlength="4" autocomplete="off" class="date-input year" data-date-input="year" min="<?php echo esc_attr(date('Y')); ?> " value="{{ data.year }}" max="9999" /> </label> <span class="time-special-char">@</span> <label> <span class="screen-reader-text"><?php esc_html_e('Hour', 'customize-snapshots'); ?> </span> <input type="number" size="2" maxlength="2" autocomplete="off" class="date-input hour" data-date-input="hour" min="0" max="23" value="{{ data.hour }}" /> </label> <span class="time-special-char">:</span> <label> <span class="screen-reader-text"><?php esc_html_e('Minute', 'customize-snapshots'); ?> </span> <input type="number" size="2" maxlength="2" autocomplete="off" class="date-input minute" data-date-input="minute" min="0" max="59" value="{{ data.minute }}" /> </label> </div> <div class="timezone-info"> <span class="snapshot-scheduled-countdown" role="timer"></span> <?php $tz_string = get_option('timezone_string'); if ($tz_string) { $tz = new \DateTimezone($tz_string); $formatted_gmt_offset = $this->format_gmt_offset($tz->getOffset(new \DateTime()) / 3600); $tz_name = str_replace('_', ' ', $tz->getName()); /* translators: 1: timezone name, 2: gmt offset */ $timezone_description = sprintf(__('This site\'s dates are in the %1$s timezone (currently UTC%2$s).', 'customize-snapshots'), $tz_name, $formatted_gmt_offset); } else { $formatted_gmt_offset = $this->format_gmt_offset(get_option('gmt_offset')); /* translators: %s: gmt offset */ $timezone_description = sprintf(__('Dates are in UTC%s.', 'customize-snapshots'), $formatted_gmt_offset); } echo esc_html($timezone_description); ?> </div> </div> </script> <script id="tmpl-snapshot-scheduled-countdown" type="text/html"> <# if ( data.remainingTime < 2 * 60 ) { #> <?php esc_html_e('This is scheduled for publishing in about a minute.', 'customize-snapshots'); ?> <# } else if ( data.remainingTime < 60 * 60 ) { #> <?php /* translators: %s is a placeholder for the Underscore template var */ echo sprintf(esc_html__('This snapshot is scheduled for publishing in about %s minutes.', 'customize-snapshots'), '{{ Math.ceil( data.remainingTime / 60 ) }}'); ?> <# } else if ( data.remainingTime < 24 * 60 * 60 ) { #> <?php /* translators: %s is a placeholder for the Underscore template var */ echo sprintf(esc_html__('This snapshot is scheduled for publishing in about %s hours.', 'customize-snapshots'), '{{ Math.round( data.remainingTime / 60 / 60 * 10 ) / 10 }}'); ?> <# } else { #> <?php /* translators: %s is a placeholder for the Underscore template var */ echo sprintf(esc_html__('This snapshot is scheduled for publishing in about %s days.', 'customize-snapshots'), '{{ Math.round( data.remainingTime / 60 / 60 / 24 * 10 ) / 10 }}'); ?> <# } #> </script> <script type="text/html" id="tmpl-snapshot-save"> <button id="snapshot-save" class="button button-secondary"> {{ data.buttonText }} </button> </script> <script type="text/html" id="tmpl-snapshot-submit"> <button id="snapshot-submit" class="button button-primary"> {{ data.buttonText }} </button> </script> <script type="text/html" id="tmpl-snapshot-dialog-error"> <div id="snapshot-dialog-error" title="{{ data.title }}"> <p>{{ data.message }}</p> </div> </script> <?php }
class classWithToString { public function __toString() { return "Class A object"; } } class classWithoutToString { } // heredoc string $heredoc = <<<EOT hello world EOT; // add arrays $index_array = array(1, 2, 3); $assoc_array = array('one' => 1, 'two' => 2); // resource $file_handle = fopen(__FILE__, 'r'); //array of values to iterate over $inputs = array('int 0' => 0, 'int 1' => 1, 'int 12345' => 12345, 'int -12345' => -12345, 'float 10.5' => 10.5, 'float -10.5' => -10.5, 'float .5' => 0.5, 'empty array' => array(), 'int indexed array' => $index_array, 'associative array' => $assoc_array, 'nested arrays' => array('foo', $index_array, $assoc_array), 'uppercase NULL' => NULL, 'lowercase null' => null, 'lowercase true' => true, 'lowercase false' => false, 'uppercase TRUE' => TRUE, 'uppercase FALSE' => FALSE, 'empty string DQ' => "", 'empty string SQ' => '', 'string DQ' => "string", 'string SQ' => 'string', 'mixed case string' => "sTrInG", 'heredoc' => $heredoc, 'instance of classWithToString' => new classWithToString(), 'instance of classWithoutToString' => new classWithoutToString(), 'undefined var' => @$undefined_var, 'unset var' => @$unset_var, 'resource' => $file_handle); $timezone = new DateTimezone("Europe/London"); foreach ($inputs as $variation => $datetime) { echo "\n-- {$variation} --\n"; var_dump($timezone->getOffset($datetime)); } // closing the resource fclose($file_handle); ?> ===DONE===