Sign in to follow this  
Followers 0
jiglei

_WeekNumberISO problem

5 posts in this topic

#1 ·  Posted (edited)

Hello everyone, I think I just noticed a problem in the UDFs included in autoIT's beta version, more precisely the _WeekNumberISO() function.

I've been checking how the ISO week system works, and this UDF doesn't seem to always be returning the correct values. I've searched and found an old topic about this issue that was closed and declared fixed the problem, which was exactly the same in 2003-2004, but it doesn't seem fixed now.

For instances, if you were to return the week number of 29 December 2014 (Monday), it returns week 53, which is wrong, because acording to the ISO 8601 dating system, the first week of the year is the one that includes the first thursday.

And for some wicked reason, if you try to return the week number of January 4th 2015, it returns week number 0 with @error=0. Another ISO rule is that the January 4th must always belong to the week number 1, so, there's something wrong with that.

I've been looking to the code, I'm not gonna promisse to try to fix it because I'm too inexperienced, and I might be wrong, and wanted to know what are your thoughts on this.

Also, this site agrees:

http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php

Edited by jiglei

Share this post


Link to post
Share on other sites



jiglei,

I have just run both the release and beta versions of this UDF on the dates you mention and both return Week 1: :)

#include <Date.au3>

$iRet = _WeekNumberISO(2014, 12, 29)
ConsoleWrite("29/12/14 - Week: " & $iRet & " - error: " & @error & @CRLF)

$iRet = _WeekNumberISO(2015, 01, 04)
ConsoleWrite("04/01/15 - Week: " & $iRet & " - error: " & @error & @CRLF
Returns:

>Running:(3.3.12.0):M:\Program\AutoIt3\autoit3.exe "M:\Program\Au3 Scripts\ISO_Test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
29/12/14 - Week: 1 - error: 0
04/01/15 - Week: 1 - error: 0
+>10:42:12 AutoIt3.exe ended.rc:0

>Running:(3.3.13.19):M:\Program\AutoIt3\Beta\autoit3.exe "M:\Program\Au3 Scripts\ISO_Test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
29/12/14 - Week: 1 - error: 0
04/01/15 - Week: 1 - error: 0
+>10:41:13 AutoIt3.exe ended.rc:0
So full marks for posting here first before opening a Trac ticket, but it does not look like a problem from here. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hello, thanks for looking into the issue, I ran the same code and it returns this :

>Running AU3Check (3.3.12.0)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\David\Documents\AutoIT\Test.au3
+>20:16:52 AU3Check ended.rc:0
>Running:(3.3.12.0):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\Users\David\Documents\AutoIT\Test.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
29/12/14 - Week: 53 - error: 0
04/01/15 - Week: 0 - error: 0
+>20:16:52 AutoIt3.exe ended.rc:0
+>20:16:52 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 0.872

Ever since I've made a PC refresh on my system, and reinstalled the autoit packages, some built-in functions have been working weirdly for me, don't know if I have the wrong date.au3 or is it system related? Could the time format of my PC influence the result? For what I've looked into the function, it shouldn't. This is the code of the function that I have:

; #FUNCTION# ====================================================================================================================
; Name...........: _WeekNumberISO
; Description ...: Calculate the weeknumber of a given date.
; Syntax.........: _WeekNumberISO([$iYear = @YEAR[, $iMonth = @MON[, $iDay = @MDAY]]])
; Parameters ....: $iYear - Year value (default = current year)
;                  $iMonth    - Month value (default = current month)
;                  $iDay - Day value (default = current day)
; Return values .: Success - Returns week number of given date
;                  Failure - 0
;                  @Error - 0 - No error.
;                  | 1 - faulty parameters values
;                  |99 - On non-acceptable weekstart value
; Author ........: Tuape
; Modified.......: JdeB: modified to UDF standards & Doc., Change calculation logic.
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _WeekNumberISO($iYear = @YEAR, $iMonth = @MON, $iDay = @MDAY)
    ; Check for erroneous input in $Day, $Month & $Year
    If $iDay > 31 Or $iDay < 1 Then
        Return SetError(1, 0, -1)
    ElseIf $iMonth > 12 Or $iMonth < 1 Then
        Return SetError(1, 0, -1)
    ElseIf $iYear < 1 Or $iYear > 2999 Then
        Return SetError(1, 0, -1)
    EndIf

    Local $idow = _DateToDayOfWeekISO($iYear, $iMonth, $iDay);
    Local $iDow0101 = _DateToDayOfWeekISO($iYear, 1, 1);

    If ($iMonth = 1 And 3 < $iDow0101 And $iDow0101 < 7 - ($iDay - 1)) Then
        ;days before week 1 of the current year have the same week number as
        ;the last day of the last week of the previous year
        $idow = $iDow0101 - 1;
        $iDow0101 = _DateToDayOfWeekISO($iYear - 1, 1, 1);
        $iMonth = 12
        $iDay = 31
        $iYear = $iYear - 1
    ElseIf ($iMonth = 12 And 30 - ($iDay - 1) < _DateToDayOfWeekISO($iYear + 1, 1, 1) And _DateToDayOfWeekISO($iYear + 1, 1, 1) < 4) Then
        ; days after the last week of the current year have the same week number as
        ; the first day of the next year, (i.e. 1)
        Return 1;
    EndIf
    
    Return Int((_DateToDayOfWeekISO($iYear, 1, 1) < 4) + 4 * ($iMonth - 1) + (2 * ($iMonth - 1) + ($iDay - 1) + $iDow0101 - $idow + 6) * 36 / 256)

EndFunc   ;==>_WeekNumberISO

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Where did you get the date.au3 from that contains the UDF you posted as that doesn't look like that standard one?

Jos

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I just typically installed autoit... guess I'll install it again, I think I've included old versions by mistake when importing my includes...

Sorry about the mess that I've made, and thank you for the help.

EDIT: Reinstall solve the problem, pardon me for my noobiness.

Edited by jiglei

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0