我应该使用哪个 CPAN 模块来提前计算工作日数

发布于 2024-12-11 12:18:31 字数 439 浏览 0 评论 0原文

这是一个由两部分组成的问题:

我想用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪眸﹌ 2024-12-18 12:18:31

printf 方法应命名为 sprintf。它返回格式化的字符串;它不打印它。尝试:

print $date->printf("It is now %b %e, %Y.\n");

Date::Manip 可能是处理工作日的最简单方法,因为它具有内置的概念。您也可以使用 DateTime::Set 来完成此操作运营(参见 DateTime::Event::Holiday::US< /a> 用于预先填充美国假期的集合)。

还有 DateTime::BusinessHours,但我从未尝试过。

The printf method should have been named sprintf. It returns the formatted string; it doesn't print it. Try:

print $date->printf("It is now %b %e, %Y.\n");

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.

删除→记忆 2024-12-18 12:18:31

DateTime 相比,DateTime 是轻量级的。 org/module/Date%3a%3aManip" rel="nofollow">Date::Manip。另请查看 Date::Business。它可以处理假期和工作日(addb)。

DateTime is lightweight compared to Date::Manip. Also have a look at Date::Business. It can deal with holidays and business days (addb).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文