Function %WeekNr and %WeekStartTime return incorrect results for 1st of january when falls on Friday, Saturday or Sunday.
%WeekNr has been corrected by %WeekOfYear.
Is there such corrected equivalent for %WeekStartTime ?
%WeekNr and %WeekOfYear do the same, but they use a different definition of “start of year”.
%WeekOfYear uses an official definition which says “1st week of year contains at least 4 days of the respective week”. So when January 1st is Friday,Saturday or Sunday, this is not 1st week but 53rd week of the last year. When January 1st is Monday to Thursday, this is the 1st week.
%WeekStartTime returns start of week that is obtained by calling %WeekNr.
An equivalent function for %WeekOfYear has not been implemented (yet). However, it can be easily emulated in ESL script:
PROCEDURE MyStartTime(IN INT _year, IN INT _week, TIME _startTime)
INT _i
TIME _t
_t := %StrToTime('00:00:00 01-01-' + %IToStr(_year))
_t := _t + (_week-1) * 86400 * 7 - 86400 * 3
FOR _i = 1 TO 7 DO_LOOP
IF %WeekOfYear(_t) = _week THEN
_startTime := _t
RETURN
ENDIF
_t := _t + 86400
END_LOOP
_startTime := %SetInvalid(_startTime)
END MyStartTime
and it can be tested:
BEGIN
TIME _t
CALL MyStartTime(2019, 1, _t)
CALL MyStartTime(2018, 1, _t)
CALL MyStartTime(2017, 1, _t)
CALL MyStartTime(2016, 1, _t)
CALL MyStartTime(2015, 1, _t)
CALL MyStartTime(2014, 1, _t)
CALL MyStartTime(2013, 1, _t)
CALL MyStartTime(2012, 1, _t)
CALL MyStartTime(2011, 1, _t)
CALL MyStartTime(2010, 1, _t)
END