Skip to content

Commit

Permalink
Merge pull request #17 from dbehnke/feature/localtime
Browse files Browse the repository at this point in the history
local time display
  • Loading branch information
kc1awv authored Oct 8, 2022
2 parents f829b6e + d8b6683 commit 45256e3
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.6
0.1.0
69 changes: 63 additions & 6 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<td class="text-center">${ station.callsignsuffix }</td>
<td>${ station.vianode }</td>
<td class="text-center">${ station.onmodule }</td>
<td>${ station.lastheard }</td>
<td>${ station.lastheardlocal }</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -67,11 +67,68 @@
}
},
methods: {
fetchStationsList () {
$.getJSON('{{ .config.SubPath }}/json/stations', (stationdata) => {
this.stationdata = stationdata
});
},
fetchStationsList () {
$.getJSON('{{ .config.SubPath }}/json/stations', (stationdata) => {
stationdata.stations.forEach(function(station, index) {
function getDateString(dt) {
console.log(dt)
const year = dt.getFullYear()
const m = dt.getMonth() + 1
var month = "" + m
if (m < 10) {
month = "0" + m
}
const d = dt.getDate()
var day = "" + d
if (d < 10) {
day = "0" + d
}
return (day+"."+month+"."+year)
}
function getTimeString(dt) {
const h = dt.getHours()
var hour = "" + h
if (h < 10) {
hour = "0" + h
}
const m = dt.getMinutes()
var min = "" + m
if (m < 10) {
min = "0" + m
}
//const s = dt.getSeconds()
//var sec = "" + s
//if (s < 10) {
// sec = "0" + s
//}
return (hour+":"+min)
}
function diffSeconds(dt2, dt1) {
var diff =(dt2.getTime() - dt1.getTime()) / 1000;

return Math.abs(Math.round(diff));
}
function localTimeString(dateTimeString) {
const now = new Date();
const then = new Date(dateTimeString)
if (now.toLocaleDateString() == then.toLocaleDateString()) {
const dSeconds = diffSeconds(now, then)
if (dSeconds < 60) {
return(dSeconds + " sec ago")
}
if (dSeconds < 60 * 5) {
return(Math.abs(Math.round(dSeconds / 60)) + " min ago")
}
return(getTimeString(then))
}
return(getDateString(then) + " " + getTimeString(then))
}
station.lastheardlocal = localTimeString(station.lastheard)
stationdata.stations[index] = station
});
this.stationdata = stationdata
});
},
},
mounted() {
this.timer = setInterval(this.fetchStationsList, refreshTime)
Expand Down
2 changes: 1 addition & 1 deletion templates/links.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
});
},
},
mounted() {
created() {
this.timer = setInterval(this.fetchLinksList, refreshTime)
this.fetchLinksList()
},
Expand Down
2 changes: 1 addition & 1 deletion templates/peers.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
});
},
},
mounted() {
created() {
this.timer = setInterval(this.fetchPeersList, refreshTime)
this.fetchPeersList()
},
Expand Down

0 comments on commit 45256e3

Please sign in to comment.