Skip to content

Commit c5ad6f5

Browse files
committed
date, time and datetime for widget templates
1 parent 9e4ebc4 commit c5ad6f5

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

api/widget.js

+23-7
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,31 @@ ethplorerWidget = {
5858
return '<a class="tx-link" href="' + ethplorerWidget.url + '/' + linkType + '/' + data + hash + '" title="' + title + '" target="_blank">' + text + '</a>';
5959
},
6060

61-
// Date with fixed GMT to local date
62-
ts2date: function(ts, withGMT){
61+
// Timestamp to local date
62+
ts2date: function(ts, withTime, withGMT){
63+
withGMT = 'undefined' !== typeof(withGMT) ? withGMT : true;
64+
ts *= 1000;
65+
function padZero(s){
66+
return (s < 10) ? '0' + s : s.toString();
67+
}
68+
var res = '';
69+
var dt = new Date(ts);
70+
res += (dt.getFullYear() + '-' + padZero((dt.getMonth() + 1)) + '-' + padZero(dt.getDate()));
71+
if(withTime){
72+
res += ' ';
73+
res += ethplorerWidget.Utils.ts2time(ts, withGMT);
74+
}
75+
return res;
76+
},
77+
//Timestamp to local time
78+
ts2time: function(ts, withGMT){
6379
withGMT = 'undefined' !== typeof(withGMT) ? withGMT : true;
6480
ts *= 1000;
6581
function padZero(s){
6682
return (s < 10) ? '0' + s : s.toString();
6783
}
6884
var res = '';
6985
var dt = new Date(ts);
70-
/*res += (dt.getFullYear() + '-' + padZero((dt.getMonth() + 1)) + '-' + padZero(dt.getDate()));
71-
res += ' '*/;
7286
res += (padZero(dt.getHours()) + ':' + padZero(dt.getMinutes()) + ':' + padZero(dt.getSeconds()));
7387
if(withGMT){
7488
res += (' (' + Ethplorer.Utils.getTZOffset() + ')');
@@ -166,14 +180,14 @@ ethplorerWidget.Type['tokenHistory'] = function(element, options, templates){
166180
debug: '<div class="txs-debug"><div class="txs-stop"></div></div>',
167181
// Big table row
168182
big: '<tr>' +
169-
'<td class="tx-field tx-date">%date%</td>' +
183+
'<td class="tx-field tx-date">%time%</td>' +
170184
'<td class="tx-field tx-transfer"><span class="tx-send">from </span>%from%<span class="tx-send">to</span>%to%</td>' +
171185
'<td class="tx-field tx-amount">%amount%</td>' +
172186
'<td class="tx-field tx-token">%token%</td>' +
173187
'</tr>',
174188
// Small table row
175189
small: '<tr>' +
176-
'<td class="tx-field tx-date">%date%</td>' +
190+
'<td class="tx-field tx-date">%time%</td>' +
177191
'<td class="tx-field tx-transfer"><span class="tx-send">from </span>%from%</td>' +
178192
'</tr><tr>' +
179193
'<td class="tx-field">&nbsp;</td>' +
@@ -348,7 +362,9 @@ ethplorerWidget.Type['tokenHistory'] = function(element, options, templates){
348362
var hash = tr.priority ? tr.priority : false;
349363

350364
return {
351-
date: ethplorerWidget.Utils.link(tr.transactionHash, ethplorerWidget.Utils.ts2date(tr.timestamp, false), tr.transactionHash, hash),
365+
date: ethplorerWidget.Utils.link(tr.transactionHash, ethplorerWidget.Utils.ts2date(tr.timestamp, false, false), tr.transactionHash, hash),
366+
time: ethplorerWidget.Utils.link(tr.transactionHash, ethplorerWidget.Utils.ts2time(tr.timestamp, false), tr.transactionHash, hash),
367+
datetime: ethplorerWidget.Utils.link(tr.transactionHash, ethplorerWidget.Utils.ts2date(tr.timestamp, true, false), tr.transactionHash, hash),
352368
from: ethplorerWidget.Utils.link(tr.from, tr.from),
353369
to: ethplorerWidget.Utils.link(tr.to, tr.to),
354370
amount: ethplorerWidget.Utils.link(tr.tokenInfo.address, amount, amount + ' ' + tr.tokenInfo.symbol),

0 commit comments

Comments
 (0)