Sign in to follow this  
Followers 0
azure

Returning Week Number

9 posts in this topic

Can anyone help me throw together a formula to return the week number of a given day?

I see that it's been conveniently omitted from the macros! :(

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Depends on your numbering of the weeks, when your week starts and so on.

Does your week start on Monday or on Sunday?

What do you call week 1? The first complete week? The first week with at least 4 days left? Or the week that has only one day in the new year?

Also in my opinion AutoIt has a strange way of storing dates and times so you'll have to convert them to a more useful format like the unixtime before.

Edited by sugi

Share this post


Link to post
Share on other sites

I'm interested in Sunday through Saturday, traditional week numbers.

Not absolutes (jan 1-7,8-14,etc).

For instance today (07/29/04) should be within week number: 31

Sunday (08/01/04) should be within week number: 32.

Share this post


Link to post
Share on other sites

Week of the month or week of the year?


Who else would I be?

Share this post


Link to post
Share on other sites

I'm interested in Sunday through Saturday, traditional week numbers.

Not absolutes (jan 1-7,8-14,etc).

For instance today (07/29/04) should be within week number: 31

Sunday (08/01/04) should be within week number: 32.

So what are traditional week numbers for you? And what do you call absolute week numbers?

When talking about dates, times and measurements you cannot take anything for granted...e.g. next Sunday would have been week 31 for me. But it's 32 for you.

08/01/04 would be january 8th, 2004 for me. But since you've spoken of july 29th as 07/29 I guess you're meaning it the other way round.

As long as not the whole world uses the same formats and measurements you have to be specific about every detail.

Share this post


Link to post
Share on other sites

Ok... Here's what I want to do.

@MON & "/" & @MDAY & "/" & @YEAR is the date format I use.

Week 1 of this year would be: 01/01/04 - 01/03/04.

Week 53 of this year would be: 12/26/04 - 12/31/04.

Specific week numbers aren't that important.

I'm saving entered times to a ini file under the header of $WEEKNUM & @WDAY. This way, when I go to next week, it doesn't overwrite my times from last week.

So all I want to do is take the input of: @MON & "/" & @MDAY & "/" & @YEAR (or anything that gives you today's date, specific format isn't important) and be able to calculate what week number it is, so that on sunday, the week number changes and it starts a new section of the ini file.

Share this post


Link to post
Share on other sites

Okay, I'm providing a script that should perform the tasks that you've specified. Although it compensates for leap years, the logic that I used will not be accurate for years prior to 1923. (See notes in script)

...But since it sounds like you're going to be using the function to process log files, it should work as long as they don't change the calendars again.

The week period returned does not take into consideration what day of the week the specified year actually started on. Since there are 14 different possible calendar years, I decided not to create a cross-reference matrix to support this functionality. (The code would get really ugly)

Anyway, here's the cut-n-paste script:

$Title = "Week Information"

; ****************************************************************************
;  Define standard month lengths
; ****************************************************************************
$MonthLens = StringSplit("31,28,31,30,31,30,31,31,30,31,30,31", ",")

;  Obtain Date from user
$Date = GetDate()

;  Extrapolate Date fields from the $Date string
;  This will help parse dates read from a file (in the specified format)
$DateData = StringSplit($Date, "/-")
$Month = Int($DateData[1])
$Day = Int($DateData[2])
$Year = Int($DateData[3])

;  Check if specified year is a leap year
$Leap = Is_Leap($Year)
If $Leap < 0 Then
  MsgBox(4096, "Error", "Please check date format, and try again.")
  Exit
EndIf

; Count the number of days accumulated so far.
$Days = Count_Days()

; Calculate the number of weeks passed
$Weeks = Int($Days / 7)
If $Weeks * 7 < $Days Then $Weeks = $Weeks + 1

; Determine approximate week interval (beginning Jan, 1)
$Period = Get_Week($Weeks)

MsgBox(4096, $Title, $Date & " is in week number " & $Weeks & @CR & @CR & "Period:  " & $Period)
Exit

