<commit_before>Attribute VB_Name = "Globals"
Option Explicit

''
' Description here
'
'@/

'@================================================================================
' Interfaces
'@================================================================================

'@================================================================================
' Events
'@================================================================================

'@================================================================================
' Enums
'@================================================================================

'@================================================================================
' Types
'@================================================================================

'@================================================================================
' Constants
'@================================================================================

Private Const ProjectName                           As String = "SessionUtils27"
Private Const ModuleName                            As String = "Globals"

Public Const OneSecond                              As Double = 1 / 86400
Public Const OneMinute                              As Double = 1 / 1440
Public Const OneHour                                As Double = 1 / 24

'@================================================================================
' Member variables
'@================================================================================

'@================================================================================
' Class Event Handlers
'@================================================================================

'@================================================================================
' XXXX Interface Members
'@================================================================================

'@================================================================================
' XXXX Event Handlers
'@================================================================================

'@================================================================================
' Properties
'@================================================================================

'@================================================================================
' Methods
'@================================================================================

Public Function gCalcOffsetSessionTimes( _
                ByVal pTimestamp As Date, _
                ByVal pOffset As Long, _
                ByVal pStartTime As Date, _
                ByVal pEndTime As Date, _
                ByVal pIgnoreWeekends As Boolean) As SessionTimes
Const ProcName As String = "gCalcOffsetSessionTimes"
On Error GoTo Err

Dim lDatumSessionTimes As SessionTimes

Dim lTargetDate As Date

If pIgnoreWeekends Then
    lDatumSessionTimes = gGetSessionTimesIgnoringWeekend(pTimestamp, pStartTime, pEndTime)
    lTargetDate = DateValue(lDatumSessionTimes.StartTime) + pOffset
Else
    lDatumSessionTimes = gCalcSessionTimes(pTimestamp, pStartTime, pEndTime)
    
    Dim lTargetWorkingDayNum As Long
    lTargetWorkingDayNum = WorkingDayNumber(lDatumSessionTimes.StartTime) + pOffset
    If sessionSpansMidnight(pStartTime, pEndTime) Then lTargetWorkingDayNum = lTargetWorkingDayNum + 1
    
    lTargetDate = WorkingDayDate(lTargetWorkingDayNum, Int(lDatumSessionTimes.StartTime))
End If

With gCalcOffsetSessionTimes
    .StartTime = lTargetDate + pStartTime
    If sessionSpansMidnight(pStartTime, pEndTime) Then .StartTime = .StartTime - 1
    .EndTime = lTargetDate + pEndTime
End With

Exit Function

Err:<commit_msg>Fix bug - offset session times incorrect where session spans midnight<commit_after>Attribute VB_Name = "Globals"
Option Explicit

''
' Description here
'
'@/

'@================================================================================
' Interfaces
'@================================================================================

'@================================================================================
' Events
'@================================================================================

'@================================================================================
' Enums
'@================================================================================

'@================================================================================
' Types
'@================================================================================

'@================================================================================
' Constants
'@================================================================================

Private Const ProjectName                           As String = "SessionUtils27"
Private Const ModuleName                            As String = "Globals"

Public Const OneSecond                              As Double = 1 / 86400
Public Const OneMinute                              As Double = 1 / 1440
Public Const OneHour                                As Double = 1 / 24

'@================================================================================
' Member variables
'@================================================================================

'@================================================================================
' Class Event Handlers
'@================================================================================

'@================================================================================
' XXXX Interface Members
'@================================================================================

'@================================================================================
' XXXX Event Handlers
'@================================================================================

'@================================================================================
' Properties
'@================================================================================

'@================================================================================
' Methods
'@================================================================================

Public Function gCalcOffsetSessionTimes( _
                ByVal pTimestamp As Date, _
                ByVal pOffset As Long, _
                ByVal pStartTime As Date, _
                ByVal pEndTime As Date, _
                ByVal pIgnoreWeekends As Boolean) As SessionTimes
Const ProcName As String = "gCalcOffsetSessionTimes"
On Error GoTo Err

Dim lDatumSessionTimes As SessionTimes

Dim lTargetDate As Date

If pIgnoreWeekends Then
    lDatumSessionTimes = gGetSessionTimesIgnoringWeekend(pTimestamp, pStartTime, pEndTime)
    lTargetDate = DateValue(lDatumSessionTimes.StartTime) + pOffset
Else
    lDatumSessionTimes = gCalcSessionTimes(pTimestamp, pStartTime, pEndTime)
    
    Dim lTargetWorkingDayNum As Long
    lTargetWorkingDayNum = WorkingDayNumber(lDatumSessionTimes.EndTime) + pOffset
    
    lTargetDate = WorkingDayDate(lTargetWorkingDayNum, Int(lDatumSessionTimes.StartTime))
    If sessionSpansMidnight(pStartTime, pEndTime) Then lTargetDate = lTargetDate - 1
End If

With gCalcOffsetSessionTimes
    .StartTime = lTargetDate + pStartTime
    .EndTime = lTargetDate + pEndTime
    If sessionSpansMidnight(pStartTime, pEndTime) Then .EndTime = .EndTime + 1
End With

Exit Function

Err:
{'fraction_non_alphanumeric': 0.5084495708154506, 'fraction_numerical': 0.004828326180257511, 'mean_word_length': 6.02165725047081, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3923699', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1292, 'n_words': 316}