Sliding Clock: Adding german 24 hour clock

pull/2178/head
Adrian Kirk 2022-10-15 13:07:33 +01:00
parent 980bba32ca
commit 712d37a9a6
No known key found for this signature in database
GPG Key ID: 5A448EB0FC623526
6 changed files with 159 additions and 94 deletions

View File

@ -19,7 +19,9 @@
{"name":"slidingtext.locale.es.js","url":"slidingtext.locale.es.js"},
{"name":"slidingtext.locale.fr.js","url":"slidingtext.locale.fr.js"},
{"name":"slidingtext.locale.jp.js","url":"slidingtext.locale.jp.js"},
{"name":"slidingtext.utils.de.js","url":"slidingtext.utils.de.js"},
{"name":"slidingtext.locale.de.js","url":"slidingtext.locale.de.js"},
{"name":"slidingtext.locale.de2.js","url":"slidingtext.locale.de2.js"},
{"name":"slidingtext.locale.dgt.js","url":"slidingtext.locale.dgt.js"},
{"name":"slidingtext.locale.hyb.js","url":"slidingtext.locale.hyb.js"},
{"name":"slidingtext.dtfmt.js","url":"slidingtext.dtfmt.js"}

View File

@ -330,7 +330,7 @@ function initDisplay(settings) {
vsmall: [20,15],
ssmall: [22,17],
small: [25,20],
msmall: [28,22],
msmall: [29,22],
medium: [40,25],
mlarge: [45,35],
large: [50,40],

View File

@ -1,72 +1,10 @@
const DateFormatter = require("slidingtext.dtfmt.js");
const germanHoursToText = require("slidingtext.utils.de.js").germanHoursToText;
const germanMinsToText = require("slidingtext.utils.de.js").germanMinsToText;
const germanNumberStr = [ ["NULL",""], // 0
["EINS",""], // 1
["ZWEI",""], //2
["DREI",''], //3
["VIER",''], //4
["FÜNF",''], //5
["SECHS",''], //6
["SIEBEN",''], //7
["ACHT",''], //8
["NEUN",''], // 9,
["ZEHN",''], // 10
["ELF",''], // 11,
["ZWÖLF",''], // 12
["DREI",'ZEHN'], // 13
["VIER",'ZEHN'], // 14
["FÜNF",'ZEHN'], // 15
["SECH",'ZEHN'], // 16
["SIEB",'ZEHN'], // 17
["ACHT",'ZEHN'], // 18
["NEUN",'ZEHN'], // 19
];
const germanTensStr = ["NULL",//0
"ZEHN",//10
"ZWANZIG",//20
"DREIßIG",//30
"VIERZIG",//40
"FÜNFZIG",//50
"SECHZIG"//60
]
const germanUnit = ["",//0
"EINUND",//1
"ZWEIUND",//2
"DREIUND",//3
"VIERUND", //4
"FÜNFUND", //5
"SECHSUND", //6
"SIEBENUND", //7
"ACHTUND", //8
"NEUNUND" //9
]
function germanHoursToText(hours){
hours = hours % 12;
if(hours === 0){
hours = 12;
}
if(hours === 1){
return "EIN"
} else {
return germanNumberStr[hours][0];
}
}
function germanMinsToText(mins) {
if (mins < 20) {
return germanNumberStr[mins];
} else {
const tens = (mins / 10 | 0);
const word1 = germanTensStr[tens];
const remainder = mins - tens * 10;
const word2 = germanUnit[remainder];
return [word2, word1];
}
}
/**
* German 12 hour clock
*/
class GermanDateFormatter extends DateFormatter {
constructor() {
super();
@ -74,21 +12,10 @@ class GermanDateFormatter extends DateFormatter {
formatDate(date){
const mins = date.getMinutes();
const hourOfDay = date.getHours();
var hours = germanHoursToText(hourOfDay);
//console.log('hourOfDay->' + hourOfDay + ' hours text->' + hours)
// Deal with the special times first
const hours = germanHoursToText(hourOfDay);
if(mins === 0){
return [hours,"UHR", "","",""];
} /*else if(mins == 30){
var hours = germanHoursToText(hourOfDay+1);
return ["", "", "HALB","", hours];
} else if(mins == 15){
var hours = germanHoursToText(hourOfDay);
return ["", "", "VIERTEL", "NACH",hours];
} else if(mins == 45) {
var hours = germanHoursToText(hourOfDay+1);
return ["", "", "VIERTEL", "VOR",hours];
} */ else {
} else {
const mins_txt = germanMinsToText(mins);
return [hours, "UHR", mins_txt[0],mins_txt[1]];
}

View File

@ -0,0 +1,49 @@
const DateFormatter = require("slidingtext.dtfmt.js");
const german24HoursToText = require("slidingtext.utils.de.js").german24HoursToText;
const germanMinsToText = require("slidingtext.utils.de.js").germanMinsToText;
/**
* German 24 hour clock
*/
class German24HourDateFormatter extends DateFormatter {
constructor() {
super();
}
formatDate(date){
const mins = date.getMinutes();
const hourOfDay = date.getHours();
const hours = german24HoursToText(hourOfDay);
const display_hours = (hours[1] === '')? ["", hours[0]] : hours;
if(mins === 0){
return [display_hours[0],display_hours[1],"UHR", "","",""];
} else {
const mins_txt = germanMinsToText(mins);
return [display_hours[0],display_hours[1], "UHR", mins_txt[0],mins_txt[1]];
}
}
defaultRowTypes(){ return {
large:{
size: 'mlarge'
}
};}
defaultRowDefs(){
return [
{
type: 'large',
init_coords: [0.05,0.06],
row_direction: [0.0,1.0],
rows: 2
},
{
type: 'medium',
init_coords: [0.05,0.5],
row_direction: [0.0,1.0],
rows: 3
}
];
}
}
module.exports = German24HourDateFormatter;

View File

@ -9,8 +9,8 @@
}
console.log("loaded:" + JSON.stringify(settings));
const locale_mappings = (bangleVersion > 1)? {
'en' : { date_formatter: 'en' },
'en alt': {
'english' : { date_formatter: 'en' },
'english alt': {
date_formatter: 'en',
row_types: {
large:{
@ -52,8 +52,8 @@
}
]
},
'en2': { date_formatter: 'en2' },
'en2 alt': { date_formatter: 'en2',
'english2': { date_formatter: 'en2' },
'english2 alt': { date_formatter: 'en2',
row_types: {
vsmall: {
color: 'minor',
@ -105,18 +105,19 @@
},
]
},
'fr': { date_formatter:'fr'},
'de': { date_formatter: 'de'},
'es': { date_formatter: 'es'},
'jp': { date_formatter: 'jp'},
'french': { date_formatter:'fr'},
'german': { date_formatter: 'de'},
'german 24h': { date_formatter: 'de2'},
'spanish': { date_formatter: 'es'},
'japanese': { date_formatter: 'jp'},
'hybrid': { date_formatter: 'hyb'},
'digits': { date_formatter: 'dgt'},
} : {
'en' : { date_formatter: 'en' },
'fr': { date_formatter:'fr'},
'de': { date_formatter: 'de'},
'es': { date_formatter: 'es'},
'jp': { date_formatter: 'jp'},
'english' : { date_formatter: 'en' },
'french': { date_formatter:'fr'},
'german': { date_formatter: 'de'},
'spanish': { date_formatter: 'es'},
'japanese': { date_formatter: 'jp'},
'hybrid': { date_formatter: 'hyb'},
'digits': { date_formatter: 'dgt'},
}

View File

@ -0,0 +1,86 @@
const germanNumberStr = [ ["NULL",""], // 0
["EINS",""], // 1
["ZWEI",""], //2
["DREI",""], //3
["VIER",""], //4
["FÜNF",""], //5
["SECHS",""], //6
["SIEBEN",""], //7
["ACHT",""], //8
["NEUN",""], // 9,
["ZEHN",""], // 10
["ELF",""], // 11,
["ZWÖLF",""], // 12
["DREI","ZEHN"], // 13
["VIER","ZEHN"], // 14
["FÜNF","ZEHN"], // 15
["SECH","ZEHN"], // 16
["SIEB","ZEHN"], // 17
["ACHT","ZEHN"], // 18
["NEUN","ZEHN"], // 19
["ZWANZIG",""], // 20
["EIN","UNDZWANZIG"], // 21
["ZWEI","UNDZWANZIG"], //22
["DREI","UNDZWANZIG"], // 23
["VIER","UNDZWANZIG"] // 24
];
const germanTensStr = ["NULL",//0
"ZEHN",//10
"ZWANZIG",//20
"DREIßIG",//30
"VIERZIG",//40
"FÜNFZIG",//50
"SECHZIG"//60
]
const germanUnit = ["",//0
"EINUND",//1
"ZWEIUND",//2
"DREIUND",//3
"VIERUND", //4
"FÜNFUND", //5
"SECHSUND", //6
"SIEBENUND", //7
"ACHTUND", //8
"NEUNUND" //9
]
function germanHoursToText(hours){
hours = hours % 12;
if(hours === 0){
hours = 12;
}
if(hours === 1){
return "EIN"
} else {
return germanNumberStr[hours][0];
}
}
function german24HoursToText(hours){
hours = hours % 24;
if(hours === 0){
return hours[24] ;
} else if(hours === 1){
return ["EIN",""];
} else {
return germanNumberStr[hours];
}
}
function germanMinsToText(mins) {
if (mins < 20) {
return germanNumberStr[mins];
} else {
const tens = (mins / 10 | 0);
const word1 = germanTensStr[tens];
const remainder = mins - tens * 10;
const word2 = germanUnit[remainder];
return [word2, word1];
}
}
exports.germanMinsToText = germanMinsToText;
exports.germanHoursToText = germanHoursToText;
exports.german24HoursToText = german24HoursToText;