changeset 23:2748cd7ccfca default tip

merge fix and buffer read returns utf-8 now
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Fri, 07 Feb 2014 11:34:38 +0900
parents 8bb1a007ed89
children
files Calcon.pm
diffstat 1 files changed, 38 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/Calcon.pm	Tue Oct 22 16:39:13 2013 +0900
+++ b/Calcon.pm	Fri Feb 07 11:34:38 2014 +0900
@@ -27,7 +27,7 @@
 
 #);
 
-our $VERSION = '0.02';
+our $VERSION = '0.03';
 
 
 # Preloaded methods go here.
@@ -121,7 +121,7 @@
 
 # 時間関係のライブラリ
 
-sub localtime {
+sub localtime { # error?
     my ($self,$date) = @_;
     return $date->localtime();
 }
@@ -159,6 +159,13 @@
     bless $record,$record_class;
 }
 
+sub print {
+    my ($self) = @_;
+    foreach my $k ( keys %$self ) {
+        print " $k -> $self->{$k}\n";
+    }
+}
+
 #######################################################################/
 
 package Calcon::Record ;
@@ -204,11 +211,17 @@
     my ($self,$record) = @_;
 
     foreach my $key (keys %{$self}) {
-	next if (!defined $self->{$key} && !defined $record->{$key});
+	if (!defined $self->{$key} && !defined $record->{$key}) {
+             # print "!!!!! $key not defiend \n";
+             next;
+        }
 	if(ref $self->{$key} && ref $record->{$key}) {
 	    return 0 if (! $self->{$key}->equal($record->{$key}));
 	} else {
-	    return 0 if ($self->{$key} ne $record->{$key});
+            if ($self->{$key} ne $record->{$key}) {
+               # print "!!!!! $key not equal $self->{$key} <!!!!!> $record->{$key}\n";
+               return 0;
+            }
 	}
     }
     return 1;
@@ -498,7 +511,7 @@
 
 sub equal {
     my ($self,$date) = @_;
-    return ($self->unix_time() !=  $date->unix_time());
+    return ($self->unix_time() ==  $date->unix_time());
 }
 
 #######################################################################/
@@ -1279,6 +1292,7 @@
 
 sub same_record_in_list {
     my ($self,$list,$record) = @_;
+    return -1 if ( ! $list );
 # print "\nCampare: ";$record->value;
     record: 
     for (my $i = 0; $i<=$#{$list}; $i++) {
@@ -1348,30 +1362,23 @@
 sub address {
     my ($self,$keys,$record) = @_;
     my $name = $record->{'name'};
-    if (my $list = $self->{'-address-index'}->{$name}) {
-	my $i;
-	if (($i = $self->same_record_in_list($list,$record)) >= 0 ) {
-	    return;
-	}
-	push(@$list,$record);
-    } else {
-	push(@{$self->{'-address-index'}->{$name}},$record);
+    my $list = $self->{'-address-index'}->{$name};
+    my $i;
+    if (($i = $self->same_record_in_list($list,$record)) >= 0 ) {
+        return;
     }
+    push(@{$self->{'-address-index'}->{$name}},$record);
 }
 
 sub calendar {
     my ($self,$keys,$record) = @_;
     my $date = $record->{'date'}->unix_time();
     my $list = $self->{'-date-index'}->{$date};
-    if ($list) {
-	my $i;
-	if (($i = $self->same_record_in_list($list,$record)) >= 0 ) {
-	    return;
-	}
-	push(@$list,$record);
-    } else {
-	push(@{$self->{'-date-index'}->{$date}},$record);
+    my $i;
+    if (($i = $self->same_record_in_list($list,$record)) >= 0 ) {
+        return;
     }
+    push(@{$self->{'-date-index'}->{$date}},$record);
 }
 
 
@@ -2896,13 +2903,13 @@
     my $dtend = '';
     my $dtstamp = '';
 
-    if (! $record{'date'}->is_allday() || ! $record{'all-day'} eq 'true') {
+    if (! $record{'date'}->is_allday() || ! $record{'all-day'} eq 'true' || defined $record{'end-date'} ) {
 	if (! defined( $record{'end-date'}) || $record{'end-date'} == $record{'date'} ) {
 	    # $dtend = "\nDURATION:PT2H";  this is useless for iCal
 	    $record{'end-date'} = $record{'date'}->add(
 		$self->{'-add-time-for-allday'});
 	    $dtend = "\nDTEND;TZID=$timezone:".$self->date($record{'end-date'});
-	} else {
+	} else  {
 	    $dtend = "\nDTEND;TZID=$timezone:".$self->date($record{'end-date'});
 	}
     } else {
@@ -3580,14 +3587,14 @@
 	if (s/^([A-Za-z][-A-Za-z0-9_]*):\s*//) {
 	    $key = $1;
 	} else {
-	    $key = 'memo';
+	    $key = 'summary';
 	}
 	$key = 'memo' if ($key eq '');
         if ($key eq 'Subject') {
-	    $key = 'memo';
+	    $key = 'summary';
         }
 	s/^(\201\100)*//;
-	$_ = nkf('-sZ',$_);
+	$_ = nkf('-wZ',$_);
 	if($key eq 'time' || $key eq 'end-time') {
 	    $record->{$key} = $_; 
 	    next;
@@ -4239,10 +4246,10 @@
 } elsif (/^X-ABUID:/i) {
 } elsif (/^note:\s*(.*)/i) { $record->{'memo'} .= $1;
 } elsif (/^dtend;value\=date:\s*(.*)/i) {           $record->{'all-day'} = 'true'; $record->{'end-date'} = $self->date($1);
-} elsif (/^dtend(.*):\s*(.*)/i) { $record->{'end-date'} = $self->date($2,$1?$1:$record->{'timezone'});
-} elsif (/^dtstamp(.*):\s*(.*)/i) { $record->{'modify-date'} = $self->date($2,$1?$1:$record->{'timezone'});
-} elsif (/^dtstart;value\=date:\s*(.*)/i) {           $record->{'all-day'} = 'true'; $record->{'end-date'} = $self->date($1);
-} elsif (/^dtstart(.*):\s*(.*)/i) { $record->{'date'} = $self->date($2,$1?$1:$record->{'timezone'});
+} elsif (/^dtend(.*?):\s*([^\s]+)/i) { $record->{'end-date'} = $self->date($2,$1?$1:$record->{'timezone'});
+} elsif (/^dtstamp(.*?):\s*([^\s]+)/i) { $record->{'modify-date'} = $self->date($2,$1?$1:$record->{'timezone'});
+} elsif (/^dtstart;value\=date:\s*([^\s]+)/i) {           $record->{'all-day'} = 'true'; $record->{'end-date'} = $self->date($1);
+} elsif (/^dtstart(.*?):\s*([^\s]+)/i) { $record->{'date'} = $self->date($2,$1?$1:$record->{'timezone'});
 } elsif (/^duration:\s*(.*)/i) { $self->duration($record,$1);
 } elsif (/^email(.*):\s*(.*)/i) { $self->items($record,'mail',$1,$2);
 } elsif (/^end:\s*vcard/i) { $self->vcard($record);
@@ -4298,6 +4305,7 @@
     } elsif ($date =~ /(\d\d\d\d)(\d\d)(\d\d)/i) {
 	return $self->make_date("$1/$2/$3");
     } else  {
+        print "date error $date";
 	return "";
     }
 }