; ****************************************************************************
;  Crude Leap Year function - Not recommended for dates prior to 1923
; ****************************************************************************
Func Is_Leap($Year)
; Success:  Returns 1 if the specified year is a leap year
; Failure:  Returns 0 if the specified year is not a leap year
;           Returns -1 if no year was specified
;           Returns -2 if specified year is not numeric
  
; Keep in mind that leap years were not adopted until 1582 or later in most countries!
;  -- Britain adopted the new leap year system in 1752 with an 11 day error on calendar.
;  -- Former Soviet Union adopted in 1918
;  -- Greece adopted in 1923
;  -- This function does not quantify the results with the above restrictions.

; No year specified abort
  If $Year = "" Then Return -1

; Year wasn't numeric, abort
  If Int($Year) < 1 Then Return -2

; Is year divisible by 4?
  If Not Mod($Year, 4) Then
  ; Is year divisible by 100?
    If Not Mod($Year, 100) Then
    ; Is year divisible by 400?
      If Not Mod($Year, 400) Then
      ; Okay, it's a leap year.
        Return 1
      Else
      ; Just a normal year.
        Return 0
      EndIf
    Else
    ; Okay, it's a leap year.
      Return 1
    EndIf
  EndIf
; Just a normal year.
  Return 0;
EndFunc

; ****************************************************************************
;  Calculates the total number of days passed to specified date
; ****************************************************************************
Func Count_Days()
  $TotalDays = 0

; Calcuate total number of days so far
  If $Month > 2 Then 
  ; Count the number of days in previous months
    For $i = 1 to ($Month - 1)
      $TotalDays = $TotalDays + $MonthLens[$i]
    Next
  ; Add one day if we've had a leap year day
    If $Month > 2 And $Leap Then $TotalDays = $TotalDays + 1
  EndIf
; Add days from current month
  $TotalDays = $TotalDays + $Day
  Return $TotalDays
EndFunc


; ****************************************************************************
;  Calculates the week period for the specified week
; ****************************************************************************
Func Get_Week($WeekCount)
 ; No week specified abort
  If $WeekCount = "" Then Return -1

 ; Week wasn't numeric, abort
  If Int($WeekCount) < 1 Then Return -2

 ; Define variable defaults
  $MonthCount = 1
  $MonthDays = 1
  $LastMonth = 1
  $LastDays = 1

 ; Cycle through weeks, counting days
  For $i = 1 to $WeekCount
   ; On final week, save previous week's info
    If $i = $WeekCount Then 
      $LastMonth = $MonthCount
      $LastDays = $MonthDays
    EndIf

   ; Lookup days in current month
    $CurLen = $MonthLens[$MonthCount]
   ; Adjust for leap year if needed
    If $Leap And $MonthCount = 2 Then $CurLen = $CurLen + 1     

    $MonthDays = $MonthDays + 7

   ; End of month reached, reset values
    If $MonthDays >= $CurLen Then
      $MonthCount = $MonthCount + 1
      $MonthDays = $MonthDays - $CurLen
    EndIf
  Next

 ; Subtract 1 day for week period output
  $MonthDays = $MonthDays - 1


; Reformat month and day information
  $PrevMonth = String($LastMonth) 
  If $LastMonth < 10 Then $PrevMonth = "0" & String($LastMonth)

  $PrevDays = String($LastDays)
  If $LastDays < 10 Then $PrevDays = "0" & String($LastDays)
 
  $CurMonth = String($MonthCount)
  If $MonthCount < 10 Then $CurMonth = "0" & String($MonthCount)

  $CurDays = String($MonthDays)
  If $MonthDays < 10 Then $CurDays = "0" & String($MonthDays) 

  Return String($PrevMonth & "/" & $PrevDays & " - " & $CurMonth & "/" & $CurDays)
EndFunc

; ****************************************************************************
;  Prompts user to enter a date
; ****************************************************************************
Func GetDate()
; Use current date default answer
  $Current = @MON & "/" & @MDAY & "/" & @YEAR

