Reputation: 643
I need to take the result of a Date::Manip ParseDateString()
and use it as the bast for an Date::ICal::Event
Date::ICal::Event
has the following date creating inputs:
use Date::ICal;
$ical = Date::ICal->new( ical => '19971024T120000' );
$ical = Date::ICal->new( epoch => time );
$ical = Date::ICal->new( year => 1964,
month => 10, day => 16, hour => 16,
min => 12, sec => 47 );
Date::Manip ParseDateString()
returns a standard date value.
How should I use that date in the ICal date? Convert to epoch? Can it easily be converted to the ical format? I feel like this should be easier than it is.
Upvotes: 1
Views: 537
Reputation: 12097
It seems that, if you've got a date into Date::Manip successfully, you can just use its printf directives to output it in any format you want.
It looks like %Y%m%dT%H%M%S
is what you want for iCal.
Upvotes: 1
Reputation: 69314
Your life will be so much easier if you dump Date::Manip and switch to DateTime for all your date and time processing. There's even a DateTime::Format::ICal to help with this specific task.
Upvotes: 1
Reputation: 643
I did some further CPAN hunting and came up with the module DateTime::Format::DateManip
Using this I was able to convert it to a DateTime representation and then get the epoch from that using the epoch method available in DateTime:
my $cagedate = ParseDateString($cagewatch);
my $cagedatetime = DateTime::Format::DateManip->parse_datetime($cagedate);
$vevent->add_properties(
summary => $cagemovie,
description => $cagemovie,
dtstart => Date::ICal->new( epoch => $cagedatetime->epoch )->ical,
);
Just in case you are curious about the CAGE variables. I was parsing the list of movies for the Year of the Cage. All Nick Cage, all year. Oh yeah.
Upvotes: 1
Reputation: 62109
Here's what I'd do:
sub date2ical
{
my $date = shift;
Date::ICal->new( ical => UnixDate($date, '%QT%H%M%S'), # %Q means %Y%m%d
offset => UnixDate($date, '%z'));
} # end date2ical
# Usage:
my $ical = date2ical(ParseDateString('today'));
This should properly handle timezones (provided Date::Manip gets the timezone right).
Upvotes: 1