10016 : Can I change the week numbers

Question

Is it possible to have the phSchema display weeks like SQL server. ie Week of year, not necessarily 7 days from a particular day. In that case, the last week of last year (2004) would have 5 days instead of 7, assuming that the first day is monday. We need this because that is how we worked out the weeks in the back end, and we need to display it like that.

Resolution

The phGant and phSchema display weeks as specified by the Julian-day-number-algorithm. You can override all texts that the components write to the datescaler by implementing OnScalerStringLong and OnScalerStringShort. These two events has reference arguments with the suggested string, they also have arguments with the date and resolution that this string represent.

So to get the week-number in a definition where week 1 always starts at the first of January, you would count the days from to today and modulus 7; (Today- (05-01-01)) mod 7

This gives you a zero based week number; add 1 and you have your week number…

You only want to change the output text when week-numbers are shown and you check this by controlling the theStep argument of the events. When weeks are show theStep equals 7 (7 days in a week).

So put this in your OnScalerStringShort and OnScalerStringLong implementation;

If theStep=7 then

  theResult=’xw’+IntToStr(((Now-firstDayOfYear) mod 7)+1)