我应该使用哪个 CPAN 模块来提前计算工作日数
这是一个由两部分组成的问题:
我想用 Perl 计算(比如说)提前 5 个工作日。兼顾周末和节假日。 Date::Manip
就是这样做的,但是非常重量级。有没有重量更轻的模块可以很好地做到这一点?
如果 Date::Manip
确实是正确的选择,您能告诉我为什么它不打印任何内容吗?关于如何实际输出内容的 Date::Manip
文档非常薄弱。
use Date::Manip;
my $date = new Date::Manip::Date;
my $err = $date->parse("today");
if ($err) {
print "Problems: $err\n";
}
$date->printf("It is now %b %e, %Y.\n");
This is a two-part question:
I want to calculate (say) 5 business days ahead in Perl. Accounting for both weekends and holidays. Date::Manip
does this, but is very heavyweight. Is there a lighter weight module that would do this well?
If Date::Manip
is indeed the right choice, can you tell me why this doesn't print anything. The documentation for Date::Manip
on how to actually output stuff is very thin.
use Date::Manip;
my $date = new Date::Manip::Date;
my $err = $date->parse("today");
if ($err) {
print "Problems: $err\n";
}
$date->printf("It is now %b %e, %Y.\n");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
printf
方法应命名为sprintf
。它返回格式化的字符串;它不打印它。尝试:Date::Manip 可能是处理工作日的最简单方法,因为它具有内置的概念。您也可以使用 DateTime::Set 来完成此操作运营(参见 DateTime::Event::Holiday::US< /a> 用于预先填充美国假期的集合)。
还有 DateTime::BusinessHours,但我从未尝试过。
The
printf
method should have been namedsprintf
. It returns the formatted string; it doesn't print it. Try:Date::Manip is probably the easiest way to handle business days, as it has the concept built in. You could also do it with DateTime::Set operations (see DateTime::Event::Holiday::US for a set pre-filled with U.S. holidays).
There's also DateTime::BusinessHours, but I've never tried it.
与
DateTime
相比,DateTime
是轻量级的。 org/module/Date%3a%3aManip" rel="nofollow">Date::Manip
。另请查看Date::Business
。它可以处理假期和工作日(addb
)。DateTime
is lightweight compared toDate::Manip
. Also have a look atDate::Business
. It can deal with holidays and business days (addb
).