diff --git a/apps.json b/apps.json index f9c5b34fb..79bd0b046 100644 --- a/apps.json +++ b/apps.json @@ -4655,7 +4655,7 @@ "name": "TimeCal", "shortName":"TimeCal", "icon": "icon.png", - "version":"0.02", + "version":"0.03", "description": "TimeCal shows the Time along with a 3 week calendar", "tags": "clock", "readme":"README.md", diff --git a/apps/timecal/timecal.app.js b/apps/timecal/timecal.app.js index 17daf127a..97cd596c8 100644 --- a/apps/timecal/timecal.app.js +++ b/apps/timecal/timecal.app.js @@ -19,14 +19,14 @@ class TimeCalClock{ const defaults = { shwDate:1, //0:none, 1:locale, 2:month, 3:monthshort.year #week - wdStrt:1, //identical to getDay() 0->Su, 1->Mo, ... //Issue #1154: weekstart So/Mo, -1 for use today + wdStrt:0, //identical to getDay() 0->Su, 1->Mo, ... //Issue #1154: weekstart So/Mo, -1 for use today - tdyNumClr:0, //0:fg, 1:red=#E00, 2:green=#0E0, 3:blue=#00E + tdyNumClr:3, //0:fg, 1:red=#E00, 2:green=#0E0, 3:blue=#00E tdyMrkr:0, //0:none, 1:circle, 2:rectangle, 3:filled tdyMrkClr:2, //1:red=#E00, 2:green=#0E0, 3:blue=#00E tdyMrkPxl:3, //px - suClr:0, //0:fg, 1:red=#E00, 2:green=#0E0, 3:blue=#00E + suClr:1, //0:fg, 1:red=#E00, 2:green=#0E0, 3:blue=#00E //phColor:"#E00", //public holiday calBrdr:false @@ -41,7 +41,19 @@ class TimeCalClock{ this.centerX = Bangle.appRect.w/2; this.nrgb = [g.theme.fg, "#E00", "#0E0", "#00E"]; //fg, r ,g , b - this.ABR_DAY = require("locale") && require("locale").abday ? require("locale").abday : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + + this.ABR_DAY=[]; + if (require("locale") && require("locale").dow) + for (let d=0; d<=6; d++) { + var refDay=new Date(); + refDay.setFullYear(1972); + refDay.setMonth(0); + refDay.setDate(2+d); + this.ABR_DAY.push(require("locale").dow(refDay)); + + } + else + this.ABR_DAY=["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; } /** @@ -57,7 +69,10 @@ class TimeCalClock{ **/ draw(){ this.drawTime(); - } + + if (this.TZOffset===undefined || this.TZOffset!==d.getTimezoneOffset()) + this.drawDateAndCal(); + } /** * draw given or current time from date @@ -77,10 +92,7 @@ class TimeCalClock{ g.drawString(("0" + require("locale").time(d, 1)).slice(-5), this.centerX, Y); //.drawRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7); //DEV-Option - setTimeout(this.drawTime.bind(this), 60000-(d.getSeconds()*1000)-d.getMilliseconds()); - if (this.TZOffset===undefined || this.TZOffset!==d.getTimezoneOffset()) - this.drawDateAndCal(); - this.TZOffset=d.getTimezoneOffset(); + setTimeout(this.draw.bind(this), 60000-(d.getSeconds()*1000)-d.getMilliseconds()); } /** @@ -90,11 +102,12 @@ class TimeCalClock{ drawDateAndCal(){ d=this.date ? this.date : new Date(); - if (this.tOutD) //abort exisiting - clearTimeout(this.tOutD); - + this.TZOffset=d.getTimezoneOffset(); this.drawDate(); this.drawCal(); + + if (this.tOutD) //abort exisiting + clearTimeout(this.tOutD); this.tOutD=setTimeout(this.drawDateAndCal.bind(this), 86400000-(d.getHours()*24*60*1000)-(d.getMinutes()*60*1000)-d.getSeconds()-d.getMilliseconds()); } @@ -182,13 +195,15 @@ class TimeCalClock{ g.setFontAlign(-1, -1); - const tdyDate=d.getDate(); - const sttngsWdStrt=this.settings().wdStrt>=0 ? this.settings().wdStrt : tdyDate.getDay(); - //draw grid & Headline const dNames = this.ABR_DAY.map((a) => a.length<=2 ? a : a.substr(0, 2)); //force shrt 2 for(var dNo=0; dNo=0 ? (dNo+this.settings().wdStrt)%7 : (dNo+d.getDay()+4)%7; + const dName=dNames[dIdx]; + if (dIdx==0) //sunday colorize txt + g.setColor(this.nrgb[this.settings().suClr]); + else + g.setColor(g.theme.fg); g.drawString(dName, dNo*CELL_W+(CELL_W-g.stringWidth(dName))/2+2, CAL_Y+1); //center Names if(dNo>0) g.drawLine(dNo*CELL_W, CAL_Y, dNo*CELL_W, CAL_Y+CAL_AREA_H-1); @@ -204,8 +219,9 @@ class TimeCalClock{ g.setFont("Vector", DAY_NUM_FONT_SIZE); //write days - const days=7+(7+d.getDay()-sttngsWdStrt)%7;//start day (week before=7 days + days in this week realtive to week start) - var rD=new Date(); + const tdyDate=d.getDate(); + const days=this.settings().wdStrt>=0 ? 7+((7+d.getDay()-this.settings().wdStrt)%7) : 10;//start day (week before=7 days + days in this week realtive to week start) or fixed 7+3 days + var rD=new Date(d.getTime()); rD.setDate(rD.getDate()-days); var rDate=rD.getDate(); for(var y=0; y<3; y++){ @@ -215,7 +231,7 @@ class TimeCalClock{ switch(this.settings().tdyMrkr){ //0:none, 1:circle, 2:rectangle, 3:filled case 1: for(m=1; m<=this.settings().tdyMrkPxl&&mSu, 1->Mo, ... //Issue #1154: weekstart So/Mo, -1 for use today + wdStrt:0, //identical to getDay() 0->Su, 1->Mo, ... //Issue #1154: weekstart So/Mo, -1 for use today - tdyNumClr:0, //0:fg, 1:red=#E00, 2:green=#0E0, 3:blue=#00E + tdyNumClr:3, //0:fg, 1:red=#E00, 2:green=#0E0, 3:blue=#00E tdyMrkr:0, //0:none, 1:circle, 2:rectangle, 3:filled tdyMrkClr:2, //1:red=#E00, 2:green=#0E0, 3:blue=#00E tdyMrkPxl:3, //px - suClr:0, //0:fg, 1:red=#E00, 2:green=#0E0, 3:blue=#00E + suClr:1, //0:fg, 1:red=#E00, 2:green=#0E0, 3:blue=#00E //phColor:"#E00", //public holiday calBrdr:false @@ -41,7 +41,19 @@ class TimeCalClock{ this.centerX = Bangle.appRect.w/2; this.nrgb = [g.theme.fg, "#E00", "#0E0", "#00E"]; //fg, r ,g , b - this.ABR_DAY = require("locale") && require("locale").abday ? require("locale").abday : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; + + this.ABR_DAY=[]; + if (require("locale") && require("locale").dow) + for (let d=0; d<=6; d++) { + var refDay=new Date(); + refDay.setFullYear(1972); + refDay.setMonth(0); + refDay.setDate(2+d); + this.ABR_DAY.push(require("locale").dow(refDay)); + + } + else + this.ABR_DAY=["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; } /** @@ -57,7 +69,10 @@ class TimeCalClock{ **/ draw(){ this.drawTime(); - } + + if (this.TZOffset===undefined || this.TZOffset!==d.getTimezoneOffset()) + this.drawDateAndCal(); + } /** * draw given or current time from date @@ -77,10 +92,7 @@ class TimeCalClock{ g.drawString(("0" + require("locale").time(d, 1)).slice(-5), this.centerX, Y); //.drawRect(Bangle.appRect.x, Y, Bangle.appRect.x2, Y+this.TIME_FONT_SIZE()-7); //DEV-Option - setTimeout(this.drawTime.bind(this), 60000-(d.getSeconds()*1000)-d.getMilliseconds()); - if (this.TZOffset===undefined || this.TZOffset!==d.getTimezoneOffset()) - this.drawDateAndCal(); - this.TZOffset=d.getTimezoneOffset(); + setTimeout(this.draw.bind(this), 60000-(d.getSeconds()*1000)-d.getMilliseconds()); } /** @@ -90,11 +102,12 @@ class TimeCalClock{ drawDateAndCal(){ d=this.date ? this.date : new Date(); - if (this.tOutD) //abort exisiting - clearTimeout(this.tOutD); - + this.TZOffset=d.getTimezoneOffset(); this.drawDate(); this.drawCal(); + + if (this.tOutD) //abort exisiting + clearTimeout(this.tOutD); this.tOutD=setTimeout(this.drawDateAndCal.bind(this), 86400000-(d.getHours()*24*60*1000)-(d.getMinutes()*60*1000)-d.getSeconds()-d.getMilliseconds()); } @@ -182,13 +195,15 @@ class TimeCalClock{ g.setFontAlign(-1, -1); - const tdyDate=d.getDate(); - const sttngsWdStrt=this.settings().wdStrt>=0 ? this.settings().wdStrt : tdyDate.getDay(); - //draw grid & Headline const dNames = this.ABR_DAY.map((a) => a.length<=2 ? a : a.substr(0, 2)); //force shrt 2 for(var dNo=0; dNo=0 ? (dNo+this.settings().wdStrt)%7 : (dNo+d.getDay()+4)%7; + const dName=dNames[dIdx]; + if (dIdx==0) //sunday colorize txt + g.setColor(this.nrgb[this.settings().suClr]); + else + g.setColor(g.theme.fg); g.drawString(dName, dNo*CELL_W+(CELL_W-g.stringWidth(dName))/2+2, CAL_Y+1); //center Names if(dNo>0) g.drawLine(dNo*CELL_W, CAL_Y, dNo*CELL_W, CAL_Y+CAL_AREA_H-1); @@ -204,8 +219,9 @@ class TimeCalClock{ g.setFont("Vector", DAY_NUM_FONT_SIZE); //write days - const days=7+(7+d.getDay()-sttngsWdStrt)%7;//start day (week before=7 days + days in this week realtive to week start) - var rD=new Date(); + const tdyDate=d.getDate(); + const days=this.settings().wdStrt>=0 ? 7+((7+d.getDay()-this.settings().wdStrt)%7) : 10;//start day (week before=7 days + days in this week realtive to week start) or fixed 7+3 days + var rD=new Date(d.getTime()); rD.setDate(rD.getDate()-days); var rDate=rD.getDate(); for(var y=0; y<3; y++){ @@ -215,7 +231,7 @@ class TimeCalClock{ switch(this.settings().tdyMrkr){ //0:none, 1:circle, 2:rectangle, 3:filled case 1: for(m=1; m<=this.settings().tdyMrkPxl&&m","|TEST_SETTINGS|","..."], //TEST_SETTINGS will be replcaed with each current {setting: case} functionNames: ["required, ", "..."], functionParams: ["optional: ","|TEST_SETTINGS|","..."] - } + }; } constructor(data){ @@ -375,7 +390,7 @@ class TestSetting extends Test{ afterExpression: entry.afterExpression||true }; }); - this.constructorParams = data.constructorParams, + this.constructorParams = data.constructorParams; this.functionNames = data.functionNames; this.functionParams = data.functionParams; } @@ -440,14 +455,16 @@ class BangleTestRunner{ this._afterCase(); } this._afterTest(); + this._firstCase(); } + this._exit(); } /** * global prepare - before all test */ _init() { - console.log(new Date().getTime(),">>init"); + console.log(this._nowTime(), ">>init"); this.currentTestNum=-1; this.currentCaseNum=-1; } @@ -456,72 +473,69 @@ class BangleTestRunner{ * before each test */ _beforeTest() { - console.log(new Date(),">>test #" + this.currentTestNum); + console.log(this._nowTime(), ">>test #" + this.currentTestNum); } /** * befor each testcase */ _beforeCase() { - console.log(new Date(),">>case #" + this.currentTestNum + "." + this.currentCaseNum + "/" + (this.currentTest.cases.length-1)); - if (this.currentTest instanceof TestSetting) { - console.log( - this.currentTest.setting + "="+this.currentCase.value+"\n"+ - this.currentCase.beforeTxt ? "testcase: " + this.currentCase.beforeTxt : "" + console.log(this._nowTime(), ">>case #" + this.currentTestNum + "." + this.currentCaseNum + "/" + (this.currentTest.cases.length-1)); + if (this.currentTest instanceof TestSetting) + console.log(this.currentTest.setting+"="+this.currentCase.value+"\n" + +this.currentCase.beforeTxt ? "testcase:"+this.currentCase.beforeTxt : "" ); - } } /** * testcase runner */ _runCase() { - console.log(new Date(), ">>running..."); + console.log(this._nowTime(), ">>running..."); var returns = []; this.currentTest.functionNames.forEach((fName) => { var settings={}; settings[this.currentTest.setting] = this.currentCase.value; var cParams = this.currentTest.constructorParams||[]; - cParams = cParams.map((v) => (v && v instanceof String && v==="|TEST_SETTINGS|") ? settings : v)//replace settings in call params + cParams = cParams.map((v) => (v && v instanceof String && v==="|TEST_SETTINGS|") ? settings : v);//replace settings in call params var fParams = this.currentTest.functionParams||[]; - fParams = fParams.map((v) => (v && v instanceof String && v==="|TEST_SETTINGS|") ? settings : v)//replace settings in call params + fParams = fParams.map((v) => (v && v instanceof String && v==="|TEST_SETTINGS|") ? settings : v);//replace settings in call params - var creatorFunc = new Function("return new " + this.oClass + "(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8],arguments[9])"); //prepare spwan arguments[0],arguments[1] + var creatorFunc = new Function("console.log('Constructor params:', arguments); return new " + this.oClass + "(arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8],arguments[9])"); //prepare spwan arguments[0],arguments[1] let instance = creatorFunc.call(this.oClass, cParams[0], cParams[1], cParams[2], cParams[3], cParams[4], cParams[5], cParams[6], cParams[7], cParams[8], cParams[9]); //spwan console.log(">>"+this.oClass+"["+fName+"]()"); + + console.log('Instance:', instance); + console.log('Function params:', fParams); returns.push(instance[fName](fParams[0], fParams[1], fParams[2], fParams[3], fParams[4], fParams[5], fParams[6], fParams[7], fParams[8], fParams[9])); //run method and store result - console.log("<<"+this.oClass+"["+fName+"]()"); g.dump(); + console.log("<<"+this.oClass+"["+fName+"]()"); }); - console.log(new Date(), "<<...running"); + console.log(this._nowTime(), "<<...running"); } /** * after each testcase */ _afterCase() { - if (this.currentTest instanceof TestSetting) { - if (this.currentCase.afterTxt.length>0) { - console.log( - "--EXPECTED: " + this.currentCase.afterTxt - ); - } - } - console.log(new Date(), "<0) + console.log("++EXPECTED:" + this.currentCase.afterTxt + "EXPECTED++"); + console.log(this._nowTime(), "<=-1 && (this.currentTestNum+1)=-1 && (this.currentCaseNum+1)