示例#1
0
recurrence.set_by_set_pos_array(array)
assert recurrence.get_by_set_pos(0) == 900
assert recurrence.get_by_set_pos(1) == 901
assert recurrence.get_by_set_pos(2) == ICalGLib.RecurrenceTypeArrayMaxValues.RECURRENCE_ARRAY_MAX
array = recurrence.get_by_set_pos_array()
assert array[0] == 900
assert array[1] == 901
assert array[2] == ICalGLib.RecurrenceTypeArrayMaxValues.RECURRENCE_ARRAY_MAX

recurrence.set_by_second(0, 13)
by_second = recurrence.get_by_second_array()
assert by_second[0] == 13

recurrence = ICalGLib.RecurrenceType.from_string(string)

assert(ICalGLib.recur_string_to_weekday("MO") == ICalGLib.RecurrenceTypeWeekday.MONDAY_WEEKDAY)

start = 100000
result = ICalGLib.recur_expand_recurrence(string, start, 10)
secs_per_day = 24*60*60
for i in range(0, 9):
    assert(result[i] == start + i*secs_per_day)

string = "19970101T183248Z/19970102T071625Z"

period = ICalGLib.PeriodType.from_string(string)
start = period.get_start()

iter = ICalGLib.RecurIterator.new(recurrence, start)
timetype = iter.next()
day = timetype.get_day()
示例#2
0
# The value is dependent on the libical version.
assert len(by_week_no) == 54 or len(by_week_no) == 56;
by_month = recurrence.get_by_month();
# The value is dependent on the libical version.
assert len(by_month) == 13 or len(by_month) == 14;
by_set_pos = recurrence.get_by_set_pos();
# The value is dependent on the libical version.
assert len(by_set_pos) == 367 or len(by_set_pos) == 386;

recurrence.set_by_second(0, 1);
by_second = recurrence.get_by_second();
assert by_second[0] == 1;

recurrence = ICalGLib.RecurrenceType.from_string(string);

assert(ICalGLib.recur_string_to_weekday("MO") == ICalGLib.RecurrenceTypeWeekday.MONDAY_WEEKDAY);

start = 100000;
result = ICalGLib.recur_expand_recurrence(string, start, 10);
secs_per_day = 24*60*60;
for i in range(0, 9):
    assert(result[i] == start + i*secs_per_day);

string = "19970101T183248Z/19970102T071625Z";

period = ICalGLib.PeriodType.from_string(string);
start = period.get_start();

iter = ICalGLib.RecurIterator.new(recurrence, start);
timetype = iter.next();
day = timetype.get_day();
示例#3
0
# Or:
#
#   The Mozilla Public License Version 2.0. You may obtain a copy of
#   the License at http://www.mozilla.org/MPL/
#
###############################################################################

import gi

gi.require_version('ICalGLib', '3.0')

from gi.repository import ICalGLib

message = "This is a stinky error!"

string_rep = ICalGLib.error_strerror(ICalGLib.ErrorEnum.NEWFAILED_ERROR)
assert (string_rep ==
        "NEWFAILED: Failed to create a new object via a *_new() routine")
string_perror = ICalGLib.error_perror()
assert (string_perror == "NO: No error")

ICalGLib.error_set_error_state(ICalGLib.ErrorEnum.NEWFAILED_ERROR,
                               ICalGLib.ErrorState.FATAL)
state = ICalGLib.error_get_error_state(ICalGLib.ErrorEnum.NEWFAILED_ERROR)
assert (state == ICalGLib.ErrorState.FATAL)

