# weeks calculation

I could not find on dhis2 docs so I am asking:

How dhis2 calculate the weeks? The first week of a year for example.

Thank you
Caveman

Hi Caveman,

···

----- Original Message ----
From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
Sent: Monday, May 11, 2009 2:57:42 AM
Subject: [Dhis2-devs] weeks calculation

I could not find on dhis2 docs so I am asking:

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date of the given week is on the previous year, end date of that period is used. Also Saturday is used as first day of the week.

Thank you
Caveman

_______________________________________________

Thanks!

That is really usefull.

Caveman

Murodullo Latifov wrote:

···

Hi Caveman,

----- Original Message ----
From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
Sent: Monday, May 11, 2009 2:57:42 AM
Subject: [Dhis2-devs] weeks calculation

I could not find on dhis2 docs so I am asking:

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date of the given week is on the previous year, end date of that period is used. Also Saturday is used as first day of the week.

Thank you
Caveman

_______________________________________________

Hi

Hi Caveman,

From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
Sent: Monday, May 11, 2009 2:57:42 AM
Subject: [Dhis2-devs] weeks calculation

I could not find on dhis2 docs so I am asking:

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date of the given week is on the previous year, end date of that period is used. Also
Saturday is used as first day of the week.

The code is here:
./dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java

I find it a bit confusing. It seems that we try to define a week as
Saturday to Friday, and then say that as long as the endDate is in a
different year to the startDate then we are in week 1. So week 1 is
the first week in the year with a Friday in it? This doesn't sound
right. Also according to documentation on top of class, a weekly
period must have a startDate on a Monday and endDate on a Sunday.

But week numbers according to ISO8601 are equivalent to the number of
Thursdays - ie. first week in the year with a Thursday is week 1.
This is the way that, for example the javascript in the calendar.js
would calculate it. And presumably any sql week function we might
use. Also weeks would start on Monday (which agrees with our class
documentation).

So for the week of 29/12/2008 to 04/01/2009, by our calculation that
would be week 1 of 2009. And it would be week 1 by ISO 8601.

But for the week of 28/12/2009 to 3/01/2010 which is coming up, our
calculation would have this as week 1 of 2010, whereas ISO8601 would
have it as week 52 or 53 of 2010. Week 1 would be the week of
04/01/2010.

As I say - its a bit confusing.

Though perhaps in the end the actual week number doesn't matter. What
might matter most is the convention we consistently adopt and
document. Though it would be nice if our conception of week 1
coincided with the ISO8601 conception. But not so nice as to break
all the annual reports ... Do we ever exchange a week number with
another system? Do we need to be able to define this more flexibly to
accomodate different national reporting requirements which might
interpret the first week of the year differently? I haven't even
begun to think of this in terms of localised calendar systems

Regards
Bob

···

2009/5/11 Murodullo Latifov <murodlatifov@yahoo.com>:

----- Original Message ----

Thank you
Caveman

_______________________________________________

_______________________________________________

Well this comment is interesting.

And the question raises from my needs here. I am moving data from a not dhis2 system to dhis2. And we must do it weekly because dhis2 is not yet adopted.

I noticed that I had weeks changed on dhis2.

And now to adjust to dhis2 I need to know how dhis2 does. And Bob raises this. What I do? I use the algorithm from that java Class?

Caveman

Bob Jolliffe wrote:

···

Hi

2009/5/11 Murodullo Latifov <murodlatifov@yahoo.com>:

Hi Caveman,

----- Original Message ----
From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
Sent: Monday, May 11, 2009 2:57:42 AM
Subject: [Dhis2-devs] weeks calculation

I could not find on dhis2 docs so I am asking:

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date of the given week is on the previous year, end date of that period is used. Also
Saturday is used as first day of the week.

The code is here:
./dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java

I find it a bit confusing. It seems that we try to define a week as
Saturday to Friday, and then say that as long as the endDate is in a
different year to the startDate then we are in week 1. So week 1 is
the first week in the year with a Friday in it? This doesn't sound
right. Also according to documentation on top of class, a weekly
period must have a startDate on a Monday and endDate on a Sunday.

But week numbers according to ISO8601 are equivalent to the number of
Thursdays - ie. first week in the year with a Thursday is week 1.
This is the way that, for example the javascript in the calendar.js
would calculate it. And presumably any sql week function we might
use. Also weeks would start on Monday (which agrees with our class
documentation).

So for the week of 29/12/2008 to 04/01/2009, by our calculation that
would be week 1 of 2009. And it would be week 1 by ISO 8601.

But for the week of 28/12/2009 to 3/01/2010 which is coming up, our
calculation would have this as week 1 of 2010, whereas ISO8601 would
have it as week 52 or 53 of 2010. Week 1 would be the week of
04/01/2010.

As I say - its a bit confusing.

Though perhaps in the end the actual week number doesn't matter. What
might matter most is the convention we consistently adopt and
document. Though it would be nice if our conception of week 1
coincided with the ISO8601 conception. But not so nice as to break
all the annual reports ... Do we ever exchange a week number with
another system? Do we need to be able to define this more flexibly to
accomodate different national reporting requirements which might
interpret the first week of the year differently? I haven't even
begun to think of this in terms of localised calendar systems

Regards
Bob

Thank you
Caveman

_______________________________________________

_______________________________________________

Hi Orvalho

Well this comment is interesting.

And the question raises from my needs here. I am moving data from a not
dhis2 system to dhis2. And we must do it weekly because dhis2 is not yet

I noticed that I had weeks changed on dhis2.

Do you have some examples? i.e. ones which show that week 1 is
indicated as something specific for a particular year which is
different to the DHIS2 way. Then maybe we can start thinking about
how DHIS2 should best handle. Is your data coming from Excel?

Regards
Bob

