Skip to content

Commit

Permalink
Merge pull request #4 from gregmeszaros/omegapool
Browse files Browse the repository at this point in the history
Omegapool sync
  • Loading branch information
gregmeszaros authored Nov 6, 2018
2 parents 63f6659 + 0248308 commit 28697bc
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
15 changes: 15 additions & 0 deletions web/minerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,16 @@ public static function getClientIp() {
*/
public static function checkWallet($coin_seo_name = FALSE) {

// Check for the time_zone cookie, if set then reset the default timezone
if (!empty($_COOKIE['userLocalTimeZone'])) {
$time_zone = json_decode($_COOKIE['userLocalTimeZone'], true);
// Make sure there's an available abbreviation before setting the timezone

if (timezone_name_from_abbr( '', ($time_zone['offset'] - 60) * 60, $time_zone['dst'])) {
date_default_timezone_set( timezone_name_from_abbr('', ($time_zone['offset'] - 60) * 60, $time_zone['dst']));
}
}

// First check if we have something in get
if (!empty($_GET['wallet'])) {
// Update cookie
Expand Down Expand Up @@ -982,6 +992,10 @@ public static function _templateVariables($db = FALSE, $route = null, $data = FA
case 'blocks':
$blocks = minerHelper::getBlocks($db, $data['coin_id']);

if (!empty($_COOKIE['userLocalTimeZone'])) {
$time_zone = json_decode($_COOKIE['userLocalTimeZone'], true);
}

// Load last 30 blocks
return [
'blocks' => $blocks,
Expand All @@ -990,6 +1004,7 @@ public static function _templateVariables($db = FALSE, $route = null, $data = FA
'hashrate_user_24_hours' => $hashrate_user_24_hours ?? FALSE,
'coin_seo_name' => $data['coin_seo_name'],
'seo_site_name' => $data['seo_site_name'],
'offset' => $time_zone['offset'],
'load_blocks_charts' => TRUE
];
break;
Expand Down
1 change: 1 addition & 0 deletions web/templates/blocks.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</tr>
{% endfor %}

<p>Offset from GMT: {{ offset }} minutes -> times are adjusted to your local timezone!</p>
</table>

<div id="container-block-diff" style="min-width: 310px; height: 300px; margin: 0 auto"></div>
Expand Down
60 changes: 57 additions & 3 deletions web/templates/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,63 @@
<div class="fork-info">Fork based on <a href="https://github.com/tpruvot/yiimp" target="_blank">YiiMP project</a></div>

<script>
var d = new Date();
var n = d.getTimezoneOffset();
console.log(n);
/**
* Set the local time offset to display time values in the users local time
*/
function setTimeOffset() {
// Create all the dates necessary
var now = later = d1 = d2 = new Date(),
set = { 'offset': now.getTimezoneOffset() * -1, 'dst': 0 }
// Set time for how long the cookie should be saved - 1 year
later.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
// Date one is set to January 1st of this year
// Guaranteed not to be in DST for northern hemisphere and guaranteed to be in DST for southern hemisphere (If DST exists on client PC)
d1.setDate(1);
d1.setMonth(1);
// Date two is set to July 1st of this year
// Guaranteed to be in DST for northern hemisphere and guaranteed not to be in DST for southern hemisphere (If DST exists on client PC)
d2.setDate(1);
d2.setMonth(7);

// DST exists for this time zone – check if it is currently active
if ( parseInt( d1.getTimezoneOffset() ) != parseInt( d2.getTimezoneOffset() ) ) {
// Find out if we are on northern or southern hemisphere - Hemisphere is positive for northern, and negative for southern
var hemisphere = parseInt( d1.getTimezoneOffset() ) - parseInt( d2.getTimezoneOffset() );

if (
( hemisphere > 0 && parseInt( d1.getTimezoneOffset() ) == parseInt( now.getTimezoneOffset() ) ) ||
( hemisphere < 0 && parseInt( d2.getTimezoneOffset() ) == parseInt( now.getTimezoneOffset() ) )
) {
// DST is active right now
set.dst = 1;
}
}
document.cookie ='userLocalTimeZone='+ JSON.stringify(set) +'; expires='+ later +'; path=/';
}

function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

if (!getCookie('userLocalTimeZone')) {
setTimeOffset();

console.log('Cookie set');
}

console.log(getCookie('userLocalTimeZone'));
</script>

{% if load_charts %}
Expand Down

0 comments on commit 28697bc

Please sign in to comment.