;Prompt user for date
  $Input = InputBox($Title, "Please specify a date:", $Current, "", -1, -1, -1, -1, 30)
  If $Input <> "" Then 
  ; Invalid date, prompt again
    If StringSplit($Input, "/-") < 3 Then GetDate()
  ; Date OK!
    Return $Input
  Else
  ; Abort script if timeout is reached, cancel button is pressed, or other errors occur
    If @Error Then Exit 
  ; Re-prompt user if no date was specified (default answer erased)
    GetDate()
  EndIf
EndFunc

Hope this helps! :ph34r:

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Okay, I'm providing a script that should perform the tasks that you've specified.  Although it compensates for leap years, the logic that I used will not be accurate for years prior to 1923.  (See notes in script) 

...But since it sounds like you're going to be using the function to process log files, it should work as long as they don't change the calendars again.

The week period returned does not take into consideration what day of the week the specified year actually started on.  Since there are 14 different possible calendar years, I decided not to create a cross-reference matrix to support this functionality.  (The code would get really ugly)

Hope this helps!  :ph34r:

<{POST_SNAPBACK}>

When I first used this, it worked. So I pulled out the parts I wanted and integrated it into my script and I thought it worked great.....

today rolls along and all of a sudden it's using week 32 (when for whatever reason the rest of the week, monday through thursday, was week 31). I thought this was odd, so I re-copy/paste'd your code and ran it again. It's returning 08/06/04 as week 32 for the week of 08/05/04 - 08/11/04. What calendar is this? :(

It should be week 32 between 08/01/04 - 08/07/04 (sunday through saturday).

Here is my code. I know it's ugly but I'm learning as I go and get better with each script I write:

$ES_READONLY = 0x0800
$ES_MULTILINE = 0x0020
$ES_WANTRETURN = 0x1000
$ES_RIGHT = 0x0002
$ES_AUTOVSCROLL = 0x0040
$PBS_SMOOTH = 0x01
$PBS_VERTICAL = 0x04
$SS_CENTER = 0x01
$SS_LEFT = 0x0000
$SS_NOTIFY = 0x0100
$SS_RIGHT = 0x0002
$WIN_WIDTH = 130
$WIN_HEIGHT = 160

$WS_BORDER = 0x00800000;Creates a window that has a thin-line border. 
$WS_POPUP = 0x80000000;Creates a pop-up window. This style cannot be used with the WS_CHILD style. 
$WS_CAPTION = 0x00C00000;Creates a window that has a title bar (includes the WS_BORDER style) 
$WS_DISABLED = 0x08000000;Creates a window that is initially disabled. 
$WS_DLGFRAME = 0x00400000;Creates a window that has a border of a style typically used with dialog boxes. 
$WS_HSCROLL = 0x00100000;Creates a window that has a horizontal scroll bar. 
$WS_MAXIMIZE = 0x01000000;Creates a window that is initially maximized. 
$WS_MAXIMIZEBOX = 0x00010000;Creates a window that has a maximize button. Cannot be combined with the WS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified. 
$WS_MINIMIZE = 0x20000000;Creates a window that is initially minimized. 
$WS_MINIMIZEBOX = 0x00020000;Creates a window that has a minimize button. Cannot be combined with the WS_EX_CONTEXTHELP style. The WS_SYSMENU style must also be specified. 
$WS_OVERLAPPED = 0;Creates an overlapped window. An overlapped window has a title bar and a border. Same as the WS_TILED style 
$WS_OVERLAPPEDWINDOW = 0x00CF0000;Creates an overlapped window with the WS_OVERLAPPED, WS_CAPTION, WS_SYSMENU, WS_THICKFRAME, WS_MINIMIZEBOX, and WS_MAXIMIZEBOX styles. Same as the WS_TILEDWINDOW style. 
$WS_POPUPWINDOW = 0x80880000;Creates a pop-up window with WS_BORDER, WS_POPUP, and WS_SYSMENU styles. The WS_CAPTION and WS_POPUPWINDOW styles must be combined to make the window menu visible. 
$WS_SIZEBOX = 0x0000F2C0;Creates a window that has a sizing border. Same as the WS_THICKFRAME style. 
$WS_SYSMENU = 0x00080000;Creates a window that has a window menu on its title bar. The WS_CAPTION style must also be specified. 
$WS_THICKFRAME = 0x00040000;Creates a window that has a sizing border. Same as the WS_SIZEBOX style 
$WS_VSCROLL = 0x00200000;Creates a window that has a vertical scroll bar. 
$WS_VISIBLE = 0x10000000;Creates a window that is initially visible. 
$WS_CHILD = 0x40000000;Creates a child window. A window with this style cannot have a menu bar. This style cannot be used with the WS_POPUP style. 
$WS_GROUP = 0x00020000;Specifies the first control of a group of controls. The group consists of this first control and all controls defined after it, up to the next control with the WS_GROUP style. 