PS. I see mysql makes use of a mode argument
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_week
I guess ISO8601 mode would be mode 3 under this scheme.

PPS. Excel does not have a weeknum function built in. There is an
analysis toolpack plugin which implements something non-standard -
somteimes described as the US norm - the first week (like other weeks)
ends on Sunday. It can be any number of days long from 1 to 7.

PPPS. David Wheeler has done some excellent work on the OpenFormula
SubCommittee of the ODF OASIS TC on figuring out the differences
between all these. It looks like ODF will eventually adopt two
functions WEEKNUM (which implements the incorrect Excel algorithm) and
ISO_WEEKNUM which implements the correct algorithm.

···

2009/5/11 Orvalho Joaquim Augusto <orvaquim@gmail.com>:

And now to adjust to dhis2 I need to know how dhis2 does. And Bob raises
this. What I do? I use the algorithm from that java Class?

Caveman

Bob Jolliffe wrote:

Hi

2009/5/11 Murodullo Latifov <murodlatifov@yahoo.com>:

Hi Caveman,

----- Original Message ----
From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
Sent: Monday, May 11, 2009 2:57:42 AM
Subject: [Dhis2-devs] weeks calculation

I could not find on dhis2 docs so I am asking:

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date of
the given week is on the previous year, end date of that period is used.
Also
Saturday is used as first day of the week.

The code is here:
./dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java

I find it a bit confusing. It seems that we try to define a week as
Saturday to Friday, and then say that as long as the endDate is in a
different year to the startDate then we are in week 1. So week 1 is
the first week in the year with a Friday in it? This doesn't sound
right. Also according to documentation on top of class, a weekly
period must have a startDate on a Monday and endDate on a Sunday.

But week numbers according to ISO8601 are equivalent to the number of
Thursdays - ie. first week in the year with a Thursday is week 1.
This is the way that, for example the javascript in the calendar.js
would calculate it. And presumably any sql week function we might
use. Also weeks would start on Monday (which agrees with our class
documentation).

So for the week of 29/12/2008 to 04/01/2009, by our calculation that
would be week 1 of 2009. And it would be week 1 by ISO 8601.

But for the week of 28/12/2009 to 3/01/2010 which is coming up, our
calculation would have this as week 1 of 2010, whereas ISO8601 would
have it as week 52 or 53 of 2010. Week 1 would be the week of
04/01/2010.

As I say - its a bit confusing.

Though perhaps in the end the actual week number doesn't matter. What
might matter most is the convention we consistently adopt and
document. Though it would be nice if our conception of week 1
coincided with the ISO8601 conception. But not so nice as to break
all the annual reports ... Do we ever exchange a week number with
another system? Do we need to be able to define this more flexibly to
accomodate different national reporting requirements which might
interpret the first week of the year differently? I haven't even
begun to think of this in terms of localised calendar systems

Regards
Bob

Thank you
Caveman

_______________________________________________

_______________________________________________

Bob Jolliffe wrote:

Hi Orvalho

Well this comment is interesting.

And the question raises from my needs here. I am moving data from a not
dhis2 system to dhis2. And we must do it weekly because dhis2 is not yet

I noticed that I had weeks changed on dhis2.

Do you have some examples? i.e. ones which show that week 1 is
indicated as something specific for a particular year which is
different to the DHIS2 way. Then maybe we can start thinking about
how DHIS2 should best handle. Is your data coming from Excel?

It is not Excel.

Some physiology of what we have:
The System being used now is called Modulo Basico (modbas for now on). That system is in MsAccess. It stores data for each form in one table. The table contains for record identification these fields (all in strings): year (YR), week (MTH, it is no mistake), district code (DC), province code (PC) and health center (HC).

The data comens on diferent columns identified by A1, A2 up to An (depending on the form).

As this is what Ministry of Health uses and dhis2 is being prepared to be used in large scale we feed dhis2 using some rudimentar steps:
1. There is a scheduled program per day to convert the tables in MDB
in modbas to mysql (db2sync instead of mysql migration tool because db2syn exports well the keys)
2. Under the mysql server machine there is a python script that take data feeds dhis2 tables.

Step 2 uses periodid generated by dhis2 using the ranges.

For the months this is fine. But for weeks we need to know which week is based on the ranges given by periodid.

Is this clear enough?

And do you need really data to check?

Regards
Bob

PS. I see mysql makes use of a mode argument
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_week
I guess ISO8601 mode would be mode 3 under this scheme.

Thanks.

But on dhis2 it seems different isn't that?

Regards
Caveman

···

2009/5/11 Orvalho Joaquim Augusto <orvaquim@gmail.com>:

PPS. Excel does not have a weeknum function built in. There is an
analysis toolpack plugin which implements something non-standard -
somteimes described as the US norm - the first week (like other weeks)
ends on Sunday. It can be any number of days long from 1 to 7.

PPPS. David Wheeler has done some excellent work on the OpenFormula
SubCommittee of the ODF OASIS TC on figuring out the differences
between all these. It looks like ODF will eventually adopt two
functions WEEKNUM (which implements the incorrect Excel algorithm) and
ISO_WEEKNUM which implements the correct algorithm.

And now to adjust to dhis2 I need to know how dhis2 does. And Bob raises
this. What I do? I use the algorithm from that java Class?

Caveman

Bob Jolliffe wrote:

Hi

2009/5/11 Murodullo Latifov <murodlatifov@yahoo.com>:

Hi Caveman,

----- Original Message ----
From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
Sent: Monday, May 11, 2009 2:57:42 AM
Subject: [Dhis2-devs] weeks calculation

I could not find on dhis2 docs so I am asking:

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date of
the given week is on the previous year, end date of that period is used.
Also
Saturday is used as first day of the week.

The code is here:
./dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java

