← Back to team overview

dhis2-devs team mailing list archive

Re: weeks calculation

 

Hi Bob,



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

Hi cave persons

2009/5/11 Murodullo Latifov <murodlatifov@xxxxxxxxx>:

> 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


      



Follow ups

References