ループを使用せずにn番目の営業日を見つける手順を考案しました。
これについてあなたの提案を持ってきてください -
営業日を操作するアルゴリズム -
問題: 特定の日から n 番目の営業日の日付を見つけます。
解決:
最も近い月曜日に正規化 -
If today(or the initial day) happens to be something other than monday, bring the day to the closest monday by simple addition or subtraction.
例: 初日 - 10 月 17 日。たまたま水曜日です。したがって、2 つの日付を下に移動して、この月曜日でないことを正規化します。ここで、この 2 つの日付に名前を付けます。初期正規化係数です。
これらの週に該当する稼働日数 + 週末を追加します。
例: 10 営業日を追加するには、12 日を追加する必要があります。10 日間は 1 週間に 1 土曜日と 1 日曜日しか含まれないためです。これは、最も近い月曜日に正規化しているためです。
償却 -
ここで、終了日から、初期正規化係数 (負の初期正規化の場合) と別の定数係数 (k など) を追加します。または、最初の正規化が金曜日から取得された場合は 1 を追加します。これはたまたま +3 です。開始日が土曜日と日曜日の場合は、月曜日として扱います。したがって、この段階では償却は必要ありません。
例: 最初の正規化が水曜日からのものである場合、最初の正規化係数は -2 です。したがって、終了日と定数 k に 2 を追加します。
The constant k is either 2 or 0.
定数定義 -
If initial normalization factor is -3, then add 2 to the resulting date if the day before amortization is (wed,thu,fri)
If initial normalization factor is -2, then add 2 to the resulting date if the day before amortization is (thu,fri)
If initial normalization factor is -1, then add 2 to the resulting date if the day before amortization is (fri)
例 -
Find the 15th working day from Oct,17 (wednesday).
ステップ1 -
初期正規化 = -2 現在、開始日は 10 月 15 日 (月曜日) です。
ステップ2 -
add 15 working days -
15 days => 2 weeks
weekends = 2 (2 sat, 2 sun)
so add 15 + 4 = 19 days to Oct, 15 monday.
end_date = 2, nov, Friday
ステップ 3a -
end_date = end_date + initial normalization = 4, nov sunday
ステップ 3b -
end_date = end_date + constant_factor = 4, nov, sunday + 2 = 6, nov (Tuesday)
クロス検証 -
Add 15th working day to Oct, 17 wednesday
Oct,17 + 3 (Oct 17,18,19) + 5 (Oct 22-26) + 5 (Oct 29 - Nov 2) + 2 (Nov 5, Nov 6)
Now the answer is 6, Nov, Tuesday.
いくつかのケースで確認しました。あなたの提案を共有してください。
ラーセン。