I find it a bit confusing. It seems that we try to define a week as
Saturday to Friday, and then say that as long as the endDate is in a
different year to the startDate then we are in week 1. So week 1 is
the first week in the year with a Friday in it? This doesn't sound
right. Also according to documentation on top of class, a weekly
period must have a startDate on a Monday and endDate on a Sunday.

But week numbers according to ISO8601 are equivalent to the number of
Thursdays - ie. first week in the year with a Thursday is week 1.
This is the way that, for example the javascript in the calendar.js
would calculate it. And presumably any sql week function we might
use. Also weeks would start on Monday (which agrees with our class
documentation).

So for the week of 29/12/2008 to 04/01/2009, by our calculation that
would be week 1 of 2009. And it would be week 1 by ISO 8601.

But for the week of 28/12/2009 to 3/01/2010 which is coming up, our
calculation would have this as week 1 of 2010, whereas ISO8601 would
have it as week 52 or 53 of 2010. Week 1 would be the week of
04/01/2010.

As I say - its a bit confusing.

Though perhaps in the end the actual week number doesn't matter. What
might matter most is the convention we consistently adopt and
document. Though it would be nice if our conception of week 1
coincided with the ISO8601 conception. But not so nice as to break
all the annual reports ... Do we ever exchange a week number with
another system? Do we need to be able to define this more flexibly to
accomodate different national reporting requirements which might
interpret the first week of the year differently? I haven't even
begun to think of this in terms of localised calendar systems

Regards
Bob

Thank you
Caveman

_______________________________________________

_______________________________________________

Bob Jolliffe wrote:

Hi Orvalho

Well this comment is interesting.

And the question raises from my needs here. I am moving data from a not
dhis2 system to dhis2. And we must do it weekly because dhis2 is not yet

I noticed that I had weeks changed on dhis2.

Do you have some examples? i.e. ones which show that week 1 is
indicated as something specific for a particular year which is
different to the DHIS2 way. Then maybe we can start thinking about
how DHIS2 should best handle. Is your data coming from Excel?

It is not Excel.

Some physiology of what we have:
The System being used now is called Modulo Basico (modbas for now on). That
system is in MsAccess. It stores data for each form in one table. The table
contains for record identification these fields (all in strings): year (YR),
week (MTH, it is no mistake), district code (DC), province code (PC) and
health center (HC).

The data comens on diferent columns identified by A1, A2 up to An (depending
on the form).

As this is what Ministry of Health uses and dhis2 is being prepared to be
used in large scale we feed dhis2 using some rudimentar steps:
1. There is a scheduled program per day to convert the tables in MDB
in modbas to mysql (db2sync instead of mysql migration tool because db2syn
exports well the keys)
2. Under the mysql server machine there is a python script that take data
feeds dhis2 tables.

Step 2 uses periodid generated by dhis2 using the ranges.

For the months this is fine. But for weeks we need to know which week is
based on the ranges given by periodid.

Is this clear enough?

And do you need really data to check?

No I don't need lots of data. Just something like year 2005 (weeks
are ok), 2006 (dhis is one week ahead), 2007 (weeks are ok) .... I am
just trying to figure out the problem and what weeknumber system your
system (and DHIS2) is using. Empirically like this is the easiest.

Cheers
Bob

···

2009/5/11 Orvalho Joaquim Augusto <orvaquim@gmail.com>:

2009/5/11 Orvalho Joaquim Augusto <orvaquim@gmail.com>:

Regards
Bob

PS. I see mysql makes use of a mode argument

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_week
I guess ISO8601 mode would be mode 3 under this scheme.

Thanks.

But on dhis2 it seems different isn't that?

Regards
Caveman

PPS. Excel does not have a weeknum function built in. There is an
analysis toolpack plugin which implements something non-standard -
somteimes described as the US norm - the first week (like other weeks)
ends on Sunday. It can be any number of days long from 1 to 7.

PPPS. David Wheeler has done some excellent work on the OpenFormula
SubCommittee of the ODF OASIS TC on figuring out the differences
between all these. It looks like ODF will eventually adopt two
functions WEEKNUM (which implements the incorrect Excel algorithm) and
ISO_WEEKNUM which implements the correct algorithm.

And now to adjust to dhis2 I need to know how dhis2 does. And Bob raises
this. What I do? I use the algorithm from that java Class?

Caveman

Bob Jolliffe wrote:

Hi

2009/5/11 Murodullo Latifov <murodlatifov@yahoo.com>:

Hi Caveman,

----- Original Message ----
From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
Sent: Monday, May 11, 2009 2:57:42 AM
Subject: [Dhis2-devs] weeks calculation

I could not find on dhis2 docs so I am asking:

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date
of
the given week is on the previous year, end date of that period is
used.
Also
Saturday is used as first day of the week.

The code is here:
./dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java

I find it a bit confusing. It seems that we try to define a week as
Saturday to Friday, and then say that as long as the endDate is in a
different year to the startDate then we are in week 1. So week 1 is
the first week in the year with a Friday in it? This doesn't sound
right. Also according to documentation on top of class, a weekly
period must have a startDate on a Monday and endDate on a Sunday.

But week numbers according to ISO8601 are equivalent to the number of
Thursdays - ie. first week in the year with a Thursday is week 1.
This is the way that, for example the javascript in the calendar.js
would calculate it. And presumably any sql week function we might
use. Also weeks would start on Monday (which agrees with our class
documentation).

So for the week of 29/12/2008 to 04/01/2009, by our calculation that
would be week 1 of 2009. And it would be week 1 by ISO 8601.

But for the week of 28/12/2009 to 3/01/2010 which is coming up, our
calculation would have this as week 1 of 2010, whereas ISO8601 would
have it as week 52 or 53 of 2010. Week 1 would be the week of
04/01/2010.

As I say - its a bit confusing.

