Wrote a perl script to convert ics files (what google calendar exports as) to UTC time. Still has absolute paths and I mean to write a cron job to download and import it every <time here> but I have to get to work.
UPDATED
Code:
#!/usr/bin/perl -w
#################################
### A Simple regex program to ###
### change from one timezone ###
### to another with ics files ###
### ###
### Shawn Dyjak ###
### dyjaks@gmail.com ###
#################################
use Time::Local;
$infile = $ARGV[0];
$outfile = $ARGV[1];
if (!$infile || !$outfile) {
print "Welcome to tz_convert. You must specify files to use!\n";
print "Usage : perl tz_convert <read file> <output file>\n";
exit;
}
open(INFILE, "+<$infile") or die $!;
my @lines = <INFILE>;
$count = 0;
foreach (@lines) {
if ($_ =~ /DTSTART:(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})/) {
my ($year, $mon, $day, $hour, $min) =
$_ =~ /(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})/;
my $time = timegm(0, $min, $hour, $day, $mon- 1, $year - 1900);
(undef, $min, $hour, $day, $mon, $year) = localtime($time);
my $local_date = sprintf "%d%02d%02dT%02d%02d00Z\n", $year + 1900, $mon + 1, $day, $hour, $min;
$lines[$count] = "DTSTART:$local_date";
} elsif ($_ =~ /DTEND:(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})/) {
my ($year, $mon, $day, $hour, $min) =
$_ =~ /(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})/;
my $time = timegm(0, $min, $hour, $day, $mon- 1, $year - 1900);
(undef, $min, $hour, $day, $mon, $year) = localtime($time);
my $local_date = sprintf "%d%02d%02dT%02d%02d00Z\n", $year + 1900, $mon + 1, $day, $hour, $min;
$lines[$count] = "DTEND:$local_date";
}
$count++;
}
close(INFILE);
open(INFILE, ">$outfile") or die $!;
$count = 0;
foreach (@lines) {
print INFILE "$lines[$count]";
$count++;
}
close(INFILE);
Bookmarks