ICalGLib.error_stop_here()
enumeration = ICalGLib.errno_return()
string_rep = ICalGLib.error_strerror(enumeration)
assert (string_rep == "NO: No error")
示例#4
0
def main():
    #Test as_ical_string_r
    comp = ICalGLib.Component.new_from_string(event_str1)
    string = comp.as_ical_string_r()

    #Test new_clone
    clone = comp.new_clone()
    string1 = clone.as_ical_string_r()
    assert (string == string1)
    assert (comp.is_valid() == 1)
    assert (comp.isa_component() == 1)
    assert (comp.isa() == ICalGLib.ComponentKind.VEVENT_COMPONENT)

    #Test check_restrictions
    assert (comp.check_restrictions() == 0)

    #Test count_errors
    assert (comp.count_errors() == 0)

    #Test kind_is_valid
    assert (ICalGLib.Component.kind_is_valid(
        ICalGLib.ComponentKind.VEVENT_COMPONENT) == True)

    #Test kind_to_string
    kind_string = ICalGLib.Component.kind_to_string(
        ICalGLib.ComponentKind.VEVENT_COMPONENT)
    assert (ICalGLib.Component.string_to_kind(kind_string) ==
            ICalGLib.ComponentKind.VEVENT_COMPONENT)

    #Test child component manipulation
    parent = ICalGLib.Component.new_from_string(event_str1)
    comp1 = ICalGLib.Component.new_from_string(event_str2)
    comp2 = ICalGLib.Component.new_from_string(event_str3)
    comp3 = ICalGLib.Component.new_from_string(event_str4)
    comp4 = ICalGLib.Component.new_from_string(event_str5)

    parent.add_component(comp1)
    parent.add_component(comp2)
    parent.add_component(comp3)
    parent.add_component(comp4)

    assert parent.count_components(
        ICalGLib.ComponentKind.VEVENT_COMPONENT) == 3
    assert parent.count_components(
        ICalGLib.ComponentKind.VCALENDAR_COMPONENT) == 1

    #Traverse with internal API.
    count = parent.count_components(ICalGLib.ComponentKind.VEVENT_COMPONENT)
    child_component = parent.get_first_component(
        ICalGLib.ComponentKind.VEVENT_COMPONENT)
    for i in range(0, count):
        prefix = "test"
        index = i + 2
        assert (child_component.get_summary() == prefix + str(index))
        if (i != count - 1):
            child_component = parent.get_next_component(
                ICalGLib.ComponentKind.VEVENT_COMPONENT)

    #Traverse with external API.
    iter = parent.begin_component(ICalGLib.ComponentKind.VEVENT_COMPONENT)
    child_component = iter.deref()
    child_component.set_owner(parent)
    for i in range(0, count):
        prefix = "test"
        index = i + 2
        assert (child_component.get_summary() == prefix + str(index))
        if (i != count - 1):
            child_component = iter.next()
            child_component.set_owner(parent)

    iter = parent.end_component(ICalGLib.ComponentKind.VEVENT_COMPONENT)
    child_component = iter.prior()
    child_component.set_owner(parent)
    for i in range(0, count):
        prefix = "test"
        index = count + 1 - i
        assert (child_component.get_summary() == prefix + str(index))
        if (i != count - 1):
            child_component = iter.prior()
            child_component.set_owner(parent)

    #Traverse and remove with external API.
    iter = parent.begin_component(ICalGLib.ComponentKind.VEVENT_COMPONENT)
    child_component = iter.deref()
    for i in range(0, count):
        if (i != count - 1):
            iter.next()
        parent.remove_component(child_component)
        if (i != count - 1):
            child_component = iter.deref()
    assert parent.count_components(
        ICalGLib.ComponentKind.VEVENT_COMPONENT) == 0

    #Test property mainpulation
    property_string = "SUMMARY:Bastille Day Party"
    string_property = ICalGLib.Property.new_from_string(property_string)
    component = ICalGLib.Component.new(ICalGLib.ComponentKind.VEVENT_COMPONENT)
    component.add_property(string_property)
    assert (component.count_properties(
        ICalGLib.PropertyKind.SUMMARY_PROPERTY) == 1)
    component.remove_property(string_property)
    assert (component.count_properties(
        ICalGLib.PropertyKind.SUMMARY_PROPERTY) == 0)

    component.add_property(string_property)
    property_string2 = "SUMMARY:event-uid-123"
    string_property2 = ICalGLib.Property.new_from_string(property_string2)
    component.add_property(string_property2)
    component.add_property(
        ICalGLib.Property.new_from_string("SUMMARY:20140306T090000"))
    assert (component.count_properties(
        ICalGLib.PropertyKind.SUMMARY_PROPERTY) == 3)
    property1 = component.get_first_property(
        ICalGLib.PropertyKind.SUMMARY_PROPERTY)
    assert (property1.as_ical_string_r().split(
        '\n', 1)[0] == "SUMMARY:Bastille Day Party\r")
    property2 = component.get_next_property(
        ICalGLib.PropertyKind.SUMMARY_PROPERTY)
    assert (property2.as_ical_string_r().split(
        '\n', 1)[0] == "SUMMARY:event-uid-123\r")
    property3 = component.get_next_property(
        ICalGLib.PropertyKind.SUMMARY_PROPERTY)
    assert (property3.as_ical_string_r().split(
        '\n', 1)[0] == "SUMMARY:20140306T090000\r")

    #Test getters and setters
    #Test get_dtstart and get_dtend
    comp = ICalGLib.Component.new_from_string(event_str1)
    dtstart = comp.get_dtstart()
    start_string = ICalGLib.time_as_ical_string_r(dtstart)
    assert (start_string == "20140306T090000")
    dtend = comp.get_dtend()
    end_string = ICalGLib.time_as_ical_string_r(dtend)
    assert (end_string == "20140306T093000")

    #Test span
    span = comp.get_span()
    assert (span.get_start() == 1394096400)
    assert (span.get_end() == 1394098200)
    assert (span.is_busy() == 1)
    utc = ICalGLib.Timezone.get_utc_timezone()
    comp.set_dtstart(ICalGLib.time_from_timet_with_zone(1494096400, 0, utc))
    comp.set_dtend(ICalGLib.time_from_timet_with_zone(1494098200, 0, utc))
    span = comp.get_span()
    assert (span.get_start() == 1494096400)
    assert (span.get_end() == 1494098200)
    assert (span.is_busy() == 1)

    #Test set_summary/get_summary
    assert (comp.get_summary() == "test1")
    comp.set_summary("newSummary")
    assert (comp.get_summary() == "newSummary")

    #Test set_comment/get_comment
    assert (comp.get_comment() == None)
    comp.set_comment("newcomment")
    assert (comp.get_comment() == "newcomment")

    #Test set_uid/get_uid
    assert (comp.get_uid() == "event-uid-123")
    comp.set_uid("newuid")
    assert (comp.get_uid() == "newuid")

    #Test set_relcalid/get_relcalid
    assert (comp.get_relcalid() == None)
    comp.set_relcalid("newrelcalid")
    assert (comp.get_relcalid() == "newrelcalid")

    #Test set_description/get_description
    assert (comp.get_description() == None)
    comp.set_description("newdescription")
    assert (comp.get_description() == "newdescription")

    #Test set_location/get_location
    assert (comp.get_location() == "Location")
    comp.set_location("newlocation")
    assert (comp.get_location() == "newlocation")

    #Test set_sequence/get_sequence
    assert (comp.get_sequence() == 0)
    comp.set_sequence(5)
    assert (comp.get_sequence() == 5)

    #Call comp_foreach_tzid
    comp_foreach_tzid(comp, setParam, "America/Chicago")