Though perhaps in the end the actual week number doesn't matter. What
might matter most is the convention we consistently adopt and
document. Though it would be nice if our conception of week 1
coincided with the ISO8601 conception. But not so nice as to break
all the annual reports ... Do we ever exchange a week number with
another system? Do we need to be able to define this more flexibly to
accomodate different national reporting requirements which might
interpret the first week of the year differently? I haven't even
begun to think of this in terms of localised calendar systems

Regards
Bob

Thank you
Caveman

_______________________________________________

_______________________________________________

Ahh..

Thanks
Caveman

Bob Jolliffe wrote:

···

2009/5/11 Orvalho Joaquim Augusto <orvaquim@gmail.com>:

Bob Jolliffe wrote:

Hi Orvalho

2009/5/11 Orvalho Joaquim Augusto <orvaquim@gmail.com>:

Well this comment is interesting.

And the question raises from my needs here. I am moving data from a not
dhis2 system to dhis2. And we must do it weekly because dhis2 is not yet

I noticed that I had weeks changed on dhis2.

Do you have some examples? i.e. ones which show that week 1 is
indicated as something specific for a particular year which is
different to the DHIS2 way. Then maybe we can start thinking about
how DHIS2 should best handle. Is your data coming from Excel?

It is not Excel.

Some physiology of what we have:
The System being used now is called Modulo Basico (modbas for now on). That
system is in MsAccess. It stores data for each form in one table. The table
contains for record identification these fields (all in strings): year (YR),
week (MTH, it is no mistake), district code (DC), province code (PC) and
health center (HC).

The data comens on diferent columns identified by A1, A2 up to An (depending
on the form).

As this is what Ministry of Health uses and dhis2 is being prepared to be
used in large scale we feed dhis2 using some rudimentar steps:
1. There is a scheduled program per day to convert the tables in MDB
in modbas to mysql (db2sync instead of mysql migration tool because db2syn
exports well the keys)
2. Under the mysql server machine there is a python script that take data
feeds dhis2 tables.

Step 2 uses periodid generated by dhis2 using the ranges.

For the months this is fine. But for weeks we need to know which week is
based on the ranges given by periodid.

Is this clear enough?

And do you need really data to check?

No I don't need lots of data. Just something like year 2005 (weeks
are ok), 2006 (dhis is one week ahead), 2007 (weeks are ok) .... I am
just trying to figure out the problem and what weeknumber system your
system (and DHIS2) is using. Empirically like this is the easiest.

Cheers
Bob

Regards
Bob

PS. I see mysql makes use of a mode argument

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_week
I guess ISO8601 mode would be mode 3 under this scheme.

Thanks.

But on dhis2 it seems different isn't that?

Regards
Caveman

PPS. Excel does not have a weeknum function built in. There is an
analysis toolpack plugin which implements something non-standard -
somteimes described as the US norm - the first week (like other weeks)
ends on Sunday. It can be any number of days long from 1 to 7.

PPPS. David Wheeler has done some excellent work on the OpenFormula
SubCommittee of the ODF OASIS TC on figuring out the differences
between all these. It looks like ODF will eventually adopt two
functions WEEKNUM (which implements the incorrect Excel algorithm) and
ISO_WEEKNUM which implements the correct algorithm.

And now to adjust to dhis2 I need to know how dhis2 does. And Bob raises
this. What I do? I use the algorithm from that java Class?

Caveman

Bob Jolliffe wrote:

Hi

2009/5/11 Murodullo Latifov <murodlatifov@yahoo.com>:

Hi Caveman,

----- Original Message ----
From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
Sent: Monday, May 11, 2009 2:57:42 AM
Subject: [Dhis2-devs] weeks calculation

I could not find on dhis2 docs so I am asking:

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date
of
the given week is on the previous year, end date of that period is
used.
Also
Saturday is used as first day of the week.

The code is here:
./dhis-api/src/main/java/org/hisp/dhis/period/WeeklyPeriodType.java

I find it a bit confusing. It seems that we try to define a week as
Saturday to Friday, and then say that as long as the endDate is in a
different year to the startDate then we are in week 1. So week 1 is
the first week in the year with a Friday in it? This doesn't sound
right. Also according to documentation on top of class, a weekly
period must have a startDate on a Monday and endDate on a Sunday.

But week numbers according to ISO8601 are equivalent to the number of
Thursdays - ie. first week in the year with a Thursday is week 1.
This is the way that, for example the javascript in the calendar.js
would calculate it. And presumably any sql week function we might
use. Also weeks would start on Monday (which agrees with our class
documentation).

So for the week of 29/12/2008 to 04/01/2009, by our calculation that
would be week 1 of 2009. And it would be week 1 by ISO 8601.

But for the week of 28/12/2009 to 3/01/2010 which is coming up, our
calculation would have this as week 1 of 2010, whereas ISO8601 would
have it as week 52 or 53 of 2010. Week 1 would be the week of
04/01/2010.

As I say - its a bit confusing.

Though perhaps in the end the actual week number doesn't matter. What
might matter most is the convention we consistently adopt and
document. Though it would be nice if our conception of week 1
coincided with the ISO8601 conception. But not so nice as to break
all the annual reports ... Do we ever exchange a week number with
another system? Do we need to be able to define this more flexibly to
accomodate different national reporting requirements which might
interpret the first week of the year differently? I haven't even
begun to think of this in terms of localised calendar systems

Regards
Bob

Thank you
Caveman

_______________________________________________

_______________________________________________

Hi cave persons

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date of the given week is on the previous year, end date of that period is used. Also Saturday is used as first day of the week.

It seem this business of Saturdays is a red herring and is not true.
Weekly periods are defined by a start date being a Monday and an end
date being a Sunday (though this doesn't seem to be enforced anywhere
- it probably should be). We can see this in the list of periods
which are calculated in generatePeriods in WeeklyPeriodType.java. The
list are all all Monday-Sunday periods.

