Week number...

Hi,

I'm creating a function that should generate a week number.

I can't draw it, where am I making a mistake, please?

  • Your drawText is wrong. it's (x,y,font,string,justify)

  • You have too many parameters.  See the API doc.

  • You have too many parameters.  See the API doc.

    Unless they edited their post after you commented, their call to dc.drawText actually has the correct number of  parameters.

    I'm creating a function that should generate a week number.

    I can't draw it, where am I making a mistake, please?

    Does your app print "method" in the middle of the screen, like this?

    That's because your function for drawing the current week number is called getCurrentWeekNumber(), but within the same function you've got this:

        var currWeek = getCurrentWeekNumber; // <======
        dc.setColor(Graphics.COLOR_GREEN,Graphics.COLOR_BLACK);
        dc.drawText(x, y, $.fontTest, currWeek, Graphics.TEXT_JUSTIFY_CENTER);

    I think you wanted to do something with year_duration to determine the current week number.

    e.g.

          var currWeek = year_duration.value() / (3600*24) / 7 + 1; // year_duration.value() is in seconds

    Except this doesn't really work either, because that's not how the week number is calculated/defined. You probably want to use the official ISO standard definition of "week number".

    https://en.wikipedia.org/wiki/ISO_8601

    There are several mutually equivalent and compatible descriptions of week 01:

    • the week with the starting year's first Thursday in it (the formal ISO definition),
    • the week with 4 January in it,
    • the first week with the majority (four or more) of its days in the starting year, and
    • the week starting with the Monday in the period 29 December - 4 January.

    As a consequence, if 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year (there is no week 00). 28 December is always in the last week of its year.

    The week number can be described by counting the Thursdays: week 12 contains the 12th Thursday of the year.

  • Hello.

    Thank you for the advice, this was the mistake and now it works.

    var currWeek = year_duration.value() / (3600*24) / 7 + 1; // year_duration.value() is in seconds;

  • No problem!

    But like I said, that gives you "a" week number, but not "the" week number.

    If you want your week number to match the week number that everyone else uses, you have to use the standard definition of week number:

    [https://en.wikipedia.org/wiki/ISO_8601#Week_dates]

  • Standard resolution?
    I thought I wrote it right.

    So how do you always seem to agree?

  • The example code I gave was based on what I *guessed* you were trying to do.

    But the standard definition of week number is what I posted above:

    https://en.wikipedia.org/wiki/ISO_8601#Week_dates

    There are several mutually equivalent and compatible descriptions of week 01:

    • the week with the starting year's first Thursday in it (the formal ISO definition),
    • the week with 4 January in it,
    • the first week with the majority (four or more) of its days in the starting year, and
    • the week starting with the Monday in the period 29 December - 4 January.

    As a consequence, if 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year (there is no week 00). 28 December is always in the last week of its year.

    The week number can be described by counting the Thursdays: week 12 contains the 12th Thursday of the year.

    The ISO week-numbering year starts at the first day (Monday) of week 01 and ends at the Sunday before the new ISO year (hence without overlap or gap). It consists of 52 or 53 full weeks. The first ISO week of a year may have up to three days that are actually in the Gregorian calendar year that is ending; if three, they are Monday, Tuesday and Wednesday. Similarly, the last ISO week of a year may have up to three days that are actually in the Gregorian calendar year that is starting; if three, they are Friday, Saturday, and Sunday. The Thursday of each ISO week is always in the Gregorian calendar year denoted by the ISO week-numbering year.

    For example, if January 1 is a Friday, then week 1 starts on Monday, January 4.

    The idea here is that ISO weeks always start on Monday.

  • I understand that, but now I'm not sure how to adjust it so that I always get the correct number of the week ...?

  • Someone else answered this question 5 years ago Slight smile

    forums.garmin.com/.../27615

  • var today = new Time.Moment(Time.today().value() + Sys.getClockTime().timeZoneOffset);
    
    		var options = {
    		    :year   => Gregorian.info(today, Time.FORMAT_SHORT).year,
    		    :month  => 1,
    		    :day    => 1,
    		    :hour   => 0,
    		    :min    => 0,
    		    :sec    => 0
    		};