示例#5
0
timezone = ICalGLib.Timezone.array_element_at(timezones, 0)
if not ICalGLib.Timezone.get_builtin_tzdata():
    assert timezone.get_display_name() == "Europe/Andorra"
assert timezones.size() > 0

from_tzid = ICalGLib.Timezone.get_builtin_timezone_from_tzid(la.get_tzid())
assert from_tzid.get_location() == "America/Los_Angeles"

utc = ICalGLib.Timezone.get_utc_timezone()
assert utc.get_display_name() == "UTC"
utc2 = ICalGLib.Timezone.get_utc_timezone()
assert utc == utc2

time = ICalGLib.Time.new()
before = time.get_hour()
ICalGLib.timezone_convert_time(time, la, chicago)
after = time.get_hour()
assert abs(after - before) == 2
ICalGLib.Time.set_timezone(time, utc)
assert ICalGLib.Time.get_timezone(time) == utc
ICalGLib.Time.set_timezone(time, la)
assert ICalGLib.Time.get_timezone(time) == la

timeclone = time.new_clone()
assert time != timeclone
time = ICalGLib.Time.convert_to_zone(time, chicago)
timeclone.convert_to_zone_inplace(chicago)
assert time.get_year() == timeclone.get_year()
assert time.get_month() == timeclone.get_month()
assert time.get_day() == timeclone.get_day()
assert time.get_hour() == timeclone.get_hour()
def main ():
	#Test as_ical_string_r
	comp = ICalGLib.Component.new_from_string (event_str1);	
	string = comp.as_ical_string_r ();

	#Test new_clone
	clone = comp.new_clone();
	string1 = clone.as_ical_string_r ();
	assert (string == string1);
	assert (comp.is_valid() == 1);
	assert (comp.isa_component() == 1);
	assert (comp.isa() == ICalGLib.ComponentKind.VEVENT_COMPONENT);

	#Test check_restrictions
	assert (comp.check_restrictions() == 0);

	#Test count_errors
	assert (comp.count_errors() == 0);

	#Test kind_is_valid
	assert (ICalGLib.Component.kind_is_valid (ICalGLib.ComponentKind.VEVENT_COMPONENT) == True);
	
	#Test kind_to_string
	kind_string = ICalGLib.Component.kind_to_string (ICalGLib.ComponentKind.VEVENT_COMPONENT);
	assert (ICalGLib.Component.string_to_kind(kind_string) == ICalGLib.ComponentKind.VEVENT_COMPONENT);


	#Test child component manipulation
	parent = ICalGLib.Component.new_from_string (event_str1);
	comp1 = ICalGLib.Component.new_from_string (event_str2);
	comp2 = ICalGLib.Component.new_from_string (event_str3);
	comp3 = ICalGLib.Component.new_from_string (event_str4);
	comp4 = ICalGLib.Component.new_from_string (event_str5);

	parent.add_component (comp1);
	parent.add_component (comp2);
	parent.add_component (comp3);
	parent.add_component (comp4);
	
	assert parent.count_components (ICalGLib.ComponentKind.VEVENT_COMPONENT) == 3;
	assert parent.count_components (ICalGLib.ComponentKind.VCALENDAR_COMPONENT) == 1;
	
	#Traverse with internal API.
	count = parent.count_components (ICalGLib.ComponentKind.VEVENT_COMPONENT);
	child_component = parent.get_first_component (ICalGLib.ComponentKind.VEVENT_COMPONENT);
	for i in range(0, count):
		prefix = "test"
		index = i+2;
		assert (child_component.get_summary() == prefix + str(index));
		if (i != count-1):
			child_component = parent.get_next_component (ICalGLib.ComponentKind.VEVENT_COMPONENT);
	
	#Traverse with external API.
	iter = parent.begin_component (ICalGLib.ComponentKind.VEVENT_COMPONENT);	
	child_component = iter.deref();	
	child_component.set_owner (parent);
	for i in range(0, count):
		prefix = "test"
		index = i+2;
		assert (child_component.get_summary() == prefix + str(index));
		if (i != count-1):
			child_component = iter.next();
			child_component.set_owner (parent);
	
	iter = parent.end_component (ICalGLib.ComponentKind.VEVENT_COMPONENT);	
	child_component = iter.prior();	
	child_component.set_owner (parent);
	for i in range(0, count):
		prefix = "test"
		index = count+1-i;
		assert (child_component.get_summary() == prefix + str(index));
		if (i != count-1):
			child_component = iter.prior();
			child_component.set_owner (parent);
			
	#Traverse and remove with external API.		
	iter = parent.begin_component (ICalGLib.ComponentKind.VEVENT_COMPONENT);	
	child_component = iter.deref();
	for i in range(0, count):
		if (i != count-1):
			iter.next();
		parent.remove_component (child_component);
		if (i != count-1):
			child_component = iter.deref();
	assert parent.count_components (ICalGLib.ComponentKind.VEVENT_COMPONENT) == 0;		

	
	
	#Test property mainpulation
	property_string = "SUMMARY:Bastille Day Party";
	string_property=ICalGLib.Property.new_from_string (property_string);
	component = ICalGLib.Component.new(ICalGLib.ComponentKind.VEVENT_COMPONENT);
	component.add_property (string_property);
	assert (component.count_properties(ICalGLib.PropertyKind.SUMMARY_PROPERTY) == 1);
	component.remove_property (string_property);
	assert (component.count_properties(ICalGLib.PropertyKind.SUMMARY_PROPERTY) == 0);
	
	component.add_property (string_property);
	property_string2 = "SUMMARY:event-uid-123";
	string_property2=ICalGLib.Property.new_from_string (property_string2);
	component.add_property (string_property2);
	component.add_property (ICalGLib.Property.new_from_string("SUMMARY:20140306T090000"));
	assert (component.count_properties(ICalGLib.PropertyKind.SUMMARY_PROPERTY) == 3);
	property1 = component.get_first_property(ICalGLib.PropertyKind.SUMMARY_PROPERTY);
	assert (property1.as_ical_string_r().split('\n', 1)[0] == "SUMMARY:Bastille Day Party\r");
	property2 = component.get_next_property(ICalGLib.PropertyKind.SUMMARY_PROPERTY);
	assert (property2.as_ical_string_r().split('\n', 1)[0] == "SUMMARY:event-uid-123\r");
	property3 = component.get_next_property(ICalGLib.PropertyKind.SUMMARY_PROPERTY);
	assert (property3.as_ical_string_r().split('\n', 1)[0] == "SUMMARY:20140306T090000\r");
	
	
	#Test getters and setters
	#Test get_dtstart and get_dtend
	comp = ICalGLib.Component.new_from_string (event_str1);
	dtstart = comp.get_dtstart ();
	start_string = ICalGLib.time_as_ical_string_r (dtstart);
	assert (start_string == "20140306T090000");
	dtend = comp.get_dtend();
	end_string = ICalGLib.time_as_ical_string_r (dtend);
	assert (end_string == "20140306T093000");
	
	#Test span
	span = comp.get_span();
	assert (span.get_start() == 1394096400);
	assert (span.get_end() == 1394098200);
	assert (span.is_busy() == 1);
	comp.set_dtstart (ICalGLib.time_from_timet(1494096400, 0));
	comp.set_dtend (ICalGLib.time_from_timet(1494098200, 0));
	span = comp.get_span();
	assert (span.get_start() == 1494096400);
	assert (span.get_end() == 1494098200);
	assert (span.is_busy() == 1);
	
	#Test set_summary/get_summary
	assert (comp.get_summary () == "test1");
	comp.set_summary ("newSummary");
	assert (comp.get_summary () == "newSummary");

	#Test set_comment/get_comment
	assert (comp.get_comment () == None);
	comp.set_comment ("newcomment");
	assert (comp.get_comment () == "newcomment");

	#Test set_uid/get_uid
	assert (comp.get_uid () == "event-uid-123");
	comp.set_uid ("newuid");
	assert (comp.get_uid () == "newuid");

	#Test set_relcalid/get_relcalid
	assert (comp.get_relcalid () == None);
	comp.set_relcalid ("newrelcalid");
	assert (comp.get_relcalid () == "newrelcalid");

	#Test set_description/get_description
	assert (comp.get_description () == None);
	comp.set_description ("newdescription");
	assert (comp.get_description () == "newdescription");

	#Test set_location/get_location
	assert (comp.get_location () == "Location");
	comp.set_location ("newlocation");
	assert (comp.get_location () == "newlocation");

	#Test set_sequence/get_sequence
	assert (comp.get_sequence () == 0);
	comp.set_sequence (5);
	assert (comp.get_sequence () == 5);
	
	#Call comp_foreach_tzid
	comp_foreach_tzid (comp, setParam, "America/Chicago");	
