Skip to content

Commit 8a06af5

Browse files
committed
🔨 better date formatting
1 parent 68b9f59 commit 8a06af5

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

main.tis

+6-20
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,13 @@ $(#quit) << event click {
55
view.close();
66
}
77

8-
function pad(digit) {
9-
const d = digit.toString();
10-
if (d.length == 1) return "0" + d;
11-
if (d.length == 0) return "00";
12-
return d;
13-
}
14-
158
function updateDate() {
16-
const date = new Date().toLocaleString(#time);
17-
const regex = /(\d+):(\d+):(\d+) ?(.*)?/;
18-
const matches = date.match(regex);
19-
const [match, hours, minutes, seconds, meridian] = matches;
20-
const h = pad(hours);
21-
const m = pad(minutes);
22-
const H = root.TIME_FORMAT == "12h"
23-
? h
24-
: pad(new Date().hour);
25-
const MERIDIAN = root.TIME_FORMAT == "12h"
26-
? String.$( {meridian})
27-
: "";
28-
$(#time).text = String.$({H}:{m}{MERIDIAN});
9+
if(root.TIME_FORMAT == "12h") {
10+
$(#time).text = new Date().toString("%I:%M %p");
11+
}
12+
else {
13+
$(#time).text = new Date().toString("%R");
14+
}
2915
return true;
3016
}
3117

0 commit comments

Comments
 (0)