It is however a bit buggy. What I can confirm from generating loads
of period lists from various starting dates is
1. DHIS (using the java default) does indeed have an ISO8601
interpretation of week number. That is the first week of any given
year is a the first week with a Thursday in it. It is good we stick
with this. Makes it easy to answer the question "how does DHIS2
handle week numbers?".
2. Perhaps somebody who initially wrote this code seemed not quite to
appreciate how this works, which means, for example, that when we
generate the period list for the week of 29-12-2009 to 03-01-2010 we
end up with a list starting with week 1 of 2010, which doesn't
actually include the given week. The same thing happens in the end of
2005.

I don't know if this is at the root of Orvalho's problem (I haven't
yet seen his data), but it is clearly important when moving weekly
data from one system to another. Meanwhile I can fix the
generatePeriods method so that it will always generate the correct
list of periods for any given period. Before I do so please confirm
that it will not break any existing data, reports or what have you.
The implication being that generatePeriods called on the week of
29-12-2009 to 03-01-2010 will generate the list of weeks for 2009, not
2010. And more obviously, the week of 26-12-2005 to 1-01-2006
generates the list of weeks for 2005, not 2006.

Cheers
Bob

···

2009/5/11 Murodullo Latifov <murodlatifov@yahoo.com>:

Hi Bob,

···

----- Original Message ----
From: Bob Jolliffe <bobjolliffe@gmail.com>
Sent: Tuesday, May 12, 2009 12:52:58 PM
Subject: Re: [Dhis2-devs] weeks calculation

Hi cave persons

2009/5/11 Murodullo Latifov <murodlatifov@yahoo.com>:

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date of the given week is on the previous year, end date of that period is used. Also Saturday is used as first day of the week.

It seem this business of Saturdays is a red herring and is not true.
Weekly periods are defined by a start date being a Monday and an end
date being a Sunday (though this doesn't seem to be enforced anywhere
- it probably should be). We can see this in the list of periods
which are calculated in generatePeriods in WeeklyPeriodType.java. The
list are all all Monday-Sunday periods.

It is however a bit buggy. What I can confirm from generating loads
of period lists from various starting dates is
1. DHIS (using the java default) does indeed have an ISO8601
interpretation of week number. That is the first week of any given
year is a the first week with a Thursday in it. It is good we stick
with this. Makes it easy to answer the question "how does DHIS2
handle week numbers?".
2. Perhaps somebody who initially wrote this code seemed not quite to
appreciate how this works, which means, for example, that when we
generate the period list for the week of 29-12-2009 to 03-01-2010 we
end up with a list starting with week 1 of 2010, which doesn't
actually include the given week. The same thing happens in the end of
2005.

I don't know if this is at the root of Orvalho's problem (I haven't
yet seen his data), but it is clearly important when moving weekly
data from one system to another. Meanwhile I can fix the
generatePeriods method so that it will always generate the correct
list of periods for any given period. Before I do so please confirm
that it will not break any existing data, reports or what have you.
The implication being that generatePeriods called on the week of
29-12-2009 to 03-01-2010 will generate the list of weeks for 2009, not
2010. And more obviously, the week of 26-12-2005 to 1-01-2006
generates the list of weeks for 2005, not 2006.

Cheers
Bob

I think you can modify code to work correctly as long as it does not change start and end date generated in period table. DHIS weeks start at Sunday and end by Saturday, at least in Mozambique database, how did you come to Monday - Sunday?

regards,
murod

I think you can modify code to work correctly as long as it does not change start and end date generated in period table. DHIS weeks start at Sunday and end by Saturday, at least in Mozambique database, how did you come to Monday - Sunday?

regards,
murod