示例#7
0
#
# 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, see <http://www.gnu.org/licenses/>.
#
###############################################################################

from gi.repository import ICalGLib

message = "This is a stinky error!";

string_rep = ICalGLib.error_strerror (ICalGLib.ErrorEnum.NEWFAILED_ERROR);
assert (string_rep == "NEWFAILED: Failed to create a new object via a *_new() routine")
string_perror = ICalGLib.error_perror();
assert (string_perror == "NO: No error");

ICalGLib.error_set_error_state (ICalGLib.ErrorEnum.NEWFAILED_ERROR, ICalGLib.ErrorState.FATAL);
state = ICalGLib.error_get_error_state (ICalGLib.ErrorEnum.NEWFAILED_ERROR);
assert (state == ICalGLib.ErrorState.FATAL);

ICalGLib.error_stop_here();
enumeration = ICalGLib.errno_return();
string_rep = ICalGLib.error_strerror (enumeration);
assert (string_rep == "NO: No error");

state = ICalGLib.error_supress (message);
ICalGLib.error_restore (message, state);
示例#8
0
def main():
    #Test child component manipulation
    parent = ICalGLib.Component.new_from_string(event_str1);
    comp1 = ICalGLib.Component.new_from_string(event_str2);
    comp2 = ICalGLib.Component.new_from_string(event_str3);
    comp3 = ICalGLib.Component.new_from_string(event_str4);
    comp4 = ICalGLib.Component.new_from_string(event_str5);

    parent.add_component(comp1);
    parent.add_component(comp2);
    parent.add_component(comp3);
    parent.add_component(comp4);

    assert parent.as_ical_string_r() == combined_string;

    count = parent.count_components(ICalGLib.ComponentKind.VEVENT_COMPONENT);
    child_component = parent.get_first_component(ICalGLib.ComponentKind.VEVENT_COMPONENT);
    for i in range(0, count):
        if (child_component.get_summary() == "childEvent2"):
            child_component.set_summary("childEventTwo");

            start = ICalGLib.time_from_string("20141115T211923");
            end = ICalGLib.time_from_string("20141115T221923");
            child_component.set_dtstart(start);
            child_component.set_dtend(end);

            child_component.set_dtstamp(start);
            child_component.set_location("East Lansing, MI, US");

            child_component.set_relcalid("relcalid for childEventTwo");
            recur_string = "RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5";
            property = ICalGLib.Property.new_from_string(recur_string);
            child_component.add_property(property);
        if (i != count-1):
            child_component = parent.get_next_component(ICalGLib.ComponentKind.VEVENT_COMPONENT);

    modifiedCombinedString = parent.as_ical_string_r();
    newParent = ICalGLib.Component.new_from_string(modifiedCombinedString);

    count = parent.count_components(ICalGLib.ComponentKind.VEVENT_COMPONENT);
    child_component = parent.get_first_component(ICalGLib.ComponentKind.VEVENT_COMPONENT);
    for i in range(0, count):
        if (child_component.get_summary() == "childEventTwo"):
            child_component.set_summary("childEventTwo");

            dtstart = child_component.get_dtstart();
            start_string = ICalGLib.time_as_ical_string_r(dtstart);
            assert(start_string == "20141115T211923");
            dtend = child_component.get_dtend();
            end_string = ICalGLib.time_as_ical_string_r(dtend);
            assert(end_string == "20141115T221923");

            timestamp = child_component.get_dtstamp();
            assert(ICalGLib.time_as_ical_string_r(timestamp) == "20141115T211923");
            assert(child_component.get_location() == "East Lansing, MI, US");
            assert(child_component.get_relcalid() == "relcalid for childEventTwo");

            recurProperty = child_component.get_first_property(ICalGLib.PropertyKind.RRULE_PROPERTY);
            assert recurProperty.as_ical_string_r() == "RRULE:FREQ=DAILY;COUNT=5;INTERVAL=10\r\n";
        if (i != count-1):
            child_component = parent.get_next_component(ICalGLib.ComponentKind.VEVENT_COMPONENT);