$INI = @TempDir & "\TIMESHEET.INI"
$Days = Count_Days()

; Calculate the number of weeks passed
$Week = Int(($Days-2) / 7)
If $Week * 7 < $Days Then $Week = $Week + 1
   
  ;MsgBox(0,"Debug","Days: " & $DAYS & "Weeks: " & $WEEK)
$MAIN = @WDAY
$TITLE = "Timesheet Panel"
Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)
Opt("TrayIconHide", 1)
Opt("GUITaskbarEntry", 0)

GuiCreate($TITLE, $WIN_WIDTH,$WIN_HEIGHT,(@DesktopWidth - $WIN_WIDTH),(@DesktopHeight-$WIN_HEIGHT-35), $WS_POPUPWINDOW)

buttonbuild()
; 0x04CF0000 = Old WS_STYLE?
; (@DesktopWidth-130)/2, (@DesktopHeight-230)/2 <- Center Window
;$LDEBUG = GUISetControl("label", "DEBUG", 10,0,110,20,$SS_CENTER)

GuiShow()
WinWait($TITLE)
WinSetOnTop($TITLE, "", 1)
WinActivate($TITLE)
WinWaitActive($TITLE)


While 1
   sleep(100)
   $msg = GuiMsg(0)
   updatedisplay()

   Select
   Case $msg = -3
        quit()
   Case $msg = 2
       ;;;
   Case $msg = $NOK
        savechanges(GuiRead($EDISPLAY))
   Case $msg = $NCANCEL
        quit()
   Case $msg = $EDISPLAY
       ;;;
;   Case $msg = $PTIMELEFT
       ;;;
   Case $msg = $LBACK
         $MAIN = $MAIN - 1
         GUIWrite($EDISPLAY,0,"")
         GUIWrite($EDISPLAY,0,readini())
   Case $msg = $LFORWARD
         IF $MAIN <> @WDAY Then $MAIN = $MAIN + 1
         GUIWrite($EDISPLAY,0,"")
         GUIWrite($EDISPLAY,0,readini())
   EndSelect
WEnd
quit()

Func savechanges($INPUT)
   $I = 1
   $TEMP = ""
   While $I < 8
;     $TEMP = IniRead($INI,$Week & $MAIN,$I,"Missing")
      IniDelete($INI,$Week & $MAIN,$I)
      $I = $I + 1
   Wend
   $TEMP = StringReplace($INPUT,@CRLF,"|")
   While StringRight($TEMP,1) == "|"
      $TEMP = StringTrimRight($TEMP,1)
   Wend
   $TEMP = StringSplit($TEMP,"|")
   FOR $I = 1 TO $TEMP[0]
      $TEMP[$I] = INIWrite($INI,$Week & $MAIN,$I,$TEMP[$I])
   Next
   GUIWrite($EDISPLAY,0,"")
   GUIWrite($EDISPLAY,0,readini())
EndFunc

Func readini()
   $I = 1
   $OUTPUT = ""
   $TEMP = ""
   While $TEMP <> "Missing"
      $TEMP = IniRead($INI,$Week & $MAIN,$I,"Missing")
      IF $TEMP <> "Missing" Then $OUTPUT = $OUTPUT & $TEMP & @CRLF
      $I = $I + 1
   Wend
