Hi,
I'm creating a function that should generate a week number.
I can't draw it, where am I making a mistake, please?
Hi,
I'm creating a function that should generate a week number.
I can't draw it, where am I making a mistake, please?
This is my original code that I wanted to change:
Hmm, that's not what I saw in your OP before. Maybe it was edited by accident?
I saw
var currWeek = getCurrentWeekNumber;
But that explains…
Okay, so define the string for week number in your resources, very similar to the above example:
resource-eng:
<strings>
<string id="WeekNumber">WeekDay</string>
</strings…
No problem!
I will say that "WeekDay" is probably not the correct string in English. "Week day" means day of the week (Monday, Tuesday, etc.)
In this case I would go with "Week". (On…
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:
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.
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:
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:
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.
Someone else answered this question 5 years ago