示例#9
0
# The value is dependent on the libical version.
assert len(by_week_no) == 54 or len(by_week_no) == 56
by_month = recurrence.get_by_month()
# The value is dependent on the libical version.
assert len(by_month) == 13 or len(by_month) == 14
by_set_pos = recurrence.get_by_set_pos()
# The value is dependent on the libical version.
assert len(by_set_pos) == 367 or len(by_set_pos) == 386

recurrence.set_by_second(0, 1)
by_second = recurrence.get_by_second()
assert by_second[0] == 1

recurrence = ICalGLib.RecurrenceType.from_string(string)

assert (ICalGLib.recur_string_to_weekday("MO") ==
        ICalGLib.RecurrenceTypeWeekday.MONDAY_WEEKDAY)

start = 100000
result = ICalGLib.recur_expand_recurrence(string, start, 10)
secs_per_day = 24 * 60 * 60
for i in range(0, 9):
    assert (result[i] == start + i * secs_per_day)

string = "19970101T183248Z/19970102T071625Z"

period = ICalGLib.PeriodType.from_string(string)
start = period.get_start()

iter = ICalGLib.RecurIterator.new(recurrence, start)
timetype = iter.next()
示例#10
0
def main():
    #Test child component manipulation
    parent = ICalGLib.Component.new_from_string(event_str1)
    comp1 = ICalGLib.Component.new_from_string(event_str2)
    comp2 = ICalGLib.Component.new_from_string(event_str3)
    comp3 = ICalGLib.Component.new_from_string(event_str4)
    comp4 = ICalGLib.Component.new_from_string(event_str5)

    parent.add_component(comp1)
    parent.add_component(comp2)
    parent.add_component(comp3)
    parent.add_component(comp4)

    assert parent.as_ical_string_r() == combined_string

    count = parent.count_components(ICalGLib.ComponentKind.VEVENT_COMPONENT)
    child_component = parent.get_first_component(
        ICalGLib.ComponentKind.VEVENT_COMPONENT)
    for i in range(0, count):
        if (child_component.get_summary() == "childEvent2"):
            child_component.set_summary("childEventTwo")

            start = ICalGLib.time_from_string("20141115T211923")
            end = ICalGLib.time_from_string("20141115T221923")
            child_component.set_dtstart(start)
            child_component.set_dtend(end)

            child_component.set_dtstamp(start)
            child_component.set_location("East Lansing, MI, US")

            child_component.set_relcalid("relcalid for childEventTwo")
            recur_string = "RRULE:FREQ=DAILY;INTERVAL=10;COUNT=5"
            property = ICalGLib.Property.new_from_string(recur_string)
            child_component.add_property(property)
        if (i != count - 1):
            child_component = parent.get_next_component(
                ICalGLib.ComponentKind.VEVENT_COMPONENT)

    modifiedCombinedString = parent.as_ical_string_r()
    newParent = ICalGLib.Component.new_from_string(modifiedCombinedString)

    count = parent.count_components(ICalGLib.ComponentKind.VEVENT_COMPONENT)
    child_component = parent.get_first_component(
        ICalGLib.ComponentKind.VEVENT_COMPONENT)
    for i in range(0, count):
        if (child_component.get_summary() == "childEventTwo"):
            child_component.set_summary("childEventTwo")

            dtstart = child_component.get_dtstart()
            start_string = ICalGLib.time_as_ical_string_r(dtstart)
            assert (start_string == "20141115T211923")
            dtend = child_component.get_dtend()
            end_string = ICalGLib.time_as_ical_string_r(dtend)
            assert (end_string == "20141115T221923")

            timestamp = child_component.get_dtstamp()
            assert (
                ICalGLib.time_as_ical_string_r(timestamp) == "20141115T211923")
            assert (child_component.get_location() == "East Lansing, MI, US")
            assert (
                child_component.get_relcalid() == "relcalid for childEventTwo")

            recurProperty = child_component.get_first_property(
                ICalGLib.PropertyKind.RRULE_PROPERTY)
            assert recurProperty.as_ical_string_r(
            ) == "RRULE:FREQ=DAILY;COUNT=5;INTERVAL=10\r\n"
        if (i != count - 1):
            child_component = parent.get_next_component(
                ICalGLib.ComponentKind.VEVENT_COMPONENT)
