Powershell Golf:下一个工作日
问题描述:
如何使用 powershell 查找下一个工作日?
How to find next business day with powershell ?
答
这也很短(但使用别名):
This is pretty short too (but uses aliases):
,(1,2-eq7-(date).dayofweek)|%{(date)+"$(1+$_[0])"}
在一个声明中:
(date)+"$(1+$(@(1,2-eq7-(date).dayofweek)))"
关于这种方法的一些注意事项:
A few notes about this approach:
在 Powershell(至少 v1)中,与集合的比较返回条件为真的项目,例如:
In Powershell (v1 at least), comparisons with collections return items where the condition is true, for example:
PS>1,2 -eq 1
PS>1
我正在利用规则today + 1
的实际例外来计算下一个工作日的事实只有周五(+3 天)和周六(+2天).
I'm taking advantage of the fact that the actual exceptions to the rule today + 1
to calculate the next business day are only Friday (+3 days) and Saturday (+2 days).