Main > Forum > 1C:Enterprise Platform > Bugs and functionality requests to 1C:Enterprise platform > WeekOfYear() BUG

Forum

Search UsersRules
WeekOfYear() BUG
#1
Active user
Points:: 0
Joined:: Dec 4, 2015

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.

Profile
#2
Just came
Points:: 0
Joined:: Apr 8, 2013

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.

Profile
#3
Active user
Points:: 0
Joined:: Dec 4, 2015

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!

Profile
#4
Just came
Points:: 0
Joined:: Nov 10, 2015

&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

Profile
#5
Just came
Points:: 0
Joined:: Apr 8, 2013

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

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.