Subject: | BEGIN:VCALENDAR/END:CALENDAR:VCA for every event |
Date: | Thu, 24 Jul 2014 11:31:58 -0300 |
To: | bug-Tie-iCal [...] rt.cpan.org |
From: | "Diego M. Vadell" <dvadell [...] clustering.com.ar> |
Hello,
Thanks a lot for Tie::iCal!!! I've been using the last version and I get
calendars with this lines added at the beginning, for every event:
END:VCALENDAR
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Numen Inest/NONSGML Tie::iCal 0.15//EN
And at the end:
END:VCALENDAR
I've been reading the source, and STORE calls toiCal:
$self->toiCal($uid, $c)
In that function, the first lines are:
--------------
my $self = shift;
my $uid = shift;
my $c = shift;
my $excludeComponent = shift;
my @lines;
my ($component, $e) = $excludeComponent ? (undef, $c) : @$c;
push @lines, "BEGIN:VCALENDAR", "VERSION:2.0", "PRODID:-//Numen
Inest/NONSGML Tie::iCal $VERSION//EN", "BEGIN:$component", "UID:$uid" if !
$excludeComponent;
---------------
So it looks like for every STORE, the first lines are the ones that
shouldn't be there.
This is an example:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Numen Inest/NONSGML Tie::iCal 0.15//EN
BEGIN:VEVENT
UID:1406210085
SUMMARY:Meter la carne en el freezer
DTEND:20140724T105700Z
DTSTART:20140724T105400Z
END:VEVENT
END:VCALENDAR
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Numen Inest/NONSGML Tie::iCal 0.15//EN
BEGIN:VEVENT
UID:1406210177
DTEND:20140724T105900Z
SUMMARY:Meter la carne en el freezer
DTSTART:20140724T105600Z
END:VEVENT
END:VCALENDAR
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Numen Inest/NONSGML Tie::iCal 0.15//EN
BEGIN:VEVENT
UID:1406210183
DTEND:20140724T105900Z
SUMMARY:Meter la carne en el freezer
DTSTART:20140724T105600Z
END:VEVENT
END:VCALENDAR
And this is the code I've been using:
--------------------------------------------------
#!/usr/bin/perl
use strict; use warnings;
use Tie::iCal;
use Time::Piece;
use Time::Seconds;
use Data::Dumper::Simple;
guardar_evento(200, "Meter la carne en el freezer");
# guardar_eventos guarda en iCal.
sub guardar_evento {
my ($segundos, $contenido) = @_;
my %my_events;
my $calfile = $ENV{HOME} . "/bubu.ics";
tie %my_events, 'Tie::iCal', $calfile or die "Failed to tie file!\n";
print Dumper( %my_events );
# Summary no puede tener espacios, así que lo cambio por \n
$contenido =~ s/\n/\\n/gs;
my $uid = time();
$my_events{$uid} = [
'VEVENT',
{
'SUMMARY' => $contenido,
'DTSTART' => secs_to_ical_date(0),
'DTEND' => secs_to_ical_date($segundos),
'DTEND' => secs_to_ical_date($segundos),
}
];
untie %my_events;
}
# Esta func agrega $secs segundos a la fecha/hora actual
# y lo devuevle en el formato para iCal
sub secs_to_ical_date {
my ($secs) = @_;
my $now = mk_time_piece_now();
$now += $secs;
my $date = $now->strftime( "%Y%m%d" ) . "T" .
$now->strftime( "%H%M00" ) . "Z";
return $date;
}
sub mk_time_piece_now {
# Esto pasa porque el objeto Time::Piece que resulta de localtime tiene
# mal el timezone. Así que lo hago string, y lo vuelvo a hacer
# objeto.
my $now = localtime;
my $now_string = $now->strftime("%d-%m-%Y %H:%M");
$now = Time::Piece->strptime($now_string, "%d-%m-%Y %H:%M");
return $now;
}
---------------
Again, thanks. This it the only module I could make to work, and I tried
quite a few.
Cheers,
-- Diego