Return $OUTPUT
EndFunc

Func counter($INPUT)
   If lasttime($INPUT) = -1 Then
   Return 0
   Else
   $LASTSEC = timetosec(LASTTIME($INPUT))
   $CURSEC = ((@HOUR * 60)*60)+(@MIN * 60)+@SEC
   $DIFSEC = $CURSEC - $LASTSEC
   $OUTPUT = $DIFSEC
   Return $OUTPUT
   EndIf
EndFunc

Func timeleft($INPUT,$TOTAL)
   If $INPUT <> 0 Then
   $COMPAREVALUE = $TOTAL - dailytotal($MAIN)
   If $COMPAREVALUE > $INPUT Then
   $TOTSECLEFT = $COMPAREVALUE - $INPUT
   $OUTPUT = $TOTSECLEFT
   Return $OUTPUT
Else
   Return 0
   EndIf
   Else
   Return 0
   EndIf
EndFunc

Func ProgressLeft($INPUT,$TOTAL)
   If $INPUT < $TOTAL Then
   $OUTPUT = ($INPUT / $TOTAL) * 100
   Return $OUTPUT
   Else
   Return 100
   EndIf
EndFunc

Func timetosec($INPUT)
   $TEMP = StringSplit($INPUT,":")
;   For $I = 1 To $TEMP[0]
;     $STRING = $STRING & $TEMP[$I] & " - "
;   Next
   Select
      Case $TEMP[0]=3
         $OUTPUT = ($TEMP[1]*3600)+($TEMP[2]*60)+$TEMP[3]
         Return $OUTPUT
      Case $TEMP[0]=2
         $OUTPUT = ($TEMP[1]*3600)+($TEMP[2]*60)
         Return $OUTPUT
      Case Else
         Return -1
   EndSelect
EndFunc

Func sectotime($INPUT)
   If $INPUT <> 0 Then
      $HOUR = Int($INPUT / 3600)
        $MIN = Int(Mod($INPUT, 3600) / 60)
        If StringLen($MIN) = 1 Then
            $MIN = "0" & $MIN
        EndIf
        $SEC = Mod(Mod($INPUT, 3600), 60)
        If StringLen($SEC) = 1 Then
            $SEC = "0" & $SEC
        EndIf
      $OUTPUT = $HOUR & ":" & $MIN & ":" & $SEC
      Return $OUTPUT
   Else
      Return 0
   EndIf
EndFunc

Func updatedisplay()

   $fortyhours = 144000
   $modtotal = weeklytotal_mod()
   If $fortyhours - $modtotal < 28800 Then
      $eighthours = $fortyhours - $modtotal
   Else
      $eighthours = 28800
   EndIf

   $time = counter($MAIN)
Opt("MouseCoordMode",0)
   $mousepos = MouseGetPOS()
Opt("MouseCoordMode",1)
   $mouseposglobal = MouseGetPOS()
Opt("MouseCoordMode",0)
   Select
   Case $mousepos[0] > 70 AND $mousepos[0] < 95 AND $mousepos[1] > 10 AND $mousepos[1] < 130 AND WinActive($TITLE)
      ToolTip("Time Worked: " & sectotime(dailytotal($MAIN) + $time) & @CRLF & "Time Left: " & sectotime(timeleft($time,$eighthours)),$mouseposglobal[0]-120)
   Case $mousepos[0] > 95 AND $mousepos[0] < 120 AND $mousepos[1] > 10 AND $mousepos[1] < 130 AND WinActive($TITLE)
      ToolTip("Time Worked: " & sectotime(weeklytotal()) & @CRLF & "Time Left: " & sectotime($fortyhours - weeklytotal()),$mouseposglobal[0]-120)
   Case Else
      ToolTip("")
   EndSelect
;     ToolTip($fortyhours - $modtotal)
;   GUIWrite($LCOUNTDOWN,0, sectotime(timeleft($time,$eighthours,$main)))
; sectotime(timeleft($time,28800,$MAIN)) & " " &
   GUIWrite($LLEAVETIME,0, sectotime(timetoleave($eighthours)))
   GUISetControlEx($PTIMELEFTDAY,progressleft(dailytotal($MAIN)+$time,$eighthours))