示例#11
0
assert recurrence.get_by_set_pos(2) == ICalGLib.RecurrenceArrayMaxValues.RECURRENCE_ARRAY_MAX
array = recurrence.get_by_set_pos_array()
assert array[0] == 900
assert array[1] == 901
assert array[2] == ICalGLib.RecurrenceArrayMaxValues.RECURRENCE_ARRAY_MAX

recurrence.set_by_second(0, 13)
by_second = recurrence.get_by_second_array()
assert by_second[0] == 13

recurrence = ICalGLib.Recurrence.new_from_string(string)

assert(ICalGLib.Recurrence.weekday_from_string("MO") == ICalGLib.RecurrenceWeekday.MONDAY_WEEKDAY)

start = 100000
result = ICalGLib.recur_expand_recurrence(string, start, 10)
secs_per_day = 24*60*60
for i in range(0, 9):
    assert(result[i] == start + i*secs_per_day)

string = "19970101T183248Z/19970102T071625Z"

period = ICalGLib.Period.new_from_string(string)
start = period.get_start()

iter = ICalGLib.RecurIterator.new(recurrence, start)
timetype = iter.next()
day = timetype.get_day()
ref = 1
while day != 0:
    assert(day == ref)
示例#12
0
# The value is dependent on the libical version.
assert len(by_week_no) == 54 or len(by_week_no) == 56
by_month = recurrence.get_by_month()
# The value is dependent on the libical version.
assert len(by_month) == 13 or len(by_month) == 14
by_set_pos = recurrence.get_by_set_pos()
# The value is dependent on the libical version.
assert len(by_set_pos) == 367 or len(by_set_pos) == 386

