Matrix Clock: Adding 24 hour clock as an available time format (controlled from the setting window

master
lu713691 2022-07-17 21:48:17 +01:00
parent 6ca63def2f
commit c5f27550f1
2 changed files with 17 additions and 3 deletions

View File

@ -10,9 +10,16 @@
const Locale = require('locale');
const PREFERENCE_FILE = "matrixclock.settings.json";
const settings = Object.assign({color: "theme", intensity: 'light'},
const settings = Object.assign({color: "theme", time_format: '12 hour', intensity: 'light'},
require('Storage').readJSON(PREFERENCE_FILE, true) || {});
var format_time;
if(settings.time_format == '24 hour'){
format_time = (t) => format_time_24_hour(t);
} else {
format_time = (t) => format_time_12_hour(t);
}
const colors = {
'gray' :[0.5,0.5,0.5],
'green': [0,1.0,0],
@ -247,8 +254,14 @@ function format_date(now){
return Locale.dow(now,1) + " " + format00(now.getDate());
}
function format_time_24_hour(now){
var time = new Date(now.getTime());
var hours = time.getHours() ;
function format_time(now){
return format00(hours) + ":" + format00(time.getMinutes());
}
function format_time_12_hour(now){
var time = new Date(now.getTime());
var hours = time.getHours() % 12;
if(hours < 1){

View File

@ -1,6 +1,6 @@
(function(back) {
const PREFERENCE_FILE = "matrixclock.settings.json";
var settings = Object.assign({color : "theme", intensity: "light"},
var settings = Object.assign({color : "theme", time_format: '12 hour', intensity: "light"},
require('Storage').readJSON(PREFERENCE_FILE, true) || {});
console.log("loaded:" + JSON.stringify(settings));
@ -44,6 +44,7 @@
'white on red',
'white on blue'
]),
"Time Format": stringInSettings("time_format", ['12 hour','24 hour']),
"Intensity": stringInSettings("intensity", ['light',
'medium',
'high'])