WeekOfYear() BUG


If you wish to leave comments or ask questions, please log on or sign up.

This forum is intended for cases when a problem can not be solved due to restrictions of the platform: a bug or lack of functionality.

#1
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Dec 4, 2015
Company: Smart ID

Hello,

I am using 1C:Enterprise 8.3.6.2332 and today, 16.06.2017 WeekOfYear(CurrentDate()) returns 25, but current week no is 24. Please take a look at this function.

 
#2
People who like this:0Yes/0No
Active user
Rating: 2
Joined: Apr 8, 2013
Company: 1C Company

Hi, Sebastian,

Thank you for your request.
I had checked the function on the 8.3.8.2167 platform and got the correct week number for 16.06.2017.

Please use following code to check:

Code
Message(WeekOfYear('20170616'));


If you get the error again I'll recommend you to update platform version to the latest release (8.3.10.2299).

Be careful because the form rendering engine was changed in 8.3.8 platform and a platform update may take time and efforts.

 
#3
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Dec 4, 2015
Company: Smart ID

Hi,

I know this function is working on new platform versions, but the platform my client uses is 8.3.6.2332 and I cannot update it.

I user your code example and the same problem.

Is there any other way to generate the correct current week of year ?

Thank you!

 
#4
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Nov 10, 2015
Company:

&AtServer
Function WeekOfYear_ISO8601(Date)

Corrective = WeekOfYear(Date(Year(Date),1,4)) - 1;
Result = WeekOfYear(Date) - Corrective;
Result = ?(Result = 0, WeekOfYear_ISO8601(AddMonth(EndOfYear(Date), -12)), Result);

Return Result;

EndFunction

 
#5
People who like this:0Yes/0No
Active user
Rating: 2
Joined: Apr 8, 2013
Company: 1C Company

Hi Sebastian,

Basically, there is some week numbering systems:
https://en.wikipedia.org/wiki/Week#Week_numbering
https://en.wikipedia.org/wiki/ISO_week_date

I recommend you defining which numbering system is more suitable for your client and develop a function for that.

You can find a code for ISO numbering system below:

Code
Function IsoWeekDate(Command) 
   
   Year = Year(TestDate);
   
   DayOfYear    = DayOfYear(TestDate);
   WeekDay    = WeekDay(TestDate);
   Result       = Int((DayOfYear - WeekDay + 10) / 7);
   
   If Result < 1 Then
      Result = LastWeek(Year - 1);
      
   ElsIf Result > LastWeek(Year) Then
      Result = 1;
      
   EndIf;
   
   Message(Result);
   
EndFunction

Function LastWeek(Year)
   Weeks = 52;
   
   If (P(Year) = 4) Or (P(Year - 1) = 3) Then
      Weeks = Weeks + 1;
      
   EndIf;

   Return Weeks;

EndFunction

Function P(Year)
   P = (Year + Int(Year / 4) - Int(Year / 100) + Int(Year / 300)) % 7      
EndFunction

 
Subscribe