day_of_week translated to German

Hi,

once again I found something not working :-)

    private function setDateDisplay() {        
    	var now = Time.now();
	    var date = Date.info(now, Time.FORMAT_LONG);
        var heute = date.day_of_week(); 

        if (heute == "Thu"){
            var Wochentag = "Do";
        }
	    var dateString = Lang.format("$1$, $2$ $3$, $4$", Wochentag, date.day, date.month, date.year]);
	    var dateDisplay = View.findDrawableById("DateDisplay");      
	    dateDisplay.setText(dateString);	    	
    }

Now I wonder:

- why doesn't the if function work (I mean in the debugger I see that "heute" has the Value "Thu" and is a Lang.string

Second try:

Why doesn't the dictionairy work? I must admit that I'm not yet to familiar with them but should work according to 

https://developer.garmin.com/connect-iq/api-docs/Toybox/Lang/Dictionary.html

    private function setDateDisplay() {        
    	var now = Time.now();
	    var date = Date.info(now, Time.FORMAT_LONG);
        var heute = date.day_of_week(); 

        var myDict = {
            "Mon" => "Mo",
            "Tue" => "Di",
            "Wed" => "Mi",
            "Thu" => "Do",
            "Fri" => "Fr",
            "Sat" => "Sa",
            "Son" => "So"
        };

	    var dateString = Lang.format("$1$, $2$ $3$, $4$", [myDict.get(heute), date.day, date.month, date.year]);
	    var dateDisplay = View.findDrawableById("DateDisplay");      
	    dateDisplay.setText(dateString);	    	
    }

Can anybody give me the right solution for 1 and 2?

Mean theoretically they should both work !?!

Regards Marcus

  • Problem 2:
    using Toybox.Time.Gregorian;  // need this at the top of your code

    private function setDateDisplay() {        
            var now = Time.now();
            var date = Gregorian.info(now, Time.FORMAT_LONG);   // use Gregorian.info
            var heute = date.day_of_week;   // this is not a function, but a member variable.

            var myDict = {
                "Mon" => "Mo",
                "Tue" => "Di",
                "Wed" => "Mi",
                "Thu" => "Do",
                "Fri" => "Fr",
                "Sat" => "Sa",
                "Son" => "So"
            };

            var dateString = Lang.format("$1$, $2$ $3$, $4$", [myDict.get(heute), date.day, date.month, date.year]);
            //var dateDisplay = View.findDrawableById("DateDisplay");      
            System.println(dateString);   // this works fine, so the other things should also work now
            //dateDisplay.setText(dateString);          
        } 
    //  for problem #1, you may want to try using myString.equals("ComparisonString") function, rather than the == operator
  • Sorry my mistake. I had that one above all functions

    using Toybox.Time.Gregorian as Date;
    So indeed the only fault were those brackets. The Distionairy part works perfectly fine now. Thakns a lot!!!!
    But with the if statement I really wouldn't have come to this idea.

    But I must have used it wrong cause the following doesn't work. He's unhappy with the Using
        private function setDateDisplay() {        
        	var now = Time.now();
    	    var date = Date.info(now, Time.FORMAT_LONG);
            var heute = date.day_of_week; 
    
            if (using heute.equals("Thu")){
                var Wochentag = "Do";
            }
            var dateString = Lang.format("$1$, $2$ $3$, $4$", [Wochentag, date.day, date.month, date.year]);
    	    var dateDisplay = View.findDrawableById("DateDisplay");      
    	    dateDisplay.setText(dateString);	    	
        }
  • for future:

    if (heute == "Thu") doesn't run because heute is the string you have to use heute .equals("Thu")

  • Ahhh now I got it. Thanks a lot to all of you guys.

    Looks like it's time for bed now :-)))

    That's how the critical part worked:

    var Wochentag ="Hallo";

            if (heute.equals("Thu")){
                Wochentag = "Do";
            }
            var dateString = Lang.format("$1$, $2$ $3$, $4$", [Wochentag, date.day, date.month, date.year]);
  • yes I hope you don't use setdateDisplay  every second :)

  • If you use a custom font for this, it can get tricky as you have to make sure it includes all the characters that are needed. It shouldn't be an issue if you use a native font.

  • Until you told me I did :-))))

    I mean I know how to change - but does this have any effect on battery life?

    I guess no cause nothing is changed on the display but instead if I add a function to check and only write a new date when it changes causes more code => calc effort. Right?

  • Hi Jim,

    I'll be using native fonts - so no problem there. But thanks a lot for the hint!

    Regards Marcus

  • In onUpdate() you always want to update the whole display.  The only time you can safely update only part of the screen is with onPartialUpdate.

    On some devices, the screen is cleared before onUpdate() is called, on others, a notification may cover part of the screen and you don't know what needs to be redrawn, etc.

  • every line of code has influence on memory and battery, specially those that are not needed :-)

    run profiler and see and will know instead of thinking and multiply it by x60x60x24 x day you expect wf to run

    you use findDrawable... and If you put this code into onPartialUpdate power budget rather will be exceeded

    and what happen if user use French language? another function? and 40 other languages? and checking 40 if/else to find

    1. first current language... and second

    2. 7 if/else to find correct day?

    btw, you can obtain day of week as number and it's rather easier and faster to translate and your code with only == well run