Created
February 29, 2024 06:56
-
-
Save kinuasa/b7560aa9b1fb3d844406b89152fd6751 to your computer and use it in GitHub Desktop.
指定した日時から直近の平日を求めるPower Automate for desktopフロー(動作確認:バージョン 2.41 ) 関連Webサイト:https://powerusers.microsoft.com/t5/Power-Automate-Desktop/Determining-the-date-of-the-most-recent-weekday/td-p/2630429
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/# ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ | |
祝日一覧をデータテーブルに格納 | |
※Google Calendar APIのような祝日を取得するAPIを利用しても可 | |
☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★#/ | |
SET HolidayTable TO { ^['Date', 'Summary'], ['2024-01-01', '元日'], ['2024-01-08', '成人の日'], ['2024-02-11', '建国記念の日'], ['2024-02-12', '建国記念の日 振替休日'], ['2024-02-23', '天皇誕生日'], ['2024-03-20', '春分の日'], ['2024-04-29', '昭和の日'], ['2024-05-03', '憲法記念日'], ['2024-05-04', 'みどりの日'], ['2024-05-05', 'こどもの日'], ['2024-05-06', 'こどもの日 振替休日'], ['2024-07-15', '海の日'], ['2024-08-11', '山の日'], ['2024-08-12', '休日 山の日'], ['2024-09-16', '敬老の日'], ['2024-09-22', '秋分の日'], ['2024-09-23', '秋分の日 振替休日'], ['2024-10-14', 'スポーツの日'], ['2024-11-03', '文化の日'], ['2024-11-04', '文化の日 振替休日'], ['2024-11-23', '勤労感謝の日'] } | |
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime | |
# テスト用に日時設定 | |
Text.ConvertTextToDateTime.ToDateTime Text: $'''2024/5/8''' DateTime=> CurrentDateTime | |
/# ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ | |
指定日の2日前から14日間さかのぼって祝休日かどうかの判定を行う | |
☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★#/ | |
LOOP LoopIndex FROM 2 TO 14 STEP 1 | |
# 平日かどうかのフラグ[FlagWeekday]の初期値をTrueにする | |
SET FlagWeekday TO True | |
# [加算する日時]アクションで指定日からLoopIndex日さかのぼる | |
DateTime.Add DateTime: CurrentDateTime TimeToAdd: $'''-%LoopIndex%''' TimeUnit: DateTime.TimeUnit.Days ResultedDate=> ResultedDate | |
# DayOfWeekプロパティで曜日を取得し、Switchで判定を行う | |
SWITCH ResultedDate.DayOfWeek.ToLower | |
CASE = $'''saturday''' | |
SET FlagWeekday TO False | |
CASE = $'''sunday''' | |
SET FlagWeekday TO False | |
DEFAULT | |
# 祝日一覧データテーブルを使って祝日かどうかの判定を行う | |
LOOP FOREACH HolidayRow IN HolidayTable | |
/# 指定された2つの日時の時間差を求める[日付の減算]アクションを使って、対象となる日時が祝日一覧データテーブルの日時と一致するかを判定する | |
(差がゼロであれば祝日)#/ | |
Text.ConvertTextToDateTime.ToDateTime Text: HolidayRow['Date'] DateTime=> TextAsDateTime | |
DateTime.Subtract FromDate: ResultedDate SubstractDate: TextAsDateTime TimeUnit: DateTime.DifferenceTimeUnit.Days TimeDifference=> TimeDifference | |
IF TimeDifference = 0 THEN | |
SET FlagWeekday TO False | |
EXIT LOOP | |
END | |
END | |
END | |
# 平日かどうかのフラグがTrueであればループを抜ける | |
IF FlagWeekday = $'''True''' THEN | |
EXIT LOOP | |
END | |
END | |
Display.ShowMessageDialog.ShowMessage Message: $'''last weekday: %ResultedDate.Year%/%ResultedDate.Month%/%ResultedDate.Day%''' Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment