Commit 13e77614 authored by Magnus Holm Brunbjerg's avatar Magnus Holm Brunbjerg
Browse files

Time formatting

parent 5fc4dd72
......@@ -341,6 +341,11 @@
"which": "^1.2.9"
}
},
"date-format": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/date-format/-/date-format-2.0.0.tgz",
"integrity": "sha512-M6UqVvZVgFYqZL1SfHsRGIQSz3ZL+qgbsV5Lp1Vj61LZVYuEwcMXYay7DRDtYs2HQQBK5hQtQ0fD9aEJ89V0LA=="
},
"debug": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
......
......@@ -15,6 +15,7 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"date-format": "^2.0.0",
"dotenv": "^7.0.0",
"express": "^4.16.4",
"express-handlebars": "^3.0.2",
......
......@@ -4,6 +4,7 @@ const express = require('express')
const exphbs = require('express-handlebars')
const bodyParser = require('body-parser')
const fetch = require('node-fetch')
const format = require('date-format')
const app = express()
......@@ -35,7 +36,7 @@ app.use(bodyParser.urlencoded({ extended: true }))
// Console logging of request type, url and time
app.use((req, res, next) => {
console.log(`${new Date().toLocaleTimeString('en-GB', { hour12: false })} - ${req.ip.substring(7)} - ${req.method} ${req.originalUrl}`)
console.log(`${format('hh:mm:ss', new Date())} - ${req.ip.substring(7)} - ${req.method} ${req.originalUrl}`)
next()
})
......@@ -58,7 +59,7 @@ app.route('/')
.then((running) => {
// If experiment is running, load experiment info
if (running) {
running.start_time = new Date(running.start_time).toLocaleString('en-GB', { hour12: false })
running.start_time = format('hh:mm - dd/MM/yy', new Date(running.start_time))
res.render('index', {
meta: {
title: 'Forside'
......@@ -117,8 +118,7 @@ app.route('/experiments')
})
.then((experiments) => {
for (let i = 0; i < experiments.length; i++) {
experiments[i].start_time = new Date(experiments[i].start_time).toLocaleString('en-GB', { hour12: false })
experiments[i].end_time = new Date(experiments[i].end_time).toLocaleString('en-GB', { hour12: false })
experiments[i].start_time = format('hh:mm - dd/MM/yy', new Date(experiments[i].start_time))
}
res.render('experiments', {
meta: {
......@@ -177,16 +177,17 @@ app.route('/experiments/:id')
if (response.status === 200) { return response.json() }
})
.then((experiment) => {
if (experiment) {
experiment.date = format('dd/MM/yy', new Date(experiment.start_time))
experiment.start_time = format('hh:mm', new Date(experiment.start_time))
experiment.end_time = format('hh:mm', new Date(experiment.end_time))
}
// Get issues from db
fetch(`${api}/experiments/${req.params.id}/issues`, standardGet)
.then((response) => {
if (response.status === 200) { return response.json() }
})
.then((issues) => {
for (let i = 0; i < issues.length; i++) {
issues[i].start_time = new Date(issues[i].start_time).toLocaleString('en-GB', { hour12: false })
issues[i].end_time = new Date(issues[i].end_time).toLocaleString('en-GB', { hour12: false })
}
res.render('issues', {
meta: {
title: 'Problemer'
......@@ -207,8 +208,7 @@ app.route('/compare')
})
.then((experiments) => {
for (let i = 0; i < experiments.length; i++) {
experiments[i].start_time = new Date(experiments[i].start_time).toLocaleString('en-GB', { hour12: false })
experiments[i].end_time = new Date(experiments[i].end_time).toLocaleString('en-GB', { hour12: false })
experiments[i].start_time = format('hh:mm - dd/MM/yy', new Date(experiments[i].start_time))
}
res.render('compare', {
meta: {
......
......@@ -8,8 +8,8 @@
<span>{{this.name}}</span>
</div>
<div class="experiment-information">
<span>Lærer: {{this.user_name}}</span>
<span>Tidspunkt: {{this.start_time}}</span>
<span>{{this.user_name}}</span>
<span>{{this.start_time}}</span>
</div>
</a>
</li>
......
<h1>{{experiment.name}}</h1>
<p>Lærer: {{experiment.user_name}}</p>
<span>Start: {{experiment.start_time}}</span>
<span>Slut: {{experiment.end_time}}</span>
<p>{{experiment.user_name}}</p>
<span>{{experiment.start_time}}</span>
<span> - {{experiment.end_time}}, </span>
<span>den {{experiment.date}}</span>
{{#if issues}}
<div style="position: relative; height:40vh; width:80vw">
<div style="position: relative; height:38vh; width:78vw">
<canvas id="issues-chart"></canvas>
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment