# Copyright (c) 2010 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: CalendarEventRecurrence.pm,v 1.1 2010/01/15 06:22:22 nagler Exp $ package Bivio::Type::CalendarEventRecurrence; use strict; use Bivio::Base 'Type.Enum'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.1 $ =~ /\d+/g); my($_DT) = b_use('Type.DateTime'); my($_TOO_SHORT) = b_use('Bivio.TypeError')->TOO_SHORT; my($_TOO_LONG) = b_use('Bivio.TypeError')->TOO_LONG; my($_NULL) = b_use('Bivio.TypeError')->NULL; my($_EXISTS) = b_use('Bivio.TypeError')->EXISTS; __PACKAGE__->compile([ UNKNOWN => [0, 'None'], EVERY_WEEK => 1, EVERY_TWO_WEEKS => 2, EVERY_FOUR_WEEKS => 4, ]); sub is_continuous { return 0; } sub period_in_days { return shift->as_int * 7; } sub validate_end_date { my($self, $end_date, $recurrence_end_date) = @_; if ($self->eq_unknown) { return $_EXISTS if $recurrence_end_date; return undef; } return $_NULL unless $recurrence_end_date; my($dd) = $_DT->delta_days($end_date, $recurrence_end_date); return $dd < 7 ? $_TOO_SHORT : $dd >= 365 ? $_TOO_LONG : undef, } 1;