;  ,(8421376 - (540000 * (dailytotal($MAIN)+$time)/$eighthours)/100)
   GUISetControlEx($PTIMELEFTWEEK,progressleft(weeklytotal(),$fortyhours))
EndFunc

Func buttonbuild()
   $BWIDTH = ($WIN_WIDTH-20)/2
   $BHEIGHT = 20
   $BTOP = $WIN_HEIGHT-25
   Global $EDISPLAY = GUISetControl("edit", readini(), 10, 10, 60, 110, $ES_MULTILINE + $ES_WANTRETURN + $ES_RIGHT + $ES_AUTOVSCROLL)
   Global $PTIMELEFTDAY = GUISetControl("progress", "Time Left", 70, 10, 25, 120, $PBS_SMOOTH + $PBS_VERTICAL)
   Global $PTIMELEFTWEEK = GUISetControl("progress", "Time Left", 95, 10, 25, 120, $PBS_SMOOTH + $PBS_VERTICAL)
   Global $LBACK = GUISetControl("label", "<", 10, 120, 10, 10, $SS_LEFT + $SS_NOTIFY)
   GUISetControlFont($LBACK,7,900,-1,4)
   GUISetControlEx($LBACK,-1,-1,"Back One Day", 0x35518E)
   Global $LFORWARD = GUISetControl("label", ">", 60, 120, 10, 10, $SS_NOTIFY + $SS_RIGHT)
   GUISetControlFont($LFORWARD,7,900,-1,4)
   GUISetControlEx($LFORWARD,-1,-1,"Forward One Day", 0x35518E)
   Global $LLEAVETIME = GUISetControl("label", "", 20, 120, 40, 10, $SS_CENTER)
   GUISetControlFont($LLEAVETIME,7,400)
   GUISetControlEx($LLEAVETIME,-1,-1,"Time You Can Leave", 0x35518E)
;   Global $LCOUNTDOWN = GUISetControl("label", "", 10, 135, 110, 20, $SS_CENTER)
   Global $NOK = GUISetControl("button", "Save", 10, $BTOP, $BWIDTH, $BHEIGHT)
   Global $NCANCEL = GUISetControl("button", "Exit", $WIN_WIDTH/2, $BTOP, $BWIDTH, $BHEIGHT)
EndFunc

Func dailytotal($INPUT)
   $I = 1
   $OUTPUT = ""
   $TEMP = ""
   $TEMPSTRING = ""
   $SECTOTAL = ""
   While $TEMP <> "Missing"
      $TEMP = IniRead($INI,$WEEK & $INPUT,$I,"Missing")
      IF $TEMP <> "Missing" Then $TEMPSTRING = $TEMPSTRING & $TEMP & "|"
      $I = $I + 1
   Wend
   $TEMPSTRING = StringTrimRight($TEMPSTRING,1)
   $TEMP = StringSplit($TEMPSTRING,"|")
   DIM $CALCSEC[$TEMP[0]]
   FOR $I = 1 TO $TEMP[0]
      IF MOD($I-1,2) = 0 Then
         $CALCSEC[$I-1] = timetosec($TEMP[$I])
      Else
         $CALCSEC[$I-1] = timetosec($TEMP[$I])
         $SECTOTAL = $SECTOTAL + ($CALCSEC[$I-1] - $CALCSEC[$I-2])
      EndIf
   Next
   
   $OUTPUT = $SECTOTAL
   Return $OUTPUT
EndFunc

Func lasttime($INPUT)
   $I = 1
   $TEMP = ""
   While $TEMP <> "Missing"
      $TEMP = IniRead($INI,$WEEK & $INPUT,$I,"Missing")
      IF $TEMP <> "Missing" Then $TEMPSTRING = $TEMPSTRING & $TEMP & "|"
      $I = $I + 1
   Wend
   $TEMPSTRING = StringTrimRight($TEMPSTRING,1)
   $TEMP = StringSplit($TEMPSTRING,"|")
   If MOD($TEMP[0],2) = 0 Then
      Return -1
   Else
      $OUTPUT = $TEMP[$TEMP[0]]
      Return $OUTPUT
   EndIf
