【问题标题】:Mark iCal event as "all day" with Perl module Data::ICal使用 Perl 模块 Data::ICal 将 iCal 事件标记为“全天”
【发布时间】:2013-09-06 17:01:04
【问题描述】:

有一个巨大的 Perl 模块 Data::ICal 可以创建 iCal 文件,这些文件可以添加到 mac 上的日历应用程序中(它们也可以添加到许多其他程序中)。

我使用过Data::ICal,并编写了一个创建 iCal 文件的简单脚本。我已将它添加到日历应用程序中,它运行良好。

这里是列表:

#!/usr/bin/perl

use strict;
use warnings FATAL => 'all';

use Data::ICal;
use Data::ICal::Entry::Event;
use Date::ICal;
use File::Slurp;

my $calendar = Data::ICal->new();

my $ical_date = Date::ICal->new(
    year => 2013,
    month => 9,
    day => 6,
);

my $event = Data::ICal::Entry::Event->new();
$event->add_properties(
    summary => "my party",
    description => "I'll cry if I want to",
    dtstart => $ical_date->ical(),
);

$calendar->add_entry($event);

write_file('sample.ics', $calendar->as_string);

但现在我想将此事件标记为持续一整天。我已经 grepped throw 模块源文档和代码,但我还没有找到方法。

如何将此活动标记为持续一整天?

【问题讨论】:

    标签: perl cpan icalendar


    【解决方案1】:

    根据innerjoin 上的description,您所要做的就是将dtstartdtend 设置为YYYYMMDD(无小时或以下),其中开始是(您的聚会的)一天并结束下一个天。

    至少对于雷鸟/太阳鸟来说,这可以完美地工作:

    #!/usr/bin/perl
    
    use strict;
    
    use Data::ICal;
    use Data::ICal::Entry::Event;
    use File::Slurp;
    
    my $calendar = Data::ICal->new();
    
    my $event = Data::ICal::Entry::Event->new();
    $event->add_properties(
        summary     => "my party",
        description => "I'll cry if I want to",
        dtstart     => "20130906",
        dtend       => "20130907",
    );
    
    $calendar->add_entry($event);
    
    write_file('sample.ics', $calendar->as_string);
    

    【讨论】:

    • 是的!它完美地解决了我的问题。谢谢你。 (实际上我不喜欢这个解决方案,因为它看起来像 hack,但它确实有效,因为我不知道其他解决方案,所以我将使用此代码)
    猜你喜欢
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 2020-09-20
    • 2012-08-17
    • 2013-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多