Skip to content

Commit

Permalink
Merge pull request osTicket#2981 from protich/issue/timestamp
Browse files Browse the repository at this point in the history
Date Time Conversion Mojo

Reviewed-By: Jared Hancock <[email protected]>
  • Loading branch information
greezybacon committed Mar 28, 2016
2 parents 498aa9a + 3c92a71 commit 26f7069
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
31 changes: 14 additions & 17 deletions include/class.misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,15 @@ function user2gmtime($timestamp=null, $user=null) {

$tz = new DateTimeZone($cfg->getTimezone($user));

if (!$timestamp)
$timestamp = 'now';

if (is_int($timestamp)) {
$time = $timestamp;
} else {
if (!($date = new DateTime($timestamp, $tz))) {
// Timestamp might be invalid
if ($timestamp && is_int($timestamp)) {
if (!($date = DateTime::createFromFormat('U', $timestamp)))
return $timestamp;
}
$time = $date->format('U');
}

if (!($D = DateTime::createFromFormat('U', $time)))
return $time;
return $timestamp - $tz->getOffset($date);
}

return $time - $tz->getOffset($D);
$date = new DateTime($timestamp ?: 'now', $tz);
return $date ? $date->getTimestamp() : $timestamp;
}

//Take user time or gmtime and return db (mysql) time.
Expand Down Expand Up @@ -131,10 +123,14 @@ function gmtime($time=false, $user=false) {
global $cfg;

$tz = new DateTimeZone($user ? $cfg->getDbTimezone($user) : 'UTC');
if (!($time = new DateTime($time ?: 'now'))) {

if ($time && is_numeric($time))
$time = DateTime::createFromFormat('U', $time);
elseif (!($time = new DateTime($time ?: 'now'))) {
// Old standard
return time() - date('Z');
}

return $time->getTimestamp() - $tz->getOffset($time);
}

Expand Down Expand Up @@ -189,15 +185,16 @@ function timeDropdown($hr=null, $min =null,$name='time') {
else
$min=0;

$time = Misc::user2gmtime(mktime(0,0,0));
ob_start();
echo sprintf('<select name="%s" id="%s" style="display:inline-block;width:auto">',$name,$name);
echo '<option value="" selected>'.__('Time').'</option>';
for($i=23; $i>=0; $i--) {
for($minute=45; $minute>=0; $minute-=15) {
for ($minute=45; $minute>=0; $minute-=15) {
$sel=($hr==$i && $min==$minute)?'selected="selected"':'';
$_minute=str_pad($minute, 2, '0',STR_PAD_LEFT);
$_hour=str_pad($i, 2, '0',STR_PAD_LEFT);
$disp = Format::time($i*3600 + $minute*60 + 1);
$disp = Format::time($time + ($i*3600 + $minute*60 + 1), false);
echo sprintf('<option value="%s:%s" %s>%s</option>',$_hour,$_minute,$sel,$disp);
}
}
Expand Down
10 changes: 8 additions & 2 deletions include/class.ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,16 +587,22 @@ function getHashtable() {
}

function getUpdateInfo() {
global $cfg;

return array(
'source' => $this->getSource(),
'topicId' => $this->getTopicId(),
'slaId' => $this->getSLAId(),
'user_id' => $this->getOwnerId(),
'duedate' => $this->getDueDate()
? Format::date($this->getDueDate())
? Format::date($this->getDueDate(), true,
$cfg->getDateFormat(true))
: '',
'time' => $this->getDueDate()
? Format::time($this->getDueDate(), true, 'HH:mm')
: '',
'time' => $this->getDueDate()?(Format::date($this->getDueDate(), true, 'HH:mm')):'',
);

}

function getLock() {
Expand Down
1 change: 1 addition & 0 deletions scp/js/scp.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ $.translate_format = function(str) {
'yyyy': '`',
'yyy': '`',
'yy': 'y',
'y': 'yy',
'`': 'yy'
};
// Change PHP formats to datepicker ones
Expand Down

0 comments on commit 26f7069

Please sign in to comment.