EndFunc

Func weeklytotal()
   For $I = 1 To 7
      If $I = @WDAY Then
         $TOTAL = $TOTAL + dailytotal($I) + counter($I)
      Else
         $TOTAL = $TOTAL + dailytotal($I)
      EndIf
   Next
   $OUTPUT = $TOTAL
   Return $OUTPUT
EndFunc

Func timetoleave($INPUT)
   $TIMELEFT = ($INPUT - dailytotal(@WDAY))
;   ToolTip("$INPUT = " & $INPUT & " dailytotal(@WDAY) = " & dailytotal(@WDAY) & " $TIMELEFT = " & $TIMELEFT)
   $OUTPUT = timetosec(lasttime(@WDAY)) + $TIMELEFT
   Return $OUTPUT
EndFunc

Func quit()
   GUIDelete()
   Exit
EndFunc

Func weeklytotal_mod()
   $TOTAL = 0
   For $I = 1 To @WDAY - 1
         $TOTAL = $TOTAL + dailytotal($I)
   Next
   $OUTPUT = $TOTAL
   Return $OUTPUT
EndFunc

Func Count_Days()
 $Month = Int(@MON)
 $Day = Int(@MDAY)
 $TotalDays = 0
 $MonthLens = StringSplit("31,28,31,30,31,30,31,31,30,31,30,31", ",")

; Calcuate total number of days so far
 If $Month > 2 Then 
; Count the number of days in previous months
   For $i = 1 to ($Month - 1)
     $TotalDays = $TotalDays + $MonthLens[$i]
   Next
; Add one day if we've had a leap year day
;   If $Month > 2 And $Leap Then $TotalDays = $TotalDays + 1
 EndIf
; Add days from current month
 $TotalDays = $TotalDays + $Day
 Return $TotalDays
EndFunc

my ini file looks like this:

[302]
1=7:47
2=16:57
[303]
1=7:50
2=11:19
3=11:31
4=16:16
[304]
1=7:38
2=11:38
3=11:49
4=16:21
[305]
1=7:40
2=15:43
[306]
1=8:08
2=14:07
[312]
1=8:08
2=12:18
3=12:42
4=16:24
[313]
1=7:47
2=11:23
3=11:56
4=16:17
[314]
1=7:40
2=16:34
[315]
1=8:04
2=12:37
3=12:45
4=16:28
[316]
1=7:53
2=11:54
3=12:15

This is a timekeeper of sorts. I plug in my punch times into the editbox and it tells me when I can leave and how much longer I have during the week and during the day.

Hopefully someone can help me return the correct week numbers!

EDIT: By the way, In the code above, I used a temporary workaround by adding two days to $DAYS before dividing it by 7.

Edited by azure

Share this post


Link to post
Share on other sites

today rolls along and all of a sudden it's using week 32 (when for whatever reason the rest of the week, Monday through Thursday, was week 31).  I thought this was odd, so I re-copy/paste'd your code and ran it again.  It's returning 08/06/04 as week 32 for the week of 08/05/04 - 08/11/04.  What calendar is this? :ph34r:

The script is actually performing as I had originally coded it:

The week period returned does not take into consideration what day of the week the specified year actually started on.  Since there are 14 different possible calendar years, I decided not to create a cross-reference matrix to support this functionality.  (The code would get really ugly)

As I said, my script doesn't verify the days of the week for the specified year, nor does it break the weeks down to periods starting on the first full week of the year. (ie which Sunday was the first Sunday in January)

It merely calculates the total number of days that have occurred within the specified year, and divides it into 7-day segments. So it January 1st falls on Wednesday, the weeks will all start on Wednesday (not Sunday). ...I tried to make the script as generic as possible, with the least amount of code. :">

Unfortunately i don't have time to examine your code at the moment, but I hope that this explanation helps clarify the situation.

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