recurrence.set_by_second(0, 1)
by_second = recurrence.get_by_second()
assert by_second[0] == 1

recurrence = ICalGLib.RecurrenceType.from_string(string)

assert (ICalGLib.recur_string_to_weekday("MO") ==
        ICalGLib.RecurrenceTypeWeekday.MONDAY_WEEKDAY)

start = 100000
result = ICalGLib.recur_expand_recurrence(string, start, 10)
secs_per_day = 24 * 60 * 60
for i in range(0, 9):
    assert (result[i] == start + i * secs_per_day)

string = "19970101T183248Z/19970102T071625Z"

period = ICalGLib.PeriodType.from_string(string)
start = period.get_start()

iter = ICalGLib.RecurIterator.new(recurrence, start)
timetype = iter.next()
示例#13
0
recurrence.set_by_set_pos_array(array)
assert recurrence.get_by_set_pos(0) == 900
assert recurrence.get_by_set_pos(1) == 901
assert recurrence.get_by_set_pos(2) == ICalGLib.RecurrenceArrayMaxValues.RECURRENCE_ARRAY_MAX
array = recurrence.get_by_set_pos_array()
assert array[0] == 900
assert array[1] == 901
assert array[2] == ICalGLib.RecurrenceArrayMaxValues.RECURRENCE_ARRAY_MAX

recurrence.set_by_second(0, 13)
by_second = recurrence.get_by_second_array()
assert by_second[0] == 13

recurrence = ICalGLib.Recurrence.from_string(string)

assert(ICalGLib.recur_string_to_weekday("MO") == ICalGLib.RecurrenceWeekday.MONDAY_WEEKDAY)

start = 100000
result = ICalGLib.recur_expand_recurrence(string, start, 10)
secs_per_day = 24*60*60
for i in range(0, 9):
    assert(result[i] == start + i*secs_per_day)

string = "19970101T183248Z/19970102T071625Z"

period = ICalGLib.Period.from_string(string)
start = period.get_start()

iter = ICalGLib.RecurIterator.new(recurrence, start)
timetype = iter.next()
day = timetype.get_day()