Index: src/libical/Makefile.am =================================================================== RCS file: /home/cvs/projects/libical/src/libical/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.5 diff -u -r1.1.1.1 -r1.5 --- src/libical/Makefile.am 12 May 2004 08:44:28 -0000 1.1.1.1 +++ src/libical/Makefile.am 1 Jul 2004 11:34:23 -0000 1.5 @@ -28,7 +28,7 @@ if WITH_CXX cxx_lib=libical_cxx.la -cxx_headers=vcomponent.h icalparameter_cxx.h icalproperty_cxx.h icalvalue_cxx.h icptrholder.h +cxx_headers=vcomponent.h icalparameter_cxx.h icalproperty_cxx.h icalvalue_cxx.h icalduration_cxx.h icaltime_cxx.h icaltimezone_cxx.h icptrholder.h else cxx_lib= cxx_headers= @@ -40,7 +40,7 @@ libical_static_la_SOURCES = $(libical_la_SOURCES) libical_static_la_LDFLAGS = --all-static -CPPFLAGS = -DPACKAGE_DATA_DIR=\""$(datadir)/$(PACKAGE)"\" +AM_CPPFLAGS = -DPACKAGE_DATA_DIR=\""$(datadir)/$(PACKAGE)"\" # CFLAGS = -g @@ -116,6 +116,12 @@ icalparameter_cxx.cpp \ icalvalue_cxx.h \ icalvalue_cxx.cpp \ + icalduration_cxx.h \ + icalduration_cxx.cpp \ + icaltime_cxx.h \ + icaltime_cxx.cpp \ + icaltimezone_cxx.h \ + icaltimezone_cxx.cpp \ icptrholder.h endif Index: src/libical/icalduration_cxx.cpp =================================================================== RCS file: src/libical/icalduration_cxx.cpp diff -N src/libical/icalduration_cxx.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libical/icalduration_cxx.cpp 1 Jul 2004 11:34:23 -0000 1.1 @@ -0,0 +1,61 @@ + +#include "icalduration_cxx.h" +extern "C" { +#include +}; + +/** Constructs ICalDuration from an ISO format string */ +ICalDuration::ICalDuration(const char* d) throw(icalerrorenum) { + imp = icaldurationtype_from_string(d); +} +/** Constructs ICalDuration according time_t (UNIX epoch). */ +ICalDuration::ICalDuration(const int d) throw(icalerrorenum) { + imp = icaldurationtype_from_int(d); +} + +/** Copy constructor */ +ICalDuration::ICalDuration(const ICalDuration& t) throw(icalerrorenum) { + memcpy((void*)&imp, (void*)&t, sizeof(icaldurationtype)); +} + +ICalDuration& +ICalDuration::operator=(const ICalDuration& t) throw(icalerrorenum) { + memcpy((void*)&imp, (void*)&t, sizeof(icaldurationtype)); + return *this; +} + +/** Destructor */ +ICalDuration::~ICalDuration() throw(icalerrorenum) { +} + +/** Get ICalDuration as seconds past the UNIX epoch */ +int +ICalDuration::as_int() { + return icaldurationtype_as_int(imp); +} + +/** Get ICalDuration as string represention of the time, in RFC2445 format. + * The string is owned by libical */ +const char* +ICalDuration::as_ical_string() { + return icaldurationtype_as_ical_string(imp); +} + +/** Get ICalDuration as icaltimetype, seconds past the UNIX epoch */ +icaldurationtype +ICalDuration::as_icaldurationtype() { + return imp; +} + +/** Test if the ICalDuration is null. */ +int +ICalDuration::is_null() { + return icaldurationtype_is_null_duration(imp); +} + +/** Test if the ICalDuration is bad. */ +int +ICalDuration::is_bad() { + return icaldurationtype_is_bad_duration(imp); +} + Index: src/libical/icalduration_cxx.h =================================================================== RCS file: src/libical/icalduration_cxx.h diff -N src/libical/icalduration_cxx.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libical/icalduration_cxx.h 1 Jul 2004 11:34:23 -0000 1.1 @@ -0,0 +1,41 @@ +#ifndef ICALDURATION_CXX_H +#define ICALDURATION_CXX_H + +extern "C" { +#include +#include "ical.h" +#include "icaltime.h" +}; + +class ICalDuration { +public: + /** Constructs ICalDuration from an ISO format string */ + ICalDuration(const char* d) throw(icalerrorenum); + /** Constructs ICalDuration from an integer */ + ICalDuration(const int d) throw(icalerrorenum); + + /** Copy constructor */ + ICalDuration(const ICalDuration& t) throw(icalerrorenum); + ICalDuration& operator=(const ICalDuration& t) throw(icalerrorenum); + + /** Destructor */ + ~ICalDuration() throw(icalerrorenum); + + /** Get the duration in seconds */ + int as_int(); + /** Get date/time as string represention of the time, in RFC2445 format. + * The string is owned by libical */ + const char* as_ical_string(); + + /** Get the duration as icaldurationtype */ + icaldurationtype as_icaldurationtype(); + + /** Check if the duration is a null duration */ + int is_null(); + /** Check if the duration is a bad duration */ + int is_bad(); + +private: + icaldurationtype imp; +}; +#endif /* !ICALDURATION_CXX_H */ Index: src/libical/icaltime_cxx.cpp =================================================================== RCS file: src/libical/icaltime_cxx.cpp diff -N src/libical/icaltime_cxx.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libical/icaltime_cxx.cpp 1 Jul 2004 11:32:02 -0000 1.3 @@ -0,0 +1,150 @@ +#include "icaltime_cxx.h" +extern "C" { +#include +}; + +/** Constructor */ +ICalTime::ICalTime() throw(icalerrorenum) { + imp = icaltime_null_time(); +} +/** Constructs ICalTime from an ISO format string */ +ICalTime::ICalTime(const char* t) throw(icalerrorenum) { + imp = icaltime_from_string(t); +} +/** Constructs ICalTime from an ISO format string */ +ICalTime::ICalTime(const char* t, + const icaltimezone *zone) throw(icalerrorenum) { + imp = icaltime_from_string(t); +} +/** Constructs ICalTime according time_t (UNIX epoch). */ +ICalTime::ICalTime(const time_t t, const int is_date) throw(icalerrorenum) { + imp = icaltime_from_timet(t, is_date); +} + +/** Constructs ICalTime according time_t (UNIX epoch), using timezone. */ +ICalTime::ICalTime(const time_t t, const int is_date, + const icaltimezone* zone) throw(icalerrorenum) { + imp = icaltime_from_timet_with_zone(t, is_date, zone); +} + +/** Copy constructor */ +ICalTime::ICalTime(const ICalTime& t) throw(icalerrorenum) { + memcpy((void*)&imp, (void*)&t, sizeof(icaltimetype)); +} + +ICalTime& +ICalTime::operator=(const ICalTime& t) throw(icalerrorenum) { + memcpy((void*)&imp, (void*)&t, sizeof(icaltimetype)); + return *this; +} + +/** Destructor */ +ICalTime::~ICalTime() throw(icalerrorenum) { +} + +/** Sets date/time to current in UTC. */ +void +ICalTime::current() { + imp = icaltime_from_timet_with_zone(time(NULL), 0, icaltimezone_get_utc_timezone()); +} + +/** Sets date/time to current. */ +void +ICalTime::current(char* tz) { + /* FIMXE, ignores given timezone, uses local. */ + imp = icaltime_from_timet(time(NULL), 0); +} + +/** Returns the current day as an icaltimetype, with is_date set. */ +void +ICalTime::today() { + imp = icaltime_today(); +} + +/** Set time with epoch. Constructor should be used, but needed for JNI-API. */ +void +ICalTime::set_epoch(time_t e) { + imp = icaltime_from_timet_with_zone(e, 0, icaltimezone_get_utc_timezone()); +} + +/** Sets date from day of year and year. */ +void +ICalTime::from_day_of_year(const int doy, const int year) { + imp = icaltime_from_day_of_year(doy, year); +} + +/** Get the date/time as time_t, seconds past the UNIX epoch */ +time_t +ICalTime::as_timet() { + return icaltime_as_timet(imp); +} + +/** Adding a duration */ +void +ICalTime::add(struct icaldurationtype duration) { + imp = icaltime_add(imp, duration); +} + +/** Get the date/time as icaltimetype, seconds past the UNIX epoch */ +icaltimetype +ICalTime::as_icaltimetype() { + return imp; +} + + +/** Get date/time as string represention of the time, in RFC2445 format. + * The string is owned by libical */ +const char* +ICalTime::as_ical_string() { + return icaltime_as_ical_string(imp); +} + +/** Set/change the timezone */ +void +ICalTime::set_timezone(const icaltimezone *zone) { + icaltime_set_timezone(&imp, zone); +} + +/** Get day of the year. */ +int +ICalTime::day_of_year() { + return icaltime_day_of_year(imp); +} + +/** Test if the time is null. */ +int +ICalTime::is_null_time() { + return icaltime_is_null_time(imp); +} + +/** Test if the time is set and valid. */ +int +ICalTime::is_valid_time() { + return icaltime_is_valid_time(imp); +} + +/** @brief Returns true if time is of DATE type, false if DATE-TIME */ +/** Test if the date is set. (if date and time is set returns false) */ +int +ICalTime::is_date() { + return icaltime_is_date(imp); +} + +/** Test if the time is in the UTC timezone */ +int +ICalTime::is_utc() { + return icaltime_is_utc(imp); +} + +/** Adds or subtracts date/time with number of days, hours, minutes and seconds. */ +void +ICalTime::adjust(const int days, const int hours, const int minutes, const int seconds) { + icaltime_adjust(&imp, days, hours, minutes, seconds); +} + +/** Normalize the date/time, so that all fields are within the normal range. */ +void +ICalTime::normalize() { + icaltime_normalize(imp); +} + Index: src/libical/icaltime_cxx.h =================================================================== RCS file: src/libical/icaltime_cxx.h diff -N src/libical/icaltime_cxx.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libical/icaltime_cxx.h 1 Jul 2004 11:32:02 -0000 1.2 @@ -0,0 +1,93 @@ +#ifndef ICALTIME_CXX_H +#define ICALTIME_CXX_H + +extern "C" { +#include +#include "ical.h" +#include "icaltime.h" +#include "icaltimezone.h" +}; + +#include "icaltimezone_cxx.h" + +class ICalTime { +public: + /** 'NULL' Constructor */ + ICalTime() throw(icalerrorenum); + /** Constructs from an ISO format string in UTC */ + ICalTime(const char* t) throw(icalerrorenum); + /** Constructs from an ISO format string */ + ICalTime(const char* t, const icaltimezone* zone) throw(icalerrorenum); + /** Constructs according time_t (UNIX epoch) in UTC. */ + ICalTime(const time_t t, const int is_date) throw(icalerrorenum); + /** Constructs according time_t (UNIX epoch), using timezone. */ + ICalTime(const time_t t, const int is_date, + const icaltimezone* zone) throw(icalerrorenum); + + /** Copy constructor */ + ICalTime(const ICalTime& t) throw(icalerrorenum); + ICalTime& operator=(const ICalTime& t) throw(icalerrorenum); + + /** Destructor */ + ~ICalTime() throw(icalerrorenum); + + /** Sets date/time to current in UTC. */ + void current(); + + /** Sets date/time to current. */ + void current(char *tz); + + /** Returns the current day as an icaltimetype, with is_date set. */ + void today(); + + /** Set time with epoch. Constructor should be used, but needed for JNI-API. */ + void set_epoch(time_t e); + + /** Sets date from day of year and year. */ + void from_day_of_year(const int doy, const int year); + + /** Get the date/time as time_t, seconds past the UNIX epoch */ + time_t as_timet(); + + /** Get the date/time as icaltimetype */ + icaltimetype as_icaltimetype(); + + /** Get date/time as string represention of the time, in RFC2445 format. + * The string is owned by libical */ + const char* as_ical_string(); + + /** Set/change the timezone */ + void set_timezone(const icaltimezone* zone); + + /** Adding a duration */ + void add(struct icaldurationtype duration); + + /** Get day of the year. */ + int day_of_year(); + + /** Test if the time is null. */ + int is_null_time(); + + /** Test if the time is set and valid. */ + int is_valid_time(); + + /** @brief Returns true if time is of DATE type, false if DATE-TIME */ + /** Test if the date is set. (if date and time is set returns false) */ + int is_date(); + + /** Test if the time is in the UTC timezone */ + int is_utc(); + + /** Adds or subtracts date/time with number of days, hours, minutes and seconds. */ + void adjust(const int days, const int hours, const int minutes, const int seconds); + + /** Normalize the date/time, so that all fields are within the normal range. */ + void normalize(); + +private: + icaltimetype imp; +}; + +#endif /* !ICALTIME_CXX_H */ + + Index: src/libical/icaltimezone.c =================================================================== RCS file: /home/cvs/projects/libical/src/libical/icaltimezone.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -r1.1.1.1 -r1.2 --- src/libical/icaltimezone.c 12 May 2004 08:44:29 -0000 1.1.1.1 +++ src/libical/icaltimezone.c 14 May 2004 16:17:01 -0000 1.2 @@ -38,6 +38,7 @@ #include "icalerror.h" #include "icalparser.h" #include "icaltimezone.h" +#include "icaltimezoneimpl.h" #ifdef WIN32 #define snprintf _snprintf @@ -62,78 +63,6 @@ /** This is the maximum year we will expand to. time_t values only go up to somewhere around 2037. */ #define ICALTIMEZONE_MAX_YEAR 2035 - -struct _icaltimezone { - char *tzid; - /**< The unique ID of this timezone, - e.g. "/softwarestudio.org/Olson_20010601_1/Africa/Banjul". - This should only be used to identify a VTIMEZONE. It is not - meant to be displayed to the user in any form. */ - - char *location; - /**< The location for the timezone, e.g. "Africa/Accra" for the - Olson database. We look for this in the "LOCATION" or - "X-LIC-LOCATION" properties of the VTIMEZONE component. It - isn't a standard property yet. This will be NULL if no location - is found in the VTIMEZONE. */ - - char *tznames; - /**< This will be set to a combination of the TZNAME properties - from the last STANDARD and DAYLIGHT components in the - VTIMEZONE, e.g. "EST/EDT". If they both use the same TZNAME, - or only one type of component is found, then only one TZNAME - will appear, e.g. "AZOT". If no TZNAME is found this will be - NULL. */ - - double latitude; - double longitude; - /**< The coordinates of the city, in degrees. */ - - icalcomponent *component; - /**< The toplevel VTIMEZONE component loaded from the .ics file for this - timezone. If we need to regenerate the changes data we need this. */ - - icaltimezone *builtin_timezone; - /**< If this is not NULL it points to the builtin icaltimezone - that the above TZID refers to. This icaltimezone should be used - instead when accessing the timezone changes data, so that the - expanded timezone changes data is shared between calendar - components. */ - - int end_year; - /**< This is the last year for which we have expanded the data to. - If we need to calculate a date past this we need to expand the - timezone component data from scratch. */ - - icalarray *changes; - /**< A dynamically-allocated array of time zone changes, sorted by the - time of the change in local time. So we can do fast binary-searches - to convert from local time to UTC. */ -}; - -typedef struct _icaltimezonechange icaltimezonechange; - -struct _icaltimezonechange { - int utc_offset; - /**< The offset to add to UTC to get local time, in seconds. */ - - int prev_utc_offset; - /**< The offset to add to UTC, before this change, in seconds. */ - - int year; /**< Actual year, e.g. 2001. */ - int month; /**< 1 (Jan) to 12 (Dec). */ - int day; - int hour; - int minute; - int second; - /**< The time that the change came into effect, in UTC. - Note that the prev_utc_offset applies to this local time, - since we haven't changed to the new offset yet. */ - - int is_daylight; - /**< Whether this is STANDARD or DAYLIGHT time. */ -}; - /** An array of icaltimezones for the builtin timezones. */ static icalarray *builtin_timezones = NULL; Index: src/libical/icaltimezone_cxx.cpp =================================================================== RCS file: src/libical/icaltimezone_cxx.cpp diff -N src/libical/icaltimezone_cxx.cpp --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libical/icaltimezone_cxx.cpp 14 Jun 2004 07:42:56 -0000 1.2 @@ -0,0 +1,75 @@ + +#ifndef ICALTIMEZONE_CXX_H +#include "icaltimezone_cxx.h" +#endif /* ICALTIMEZONE_CXX_H */ + +extern "C" { +#include +}; + +/** ICalTimeZone constructor. */ +ICalTimeZone::ICalTimeZone() throw(icalerrorenum) : imp(icaltimezone_new()) {} + +ICalTimeZone::ICalTimeZone(const ICalTimeZone& tz) throw(icalerrorenum) { + if (!imp) throw icalerrno; + memcpy((void*)imp, (void*)&tz, sizeof(struct _icaltimezone)); +} + +ICalTimeZone& +ICalTimeZone::operator=(const ICalTimeZone& tz) throw(icalerrorenum) { + if ((this != &tz) && (imp)) { + icaltimezone_free(imp, 1); + imp = icaltimezone_new(); + if (!imp) { + throw icalerrno; + } else { + memcpy((void*)imp, (void*)&tz, sizeof(icaltimezone)); + } + } + return *this; +} + +/** ICalTimeZone destructor. */ +ICalTimeZone::~ICalTimeZone() { + icaltimezone_free(imp, 1); +} + +/** Returns the TZID of the timezone. */ +char* +ICalTimeZone::get_tzid() { + return icaltimezone_get_tzid(imp); +} + +/** Returns the city name of the timezone. */ +char* +ICalTimeZone::get_location() { + return icaltimezone_get_location(imp); +} + +/** Returns the latitude of a builtin timezone. */ +double +ICalTimeZone::get_latitude() { + return icaltimezone_get_latitude(imp); +} + +/** Returns the longitude of a builtin timezone. */ +double +ICalTimeZone::get_longitude() { + return icaltimezone_get_longitude(imp); +} + +/** Returns the VTIMEZONE component of a timezone. */ +icalcomponent* +ICalTimeZone::get_component() { + return icaltimezone_get_component(imp); +} + +/** Returns the TZNAME properties used in the latest STANDARD and DAYLIGHT + * components. If they are the same it will return just one, e.g. "LMT". + * If they are different it will format them like "EST/EDT". Note that this + * may also return NULL. + */ +char* +ICalTimeZone::get_tznames() { + return icaltimezone_get_tznames(imp); +} Index: src/libical/icaltimezone_cxx.h =================================================================== RCS file: src/libical/icaltimezone_cxx.h diff -N src/libical/icaltimezone_cxx.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libical/icaltimezone_cxx.h 14 May 2004 16:26:37 -0000 1.1 @@ -0,0 +1,48 @@ +#ifndef ICALTIMEZONE_CXX_H +#define ICALTIMEZONE_CXX_H + +extern "C" { +#include "ical.h" +#include "icalcomponent.h" +#include "icaltimezone.h" +#include "icaltimezoneimpl.h" +}; + +class ICalTimeZone { + +public: + /** ICalTimeZone constructor. */ + ICalTimeZone() throw(icalerrorenum); + ICalTimeZone(const ICalTimeZone& tz) throw (icalerrorenum); + ICalTimeZone& operator=(const ICalTimeZone& tz) throw(icalerrorenum); + + /** ICalTimeZone destructor. */ + ~ICalTimeZone(); + + /** Returns the TZID of the timezone. */ + char* get_tzid(); + + /** Returns the city name of the timezone. */ + char* get_location(); + + /** Returns the latitude of a builtin timezone. */ + double get_latitude(); + + /** Returns the longitude of a builtin timezone. */ + double get_longitude(); + + /** Returns the VTIMEZONE component of a timezone. */ + icalcomponent* get_component(); + + /** Returns the TZNAME properties used in the latest STANDARD and DAYLIGHT + * components. If they are the same it will return just one, e.g. "LMT". + * If they are different it will format them like "EST/EDT". Note that this + * may also return NULL. + */ + char* get_tznames(); + +private: + icaltimezone* imp; +}; + +#endif /* ICALTIMEZONE_CXX_H */ Index: src/libical/icaltimezoneimpl.h =================================================================== RCS file: src/libical/icaltimezoneimpl.h diff -N src/libical/icaltimezoneimpl.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/libical/icaltimezoneimpl.h 14 May 2004 16:17:01 -0000 1.1 @@ -0,0 +1,101 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/*====================================================================== + FILE: icaltimezoneimpl.h + CREATOR: Harrie Hazewinkel May 14 2004 + This file contains code that was originally in icaltimezone.c + + $Id: icaltimezoneimpl.h,v 1.1 2004/05/14 16:17:01 harrie Exp $ + $Locker: $ + + (C) COPYRIGHT 2001, Damon Chaplin + + This program is free software; you can redistribute it and/or modify + it under the terms of either: + + The LGPL as published by the Free Software Foundation, version + 2.1, available at: http://www.fsf.org/copyleft/lesser.html + + Or: + + The Mozilla Public License Version 1.0. You may obtain a copy of + the License at http://www.mozilla.org/MPL/ + + +======================================================================*/ +#ifndef ICALTIMEZONEIMPL_H +#define ICALTIMEZONEIMPL_H + + +struct _icaltimezone { + char *tzid; + /**< The unique ID of this timezone, + e.g. "/softwarestudio.org/Olson_20010601_1/Africa/Banjul". + This should only be used to identify a VTIMEZONE. It is not + meant to be displayed to the user in any form. */ + + char *location; + /**< The location for the timezone, e.g. "Africa/Accra" for the + Olson database. We look for this in the "LOCATION" or + "X-LIC-LOCATION" properties of the VTIMEZONE component. It + isn't a standard property yet. This will be NULL if no location + is found in the VTIMEZONE. */ + + char *tznames; + /**< This will be set to a combination of the TZNAME properties + from the last STANDARD and DAYLIGHT components in the + VTIMEZONE, e.g. "EST/EDT". If they both use the same TZNAME, + or only one type of component is found, then only one TZNAME + will appear, e.g. "AZOT". If no TZNAME is found this will be + NULL. */ + + double latitude; + double longitude; + /**< The coordinates of the city, in degrees. */ + + icalcomponent *component; + /**< The toplevel VTIMEZONE component loaded from the .ics file for this + timezone. If we need to regenerate the changes data we need this. */ + + icaltimezone *builtin_timezone; + /**< If this is not NULL it points to the builtin icaltimezone + that the above TZID refers to. This icaltimezone should be used + instead when accessing the timezone changes data, so that the + expanded timezone changes data is shared between calendar + components. */ + + int end_year; + /**< This is the last year for which we have expanded the data to. + If we need to calculate a date past this we need to expand the + timezone component data from scratch. */ + + icalarray *changes; + /**< A dynamically-allocated array of time zone changes, sorted by the + time of the change in local time. So we can do fast binary-searches + to convert from local time to UTC. */ +}; + +typedef struct _icaltimezonechange icaltimezonechange; + +struct _icaltimezonechange { + int utc_offset; + /**< The offset to add to UTC to get local time, in seconds. */ + + int prev_utc_offset; + /**< The offset to add to UTC, before this change, in seconds. */ + + int year; /**< Actual year, e.g. 2001. */ + int month; /**< 1 (Jan) to 12 (Dec). */ + int day; + int hour; + int minute; + int second; + /**< The time that the change came into effect, in UTC. + Note that the prev_utc_offset applies to this local time, + since we haven't changed to the new offset yet. */ + + int is_daylight; + /**< Whether this is STANDARD or DAYLIGHT time. */ +}; + + +#endif /* ICALTIMEZONEIMPL_H */