From WeeklyPeriodType.java in dhis-api (excuse all the ^M's):

// ---------------------------------------------------------------------^M
// Generate weeks^M
// ---------------------------------------------------------------------^M
^M
cal.set( Calendar.WEEK_OF_YEAR, 1 );^M
cal.set( Calendar.DAY_OF_WEEK, Calendar.MONDAY );^M
^M
int firstWeek = cal.get( Calendar.WEEK_OF_YEAR );^M
^M
ArrayList<Period> weeks = new ArrayList<Period>();^M
^M
Date startDate = cal.getTime();^M
weeks.add( new Period( this, startDate, cal.getTime() ) );^M
^M
while ( cal.get( Calendar.WEEK_OF_YEAR ) != firstWeek )^M
{^M
startDate = cal.getTime();^M
weeks.add( new Period( this, startDate, cal.getTime() ) );^M
}^M

So you see - cal.set( Calendar.DAY_OF_WEEK, Calendar.MONDAY );. All
weekly periods start on a Monday. I've dumped these and verified.

Or is the period table being generated from somewhere else?

Regards
Bob

Well

Bob Jolliffe wrote:

Hi cave persons

How dhis2 calculate the weeks? The first week of a year for example.

Weekly periods are calculated based on their start date. If start date of the given week is on the previous year, end date of that period is used. Also Saturday is used as first day of the week.

It seem this business of Saturdays is a red herring and is not true.
Weekly periods are defined by a start date being a Monday and an end
date being a Sunday (though this doesn't seem to be enforced anywhere
- it probably should be). We can see this in the list of periods
which are calculated in generatePeriods in WeeklyPeriodType.java. The
list are all all Monday-Sunday periods.

It is however a bit buggy. What I can confirm from generating loads
of period lists from various starting dates is
1. DHIS (using the java default) does indeed have an ISO8601
interpretation of week number. That is the first week of any given
year is a the first week with a Thursday in it. It is good we stick
with this. Makes it easy to answer the question "how does DHIS2
handle week numbers?".
2. Perhaps somebody who initially wrote this code seemed not quite to
appreciate how this works, which means, for example, that when we
generate the period list for the week of 29-12-2009 to 03-01-2010 we
end up with a list starting with week 1 of 2010, which doesn't
actually include the given week. The same thing happens in the end of
2005.

I don't know if this is at the root of Orvalho's problem (I haven't
yet seen his data), but it is clearly important when moving weekly
data from one system to another. Meanwhile I can fix the
generatePeriods method so that it will always generate the correct
list of periods for any given period. Before I do so please confirm
that it will not break any existing data, reports or what have you.
The implication being that generatePeriods called on the week of
29-12-2009 to 03-01-2010 will generate the list of weeks for 2009, not
2010. And more obviously, the week of 26-12-2005 to 1-01-2006
generates the list of weeks for 2005, not 2006.

Yes this a problem for us. Because we expect to use correctly DHIS [reporting tools for now] and we need to map exactly the periods from the actual system to DHIS.

But meanwhile there is a another problem with a lot of empty data on that system. Mine foucus has been on that and I forgot for a while these dateweeks troubles.

Anyway, can you corect the DHIS2 code please to calculate weekdates? If it is buggy.

Cheers
Bob

_______________________________________________

Regards
Caveman

···

2009/5/11 Murodullo Latifov <murodlatifov@yahoo.com>:

Hi Caveman,

···

----- Original Message ----
From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
To: Bob Jolliffe <bobjolliffe@gmail.com>
Sent: Tuesday, May 12, 2009 2:08:43 PM
Subject: Re: [Dhis2-devs] weeks calculation

Well

Yes this a problem for us. Because we expect to use correctly DHIS [reporting tools for now] and we need to map exactly the periods from the actual system to DHIS.

But meanwhile there is a another problem with a lot of empty data on that system. Mine foucus has been on that and I forgot for a while these dateweeks troubles.

Anyway, can you corect the DHIS2 code please to calculate weekdates? If it is buggy.

Regards
Caveman

Are current periods in Mozambican database generated by DHIS or they are also imported from elsewhere?

murod
_______________________________________________

Its bad to re-invent the wheel, but I think we just keep doing that all the time. The Java API has all these things built-in, but we seem to have our own conventions for everything…
The Calender class does all the good work with enough locale specific things…

http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#getFirstDayOfWeek()

···

Regards,

Saptarshi PURKAYASTHA

Director R & D, HISP India
Health Information Systems Programme

My Tech Blog: http://sunnytalkstech.blogspot.com
You Live by CHOICE, Not by CHANCE

2009/5/12 Murodullo Latifov murodlatifov@yahoo.com

Hi Caveman,

----- Original Message ----

From: Orvalho Joaquim Augusto orvaquim@gmail.com

To: Bob Jolliffe bobjolliffe@gmail.com

Sent: Tuesday, May 12, 2009 2:08:43 PM

Subject: Re: [Dhis2-devs] weeks calculation

Well

Yes this a problem for us. Because we expect to use correctly DHIS [reporting tools for now] and we need to map exactly the periods from the actual system to DHIS.

But meanwhile there is a another problem with a lot of empty data on that system. Mine foucus has been on that and I forgot for a while these dateweeks troubles.

Anyway, can you corect the DHIS2 code please to calculate weekdates? If it is buggy.

Regards

Caveman

Are current periods in Mozambican database generated by DHIS or they are also imported from elsewhere?

murod

Hi Saptarshi

Its bad to re-invent the wheel, but I think we just keep doing that all the
time. The Java API has all these things built-in, but we seem to have our
own conventions for everything...
The Calender class does all the good work with enough locale specific
things...

http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#getFirstDayOfWeek()

Sorry, but its not quite as simple as that. The Calendar class lets
you specify important things like the setFirstDayOfWeek and
setMinimalDaysInFirstWeek, but it doesn't decide on those values for
you. And the WeeklyPeriodType is of course using the Calendar class.
When generating weekly periods for a year it has setFirstDayOfWeek to
Monday. We don't specify MinimalDaysInFirstWeek so I checked - we get
4 as a default, which is fine. In other words DHIS2 generates ISO8601
compliant week numbers (using the calendar class) which is excellent.

There are only three problems:
1. there is a small bug in the generator which I would like to fix

2. we don't validate when we construct weekly periods. For example
we construct a weekly period with three parameters - type (weekly),
start date and end date. When we construct we should ensure that
startdate is a Monday and that enddate is indeed 6 days apart from
startdate. Otherwise it is possible, through the API, to construct
invalid weekly periods. This probably shouldn't be. (in fact having
both start and enddate is strictly redundant - but I can see how it is
there in support of generality).

