diff --git a/indefero/src/IDF/Form/UserAccount.php b/indefero/src/IDF/Form/UserAccount.php index da10bd6..2ceb9e8 100644 --- a/indefero/src/IDF/Form/UserAccount.php +++ b/indefero/src/IDF/Form/UserAccount.php @@ -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.'), + )); } diff --git a/indefero/src/IDF/templates/idf/issues/view.html b/indefero/src/IDF/templates/idf/issues/view.html index 606437d..bc91af9 100644 --- a/indefero/src/IDF/templates/idf/issues/view.html +++ b/indefero/src/IDF/templates/idf/issues/view.html @@ -22,12 +22,12 @@  {/if} {if $i == 0} -

{blocktrans}Reported by {$submitter}, {$c.creation_dtime|date}{/blocktrans}

+

{blocktrans}Reported by {$submitter}, {/blocktrans}{$request.user.convertToUserTimezone($c.creation_dtime)}

{else} {aurl 'url', 'IDF_Views_Issue::view', array($project.shortname, $issue.id)} {assign $id = $c.id} {assign $url = $url~'#ic'~$c.id} -

{blocktrans}Comment {$i} by {$submitter}, {$c.creation_dtime|date}{/blocktrans}

+

{blocktrans}Comment {$i} by {$submitter}, {/blocktrans}{$request.user.convertToUserTimezone($c.creation_dtime)}

{/if} diff --git a/indefero/src/IDF/templates/idf/user/myaccount.html b/indefero/src/IDF/templates/idf/user/myaccount.html index 7dfa607..7623635 100644 --- a/indefero/src/IDF/templates/idf/user/myaccount.html +++ b/indefero/src/IDF/templates/idf/user/myaccount.html @@ -35,6 +35,13 @@ + {$form.f.timezone.labelTag}: + {if $form.f.timezone.errors}{$form.f.timezone.fieldErrors}{/if} + {$form.f.timezone|unsafe}
+ {$form.f.timezone.help_text} + + + {$form.f.language.labelTag}: {if $form.f.language.errors}{$form.f.language.fieldErrors}{/if} {$form.f.language|unsafe} diff --git a/pluf/src/Pluf/Form/Field/TimeZone.php b/pluf/src/Pluf/Form/Field/TimeZone.php new file mode 100644 index 0000000..01dcdb8 --- /dev/null +++ b/pluf/src/Pluf/Form/Field/TimeZone.php @@ -0,0 +1,8 @@ +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[] = ""; + } else { + $listArray[] = ""; + } + } + + return ""; + } +} \ No newline at end of file diff --git a/pluf/src/Pluf/User.php b/pluf/src/Pluf/User.php index fc44b7d..31f133d 100644 --- a/pluf/src/Pluf/User.php +++ b/pluf/src/Pluf/User.php @@ -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. *