Subject: | Namespace and when fix |
The namespace gets dropped from critical elements in the <gd:...>
namespace, which results in Google simply dropping them. The underlying
problem is the SUPER::_initialize call, which isn't populating the
$self->{_gd_ns} array.
I would have liked to have isolated the cause of that further, but time
is not on my side and would rather just alert you to the issue.
The other issue is a revamp of the "when" method, which now allows
better support for all the other options (single day events without
having to unnecessarily add hours on to $end)
Subject: | when_ns.patch |
=== lib/Net/Google/Calendar/Entry.pm
==================================================================
--- lib/Net/Google/Calendar/Entry.pm (revision 8581)
+++ lib/Net/Google/Calendar/Entry.pm (local)
@@ -54,6 +54,10 @@
$self->SUPER::_initialize();
$self->category({ scheme => 'http://schemas.google.com/g/2005#kind', term => 'http://schemas.google.com/g/2005#event' } );
$self->set_attr('xmlns:gd', 'http://schemas.google.com/g/2005');
+ unless ( $self->{_gd_ns} ) {
+ my $ns = XML::Atom::Namespace->new(gd => 'http://schemas.google.com/g/2005');
+ $self->{_gd_ns} = $ns;
+ }
}
=head2 id [id]
@@ -180,36 +184,61 @@
=head2 when [<start> <end> [allday]]
-Get or set the start and end time as supplied as DateTime objects.
-End must be more than start.
+The when method has multiple behaviors based upon the parameters being passed in
-You may optionally pass a paramter in designating if this is an all day event or not.
+For full reference, please see L<http://code.google.com/apis/gdata/elements.html#gdWhen>
-Returns two DateTime objects depicting the start and end.
+The default behavior is to pass in a start and end date, and an optional
+allday parameter (true value as the third arguemnt).
+If start and end times are the same, with the allday flag, it is a one-day event
+Get or set the start and end time as supplied as DateTime objects.
+End must be more than start if specified. If end is not specified, it is a
+zero-time occurrence.
+
+Returns up to two DateTime objects depicting the start and end.
+
=cut
sub when {
my $self = shift;
- if (@_) {
+ if ( @_ >= 2 ) {
my ($start, $end, $allday) = @_;
$allday = 0 unless defined $allday;
- unless ($end>$start) {
- $@ = "End is not less than start";
+ my $cmp = DateTime->compare( $start, $end );
+ # If they're the same, it must be all day, or $end must be greater than
+ # start
+ if ( ( $cmp == 0 and not $allday ) or $cmp > 0 ) {
+ $@ = "End time must be after start time";
return undef;
- }
+ }
$start->set_time_zone('UTC');
$end->set_time_zone('UTC');
my $format = $allday ? "%F" : "%FT%TZ";
+ if ( $cmp == 0 ) {
+ $self->set($self->{_gd_ns}, "when", '', {
+ startTime => $start->strftime($format),
+ });
+ } else {
+ $self->set($self->{_gd_ns}, "when", '', {
+ startTime => $start->strftime($format),
+ endTime => $end->strftime($format),
+ });
+ }
+ }
+ # Single date, is a zero duration event
+ elsif ( @_ == 1 ) {
+ my ( $start ) = @_;
+ $start->set_time_zone('UTC');
$self->set($self->{_gd_ns}, "when", '', {
- startTime => $start->strftime($format),
- endTime => $end->strftime($format),
- });
+ startTime => $start->strftime("%FTTZ"),
+ });
}
+
my $start = $self->_attribute_get($self->{_gd_ns}, 'when', 'startTime');
my $end = $self->_attribute_get($self->{_gd_ns}, 'when', 'endTime');
my @rets;