3. its not clear how to deal with importing weekly data from a system
which does not use ISO8601 week numbering. This would probably
include a number of VB/Excel/Access type applications. Either (i) we
must be completely agnostic towards the week numbering scheme and
accept anything with a start and end date 6 days apart as a week (or
even short weeks as per US convention) or (ii) we need to have an
approved process of grafting periods into (and perhaps out of) the
ISO8601 scheme. The first option is always a good interoperability
principle but I'm not sure we have the algorithms elsewhere, in the
reporting modules for example, to support it. The second option is a
bit gruff, and I'm not sure how it squares with Vietnamese and
Ethiopian dates for example. (What's a Vietnamese week?) But its
straightforward to implement.

Agreed we should use the Calendar class for all this. But how
exactly? Does anybody else have some experience of dealing with the
vagaries of exchanging weekly data? How does DHIS1.4 understand it?
Do weeks run from Monday to Sunday or Sunday to Saturday? Or
Wednesday to Tuesday with the first week in the year being the first
Wednesday after Easter

Regards
Bob

···

2009/5/12 Saptarshi Purkayastha <sunbiz@gmail.com>:

---
Regards,
Saptarshi PURKAYASTHA
Director R & D, HISP India
Health Information Systems Programme

My Tech Blog: http://sunnytalkstech.blogspot.com
You Live by CHOICE, Not by CHANCE

2009/5/12 Murodullo Latifov <murodlatifov@yahoo.com>

Hi Caveman,

----- Original Message ----
From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
To: Bob Jolliffe <bobjolliffe@gmail.com>
Sent: Tuesday, May 12, 2009 2:08:43 PM
Subject: Re: [Dhis2-devs] weeks calculation

Well

Yes this a problem for us. Because we expect to use correctly DHIS
[reporting tools for now] and we need to map exactly the periods from the
actual system to DHIS.

But meanwhile there is a another problem with a lot of empty data on that
system. Mine foucus has been on that and I forgot for a while these
dateweeks troubles.

Anyway, can you corect the DHIS2 code please to calculate weekdates? If it
is buggy.

Regards
Caveman

Are current periods in Mozambican database generated by DHIS or they are
also imported from elsewhere?

murod
_______________________________________________

_______________________________________________

_______________________________________________

Hi Saptarshi

Its bad to re-invent the wheel, but I think we just keep doing that all the

time. The Java API has all these things built-in, but we seem to have our

own conventions for everything…

The Calender class does all the good work with enough locale specific

things…

http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#getFirstDayOfWeek()

Sorry, but its not quite as simple as that. The Calendar class lets

you specify important things like the setFirstDayOfWeek and

setMinimalDaysInFirstWeek, but it doesn’t decide on those values for

you.

Thankfully it decided for me based on my current locale. Calendar.getInstance() gives me the calendar for the locale and the getFirstDayOfWeek() returned 1 (SUNDAY) as my locale was en_US… I changed my locale to English (United Kingdom) (en_GB) and it returns 2 (MONDAY). So it should work fine for system with the same locale and we really shouldn’t decide.

There are also REAL ways of converting between locale Calendars and Timezones and that should be able to solve any import/export from different locales. There are also various subclasses of the Calendar class available online for other than GregorianCalendar.

I would suggest not to make the starting week to something constant. Instead letting the locale decide I think is the right way forward. As for hacks to get data from Access/Excel/Flat files… it has to be the way the person importing has to understand and take care.

···

2009/5/12 Bob Jolliffe bobjolliffe@gmail.com

2009/5/12 Saptarshi Purkayastha sunbiz@gmail.com:

And the WeeklyPeriodType is of course using the Calendar class.

When generating weekly periods for a year it has setFirstDayOfWeek to

Monday. We don’t specify MinimalDaysInFirstWeek so I checked - we get

4 as a default, which is fine. In other words DHIS2 generates ISO8601

compliant week numbers (using the calendar class) which is excellent.

There are only three problems:

1. there is a small bug in the generator which I would like to fix

2. we don’t validate when we construct weekly periods. For example

we construct a weekly period with three parameters - type (weekly),

start date and end date. When we construct we should ensure that

startdate is a Monday and that enddate is indeed 6 days apart from

startdate. Otherwise it is possible, through the API, to construct

invalid weekly periods. This probably shouldn’t be. (in fact having

both start and enddate is strictly redundant - but I can see how it is

there in support of generality).

1. its not clear how to deal with importing weekly data from a system

which does not use ISO8601 week numbering. This would probably

include a number of VB/Excel/Access type applications. Either (i) we

must be completely agnostic towards the week numbering scheme and

accept anything with a start and end date 6 days apart as a week (or

even short weeks as per US convention) or (ii) we need to have an

approved process of grafting periods into (and perhaps out of) the

ISO8601 scheme. The first option is always a good interoperability

principle but I’m not sure we have the algorithms elsewhere, in the

reporting modules for example, to support it. The second option is a

bit gruff, and I’m not sure how it squares with Vietnamese and

Ethiopian dates for example. (What’s a Vietnamese week?) But its

straightforward to implement.

Agreed we should use the Calendar class for all this. But how

exactly? Does anybody else have some experience of dealing with the

vagaries of exchanging weekly data? How does DHIS1.4 understand it?

Do weeks run from Monday to Sunday or Sunday to Saturday? Or

Wednesday to Tuesday with the first week in the year being the first

Wednesday after Easter

Regards

Bob

Regards,

Saptarshi PURKAYASTHA

Director R & D, HISP India

Health Information Systems Programme

My Tech Blog: http://sunnytalkstech.blogspot.com

You Live by CHOICE, Not by CHANCE

2009/5/12 Murodullo Latifov murodlatifov@yahoo.com

Hi Caveman,

----- Original Message ----

From: Orvalho Joaquim Augusto orvaquim@gmail.com

To: Bob Jolliffe bobjolliffe@gmail.com

Sent: Tuesday, May 12, 2009 2:08:43 PM

Subject: Re: [Dhis2-devs] weeks calculation

Well

Yes this a problem for us. Because we expect to use correctly DHIS

[reporting tools for now] and we need to map exactly the periods from the

actual system to DHIS.

But meanwhile there is a another problem with a lot of empty data on that

system. Mine foucus has been on that and I forgot for a while these

dateweeks troubles.

Anyway, can you corect the DHIS2 code please to calculate weekdates? If it

is buggy.

Regards

Caveman

Are current periods in Mozambican database generated by DHIS or they are

also imported from elsewhere?

murod

Hi

Hi Saptarshi

> Its bad to re-invent the wheel, but I think we just keep doing that all
> the
> time. The Java API has all these things built-in, but we seem to have
> our
> own conventions for everything...
> The Calender class does all the good work with enough locale specific
> things...
>
>
> http://java.sun.com/javase/6/docs/api/java/util/Calendar.html#getFirstDayOfWeek()

Sorry, but its not quite as simple as that. The Calendar class lets
you specify important things like the setFirstDayOfWeek and
setMinimalDaysInFirstWeek, but it doesn't decide on those values for
you.

Thankfully it decided for me based on my current locale.
Calendar.getInstance() gives me the calendar for the locale and the
getFirstDayOfWeek() returned 1 (SUNDAY) as my locale was en_US... I changed
my locale to English (United Kingdom) (en_GB) and it returns 2 (MONDAY). So
it should work fine for system with the same locale and we really shouldn't
decide.

Thats interesting. Hadn't realized locale affects FirstDayofWeek.
That's something. Letting calendar decide on basis of locale is one
option. Does it also impact on MinimumDaysInFirstWeek? This one is
probably more significant as it determines how many weeks in the year
and which weeks are in which year.

So either we can generate weekly periods based on ISO8601 or based on
locale. Neither is ad-hoc or arbitrarily "invented" so that is fine.
Perhaps better still might be to provide a user check box or something
to allow the user to decide. Though I am still not sure what best
practice is regarding weekly periods - SDMX for example seems to hint
at the ISO8601 approach (I would also lean this way). Makes sense
when a large part of its application area is financial data and
probably international in nature. Comparing statistical data across
series where the weekly periods are determined by locale could be
painful.

The other question which occurs to me and which maybe the DHIS2 gurus
might answer is whether it really makes any difference, other than at
the point where we must generate periods - obviously then we must
decide what periods to create, using what scheme, standard, locale or
what have you. But other than that is there any assumption built in
anywhere regarding, for example, first day of a week or first week of
the year?

There are also REAL ways of converting between locale Calendars and
Timezones and that should be able to solve any import/export from different
locales.

I haven't seen anything regarding converting between week numbers
Maybe its not a big deal. I'd still like to know what the actual
problem with weekly data experienced by Orvalho was. Better to be
focussing on real problems than potential ones ...

Cheers
Bob

···

2009/5/12 Saptarshi Purkayastha <sunbiz@gmail.com>:

2009/5/12 Bob Jolliffe <bobjolliffe@gmail.com>

2009/5/12 Saptarshi Purkayastha <sunbiz@gmail.com>:

There are also various subclasses of the Calendar class available
online for other than GregorianCalendar.

I would suggest not to make the starting week to something constant. Instead
letting the locale decide I think is the right way forward. As for hacks to
get data from Access/Excel/Flat files... it has to be the way the person
importing has to understand and take care.

And the WeeklyPeriodType is of course using the Calendar class.
When generating weekly periods for a year it has setFirstDayOfWeek to
Monday. We don't specify MinimalDaysInFirstWeek so I checked - we get
4 as a default, which is fine. In other words DHIS2 generates ISO8601
compliant week numbers (using the calendar class) which is excellent.

There are only three problems:
1. there is a small bug in the generator which I would like to fix

2. we don't validate when we construct weekly periods. For example
we construct a weekly period with three parameters - type (weekly),
start date and end date. When we construct we should ensure that
startdate is a Monday and that enddate is indeed 6 days apart from
startdate. Otherwise it is possible, through the API, to construct
invalid weekly periods. This probably shouldn't be. (in fact having
both start and enddate is strictly redundant - but I can see how it is
there in support of generality).

