Issue 76: Time on issues should show time as well as date
This commit is contained in:
parent
420d4fdd26
commit
8b486e74ea
@ -187,6 +187,13 @@ class IDF_Form_UserAccount extends Pluf_Form
|
||||
'size' => 32,
|
||||
),
|
||||
));
|
||||
|
||||
$this->fields['timezone'] = new Pluf_Form_Field_TimeZone(
|
||||
array('required' => false,
|
||||
'label' => __('Change Timezone'),
|
||||
'initial' => $this->user->timezone,
|
||||
'help_text' => __('This will change the way some of the date and times are displayed on the site.'),
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,12 +22,12 @@
|
||||
<img style="float:right; position: relative; max-height: 60px; max-width: 60px;" src="http://www.gravatar.com/avatar/{$submitter.email|md5}.jpg?s=60&d={media}/idf/img/spacer.gif" alt=" " />
|
||||
{/if}
|
||||
{if $i == 0}
|
||||
<p>{blocktrans}Reported by {$submitter}, {$c.creation_dtime|date}{/blocktrans}</p>
|
||||
<p>{blocktrans}Reported by {$submitter}, {/blocktrans}<span title="{$c.creation_dtime} GMT">{$request.user.convertToUserTimezone($c.creation_dtime)}</span></p>
|
||||
{else}
|
||||
{aurl 'url', 'IDF_Views_Issue::view', array($project.shortname, $issue.id)}
|
||||
{assign $id = $c.id}
|
||||
{assign $url = $url~'#ic'~$c.id}
|
||||
<p>{blocktrans}Comment <a href="{$url}">{$i}</a> by {$submitter}, {$c.creation_dtime|date}{/blocktrans}</p>
|
||||
<p>{blocktrans}Comment <a href="{$url}">{$i}</a> by {$submitter}, {/blocktrans}<span title="{$c.creation_dtime} GMT">{$request.user.convertToUserTimezone($c.creation_dtime)}</span></p>
|
||||
{/if}
|
||||
|
||||
|
||||
|
@ -34,6 +34,13 @@
|
||||
<span class="helptext">{$form.f.email.help_text}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th><strong>{$form.f.timezone.labelTag}:</strong></th>
|
||||
<td>{if $form.f.timezone.errors}{$form.f.timezone.fieldErrors}{/if}
|
||||
{$form.f.timezone|unsafe}<br />
|
||||
<span class="helptext">{$form.f.timezone.help_text}</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>{$form.f.language.labelTag}:</th>
|
||||
<td>{if $form.f.language.errors}{$form.f.language.fieldErrors}{/if}
|
||||
|
8
pluf/src/Pluf/Form/Field/TimeZone.php
Normal file
8
pluf/src/Pluf/Form/Field/TimeZone.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
class Pluf_Form_Field_TimeZone extends Pluf_Form_Field
|
||||
{
|
||||
public $widget = 'Pluf_Form_Widget_TimeZoneInput';
|
||||
|
||||
|
||||
}
|
72
pluf/src/Pluf/Form/Widget/TimeZoneInput.php
Normal file
72
pluf/src/Pluf/Form/Widget/TimeZoneInput.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
class Pluf_Form_Widget_TimeZoneInput extends Pluf_Form_Widget_Input
|
||||
{
|
||||
public $input_type = 'text';
|
||||
public $initial = "";
|
||||
|
||||
public function __construct($attrs = []) {
|
||||
parent::__construct($attrs);
|
||||
}
|
||||
|
||||
public function render($name, $value, $extra_attrs=array()) {
|
||||
return Pluf_Template::markSafe($this->getHTML($name, $value));
|
||||
}
|
||||
|
||||
public function getHTML($name, $value) {
|
||||
// Based off snippet here: http://stackoverflow.com/a/17355238/195722
|
||||
static $regions = array(
|
||||
DateTimeZone::AFRICA,
|
||||
DateTimeZone::AMERICA,
|
||||
DateTimeZone::ANTARCTICA,
|
||||
DateTimeZone::ASIA,
|
||||
DateTimeZone::ATLANTIC,
|
||||
DateTimeZone::AUSTRALIA,
|
||||
DateTimeZone::EUROPE,
|
||||
DateTimeZone::INDIAN,
|
||||
DateTimeZone::PACIFIC,
|
||||
);
|
||||
|
||||
$timezones = array();
|
||||
foreach( $regions as $region )
|
||||
{
|
||||
$timezones = array_merge( $timezones, DateTimeZone::listIdentifiers( $region ) );
|
||||
}
|
||||
|
||||
$timezone_offsets = array();
|
||||
foreach( $timezones as $timezone )
|
||||
{
|
||||
$tz = new DateTimeZone($timezone);
|
||||
$timezone_offsets[$timezone] = $tz->getOffset(new DateTime);
|
||||
}
|
||||
|
||||
// sort timezone by timezone name
|
||||
ksort($timezone_offsets);
|
||||
|
||||
$timezone_list = array();
|
||||
foreach( $timezone_offsets as $timezone => $offset )
|
||||
{
|
||||
$offset_prefix = $offset < 0 ? '-' : '+';
|
||||
$offset_formatted = gmdate( 'H:i', abs($offset) );
|
||||
|
||||
$pretty_offset = "UTC${offset_prefix}${offset_formatted}";
|
||||
|
||||
$t = new DateTimeZone($timezone);
|
||||
$c = new DateTime(null, $t);
|
||||
$current_time = $c->format('g:i A');
|
||||
|
||||
$timezone_list[$timezone] = "(${pretty_offset}) $timezone - $current_time";
|
||||
}
|
||||
|
||||
$listArray = [];
|
||||
foreach($timezone_list as $key => $val) {
|
||||
if ($key == $value) {
|
||||
$listArray[] = "<option selected=\"selected\" value=\"$key\">$val</option>";
|
||||
} else {
|
||||
$listArray[] = "<option value=\"$key\">$val</option>";
|
||||
}
|
||||
}
|
||||
|
||||
return "<select name=\"$name\">" . implode("\n", $listArray) . "</select>";
|
||||
}
|
||||
}
|
@ -233,6 +233,12 @@ class Pluf_User extends Pluf_Model
|
||||
}
|
||||
}
|
||||
|
||||
public function convertToUserTimezone($date) {
|
||||
$currentDateTime = new \DateTime(date('Y-m-d H:i:s', strtotime($date.' GMT')));
|
||||
$currentDateTime->setTimezone(new \DateTimeZone($this->timezone));
|
||||
return $currentDateTime->format("M, j Y g:i:s A");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the password of a user.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user