テストのし易さ

今年に入ってから動作しないと言われたPG

'日付範囲の計算
Public Function calcDate(tDate As Date)
    endDate = DateAdd("d", -1, tDate) '前日

    If Day(endDate) <= DAY処理境界 Then
        '2022/1/11 日付計算バグを修正
'        startDate = CDate(Year(endDate) & "/" & Month(DateAdd("m", -1, endDate)) & "/" & DAY締切翌日)
        Dim tmpDate: tmpDate = DateAdd("m", -1, endDate)
        startDate = Year(tmpDate) & "/" & Month(tmpDate) & "/" & DAY締切翌日
    Else
        startDate = CDate(Year(endDate) & "/" & Month(endDate) & "/" & DAY締切翌日)
    End If
End Function

★気に入らない点
・関数名が意味不明
・DAY締切翌日が2回書いてある → DAY締切翌日は引数で渡すべき
グローバル変数っぽい「endDate」と「startDate」を 更新している → endDateは引数で渡すべき

整理すると、関数名はgetZenkaiCutoffDateかなぁ、、

'開始日の取得(終了日と「前回締日の翌日の日」を受け取り、「前回締日の翌日」を返却する)
Public Function getZenkaiCutoffDate(endDate As Date, CutoffDay As Integer) As Date

    Dim tmpDate: tmpDate = DateSerial(Year(endDate), Month(endDate), CutoffDay)

    If Day(endDate) <= CutoffDay Then
        tmpDate = DateAdd("m", -1, tmpDate)
    End If

    getZenkaiCutoffDate= tmpDate

End Function
/* -----codeの行番号----- */