3. its not clear how to deal with importing weekly data from a system
which does not use ISO8601 week numbering. This would probably
include a number of VB/Excel/Access type applications. Either (i) we
must be completely agnostic towards the week numbering scheme and
accept anything with a start and end date 6 days apart as a week (or
even short weeks as per US convention) or (ii) we need to have an
approved process of grafting periods into (and perhaps out of) the
ISO8601 scheme. The first option is always a good interoperability
principle but I'm not sure we have the algorithms elsewhere, in the
reporting modules for example, to support it. The second option is a
bit gruff, and I'm not sure how it squares with Vietnamese and
Ethiopian dates for example. (What's a Vietnamese week?) But its
straightforward to implement.

Agreed we should use the Calendar class for all this. But how
exactly? Does anybody else have some experience of dealing with the
vagaries of exchanging weekly data? How does DHIS1.4 understand it?
Do weeks run from Monday to Sunday or Sunday to Saturday? Or
Wednesday to Tuesday with the first week in the year being the first
Wednesday after Easter

Regards
Bob

> ---
> Regards,
> Saptarshi PURKAYASTHA
> Director R & D, HISP India
> Health Information Systems Programme
>
> My Tech Blog: http://sunnytalkstech.blogspot.com
> You Live by CHOICE, Not by CHANCE
>
>
> 2009/5/12 Murodullo Latifov <murodlatifov@yahoo.com>
>>
>> Hi Caveman,
>>
>>
>>
>> ----- Original Message ----
>> From: Orvalho Joaquim Augusto <orvaquim@gmail.com>
>> To: Bob Jolliffe <bobjolliffe@gmail.com>
>> Sent: Tuesday, May 12, 2009 2:08:43 PM
>> Subject: Re: [Dhis2-devs] weeks calculation
>>
>> Well
>>
>> Yes this a problem for us. Because we expect to use correctly DHIS
>> [reporting tools for now] and we need to map exactly the periods from
>> the
>> actual system to DHIS.
>>
>> But meanwhile there is a another problem with a lot of empty data on
>> that
>> system. Mine foucus has been on that and I forgot for a while these
>> dateweeks troubles.
>>
>> Anyway, can you corect the DHIS2 code please to calculate weekdates? If
>> it
>> is buggy.
>>
>> Regards
>> Caveman
>>
>> Are current periods in Mozambican database generated by DHIS or they
>> are
>> also imported from elsewhere?
>>
>> murod
>> _______________________________________________
>>
>>
>>
>>
>>
>> _______________________________________________
>
>
> _______________________________________________
>
>

_______________________________________________