File: lsw-date2iso.js

package info (click to toggle)
libreswan 5.2-2.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 81,632 kB
  • sloc: ansic: 129,988; sh: 32,018; xml: 20,646; python: 10,303; makefile: 3,022; javascript: 1,506; sed: 574; yacc: 511; perl: 264; awk: 52
file content (24 lines) | stat: -rw-r--r-- 751 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Convert the Date() to the truncated ISO string: YYYY-MM-DD HH:MM.
function lsw_date2iso(d) {
    // Force to UTC?
    if (d && d.toISOString && !isNaN(d)) {
	d = d.toISOString()
	d = d.match("([^T]*)T([0-9]*:[0-9]*)")
	return d[1] + " " + d[2]
    } else {
	console.log("not a date", d, new Error().stack)
	return ">>> " + d + " <<<"
    }
}

// convert Date(l)-Date(r) to hours:minutes:seconds
function subtime(l, r) {
    let ms = (Number(l) - Number(r))
    let hours = ms / 1000 / 60 / 60
    let minutes = (ms / 1000 / 60) % 60
    let seconds = (ms / 1000) % 60
    // can you believe this!
    ps = (n) => Math.trunc(n).toString().padStart(2, "0")
    // prints 0:01:00
    return Math.trunc(hours) + ":" + ps(minutes) + ":" + ps(seconds)
}