Jacov Posted July 21, 2024 Posted July 21, 2024 Hi. How can I accelerate existed functions like _NowTime() and _NowDate() to debug long term function (back up with selective age storage) ? For example : during 2 weeks to keep all versions, 2 weeks up to month keep 1 version per 4 days, 1 month up to 3 months to keep 1 version per 1 week, 3 months to 1 year - 1 version per month. I tried to reduce sleep time and changed period limits for seconds , but for selection 1-per-period I use date/week number and it didn't run properly in pseudo accelerated mode. Please advise. expandcollapse popupFunc ApplyRetentionPolicy($sDestDir) $i_1Period = 2 * 7 * 10 $i_2Period_2 = 4 * 7 * 10 $i_3Period_2 = 3 * 7 * 4 * 10 $i_4Period_2 = 365 *10 Local $aFiles = _FileListToArray($sDestDir, "*.data", $FLTA_FILES) If @error Then Return _ArraySort($aFiles, 0, 1, 0, "_CompareFileDates") Local $aToKeep[1] ; Array to store files that should be kept For $i = 1 To $aFiles[0] Local $sFilePath = $sDestDir & "\" & $aFiles[$i] Local $iFileDate = FileGetTime($sFilePath, $FT_MODIFIED, 0) Local $sFileDate = $iFileDate[0] & "/" & $iFileDate[1] & "/" & $iFileDate[2] & " " & $iFileDate[3] & ":" & $iFileDate[4] & ":" & $iFileDate[5] Local $iFileWeek = _WeekNumberISO($sFileDate) Local $iFileYear = $iFileDate[0] Local $iDaysOld = _DateDiff('s', $sFileDate, _NowCalc()) ;;;;;;;;;;;;;;Debug : Was days "D" ;ConsoleWrite($iDaysOld & " " & $aFiles[$i] & " " & _NowCalc() & @CRLF ) Switch True Case $iDaysOld <= $i_1Period ; First 2 weeks - keep all ContinueLoop Case $iDaysOld > $i_1Period And $iDaysOld <= $i_2Period_2 ; Weeks 3-4 - keep 1 per week If _ArraySearch($aToKeep, $iFileWeek & "-" & $iFileYear) = -1 Then _ArrayAdd($aToKeep, $iFileWeek & "-" & $iFileYear) Else FileDelete__($sFilePath) EndIf Case $iDaysOld > $i_2Period_2 And $iDaysOld <= $i_3Period_2 ; Months 1-3 - keep 1 per 2 weeks Local $iBiweekly = Int(($iFileWeek + 1) / 2) If _ArraySearch($aToKeep, $iBiweekly & "-" & $iFileYear) = -1 Then _ArrayAdd($aToKeep, $iBiweekly & "-" & $iFileYear) Else FileDelete__($sFilePath) EndIf Case $iDaysOld > $i_3Period_2 And $iDaysOld <= $i_4Period_2 ; Months 4-12 - keep 1 per month If _ArraySearch($aToKeep, $iFileDate[1] & "-" & $iFileYear) = -1 Then _ArrayAdd($aToKeep, $iFileDate[1] & "-" & $iFileYear) Else FileDelete__($sFilePath) EndIf Case Else ; Older than 1 year - delete ;FileDelete__($sFilePath) EndSwitch Next EndFunc
Andreik Posted July 21, 2024 Posted July 21, 2024 You know that this question doesn't make any sense, right? The "now" part of these functions state exactly what they return, so it's nothing to accelerate in now. For debug purposes you can choose a different date/time value or you can have a custom function to return _NowTime() and _NowDate() in general and whatever values you want in debug mode.
Jacov Posted July 22, 2024 Author Posted July 22, 2024 11 hours ago, Andreik said: You know that this question doesn't make any sense, right? The "now" part of these functions state exactly what they return, so it's nothing to accelerate in now. For debug purposes you can choose a different date/time value or you can have a custom function to return _NowTime() and _NowDate() in general and whatever values you want in debug mode. I overwrote _NowTime() and _NowDate() and implemented inside 'real time' calculated by Epoch time and total second counter I increase with big steps in main while loop. So , in point of view of other functions like create file name, compare time , ween number it is real time , but with increased speed. In this way I simulate 1 year in couple of minutes.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now