Ejemplo n.º 1
0
static void
add_event_clicked_cb (GcalYearView *year_view,
                      GtkButton    *button)
{
  GcalYearViewPrivate *priv = year_view->priv;
  icaltimetype *start_date, *end_date = NULL;

  if (priv->popover_mode)
    gtk_widget_hide (priv->popover);

  if (priv->start_selected_date->day == 0)
    {
      start_date = gcal_dup_icaltime (priv->current_date);
    }
  else
    {
      start_date = gcal_dup_icaltime (priv->start_selected_date);
      end_date = gcal_dup_icaltime (priv->end_selected_date);
      end_date->day += 1;
      *end_date = icaltime_normalize (*end_date);
      end_date->is_date = 1;
    }

  start_date->is_date = 1;
  g_signal_emit_by_name (GCAL_VIEW (year_view), "create-event-detailed", start_date, end_date);
  g_free (start_date);
  if (end_date != NULL)
    g_free (end_date);
}
/**
 * time_week_begin_with_zone:
 * @time: A time_t value.
 * @week_start_day: Day to use as the starting of the week.
 * @zone: Timezone to use.
 *
 * Returns the start of the week containing the given time_t, using the given
 * timezone. week_start_day should use the same values as mktime(),
 * i.e. 0 (Sun) to 6 (Sat).
 * NOTE: this function is only here to make the transition to the timezone
 * functions easier. New code should use icaltimetype values and
 * icaltime_adjust() to add or subtract days, hours, minutes & seconds.
 *
 * Return value: the beginning of the week.
 */
time_t
time_week_begin_with_zone (time_t time, int week_start_day, icaltimezone *zone)
{
	struct icaltimetype tt;
	int weekday, offset;

	/* Convert to an icaltimetype. */
	tt = icaltime_from_timet_with_zone (time, FALSE, zone);

	/* Get the weekday. */
	weekday = time_day_of_week (tt.day, tt.month - 1, tt.year);

	/* Calculate the current offset from the week start day. */
	offset = (weekday + 7 - week_start_day) % 7;

	/* Set it to the start of the month. */
	tt.day -= offset;
	tt.hour   = 0;
	tt.minute = 0;
	tt.second = 0;

	/* Normalize it, to fix any overflow. */
	tt = icaltime_normalize (tt);

	/* Convert back to a time_t. */
	return icaltime_as_timet_with_zone (tt, zone);
}
/**
 * time_add_month_with_zone:
 * @time: A time_t value.
 * @months: Number of months to add.
 * @zone: Timezone to use.
 *
 * Adds or subtracts a number of months to/from the given time_t value, using
 * the given timezone.
 *
 * If the day would be off the end of the month (e.g. adding 1 month to
 * 30th January, would lead to an invalid day, 30th February), it moves it
 * down to the last day in the month, e.g. 28th Feb (or 29th in a leap year.)
 *
 * NOTE: this function is only here to make the transition to the timezone
 * functions easier. New code should use icaltimetype values and
 * icaltime_adjust() to add or subtract days, hours, minutes & seconds.
 *
 * Return value: a time_t value containing @time plus the months added.
 */
time_t
time_add_month_with_zone (time_t time, int months, icaltimezone *zone)
{
	struct icaltimetype tt;
	int day, days_in_month;

	/* Convert to an icaltimetype. */
	tt = icaltime_from_timet_with_zone (time, FALSE, zone);

	/* Add on the number of months. */
	tt.month += months;

	/* Save the day, and set it to 1, so we don't overflow into the next
	   month. */
	day = tt.day;
	tt.day = 1;

	/* Normalize it, fixing any month overflow. */
	tt = icaltime_normalize (tt);

	/* If we go past the end of a month, set it to the last day. */
	days_in_month = time_days_in_month (tt.year, tt.month - 1);
	if (day > days_in_month)
		day = days_in_month;

	tt.day = day;

	/* Convert back to a time_t. */
	return icaltime_as_timet_with_zone (tt, zone);
}
void calDateTime::FromIcalTime(icaltimetype const* icalt, calITimezone * tz)
{
    icaltimetype t = *icalt;
    mIsValid = (icaltime_is_null_time(t) ||
                icaltime_is_valid_time(t) ? true : false);

    mIsDate = t.is_date ? true : false;
    if (mIsDate) {
        t.hour = 0;
        t.minute = 0;
        t.second = 0;
    }

    if (mIsValid) {
        t = icaltime_normalize(t);
    }

    mYear = static_cast<int16_t>(t.year);
    mMonth = static_cast<int16_t>(t.month - 1);
    mDay = static_cast<int16_t>(t.day);
    mHour = static_cast<int16_t>(t.hour);
    mMinute = static_cast<int16_t>(t.minute);
    mSecond = static_cast<int16_t>(t.second);

    if (tz) {
        mTimezone = tz;
    } else {
        mTimezone = cal::detectTimezone(t, nullptr);
    }
#if defined(DEBUG)
    if (mTimezone) {
        if (t.is_utc) {
            nsCOMPtr<calITimezone> ctz = cal::UTC();
            NS_ASSERTION(SameCOMIdentity(mTimezone, ctz), "UTC mismatch!");
        } else if (!t.zone) {
            nsAutoCString tzid;
            mTimezone->GetTzid(tzid);
            if (tzid.EqualsLiteral("floating")) {
                nsCOMPtr<calITimezone> ctz = cal::floating();
                NS_ASSERTION(SameCOMIdentity(mTimezone, ctz), "floating mismatch!");
            }
        } else {
            nsAutoCString tzid;
            mTimezone->GetTzid(tzid);
            NS_ASSERTION(tzid.Equals(icaltimezone_get_tzid(const_cast<icaltimezone *>(t.zone))),
                         "tzid mismatch!");
        }
    }
#endif

    mWeekday = static_cast<int16_t>(icaltime_day_of_week(t) - 1);
    mYearday = static_cast<int16_t>(icaltime_day_of_year(t));

    // mNativeTime: not moving the existing date to UTC,
    // but merely representing it a UTC-based way.
    t.is_date = 0;
    mNativeTime = IcaltimeToPRTime(&t, icaltimezone_get_utc_timezone());
}
Ejemplo n.º 5
0
static void
update_selected_dates_from_button_data (GcalYearView *year_view)
{
  GcalYearViewPrivate *priv = year_view->priv;

  if (priv->selected_data->start_day != 0)
    {
      ButtonData selected_data = *(priv->selected_data);
      order_selected_data (&selected_data);

      priv->start_selected_date->day = selected_data.start_day;
      priv->start_selected_date->month = selected_data.start_month + 1;
      priv->start_selected_date->year = priv->date->year;

      priv->end_selected_date->day = selected_data.end_day;
      priv->end_selected_date->month = selected_data.end_month + 1;
      priv->end_selected_date->year = priv->date->year;
      priv->end_selected_date->hour = 23;
      priv->end_selected_date->minute = 59;
      *(priv->end_selected_date) = icaltime_normalize (*(priv->end_selected_date));
    }
  else
    {
      *(priv->start_selected_date) = *(priv->current_date);
      priv->start_selected_date->hour = 0;
      priv->start_selected_date->minute = 0;

      *(priv->end_selected_date) = *(priv->current_date);
      priv->end_selected_date->hour = 23;
      priv->end_selected_date->minute = 59;
      *(priv->end_selected_date) = icaltime_normalize (*(priv->end_selected_date));
    }

  if (priv->end_selected_date->year != priv->start_selected_date->year)
    {
      priv->end_selected_date->day = 31;
      priv->end_selected_date->month = 12;
      priv->end_selected_date->year = priv->start_selected_date->year;
    }
}
Ejemplo n.º 6
0
struct icaltimetype icaltime_add(struct icaltimetype t, struct icaldurationtype d)
{
    if (!d.is_neg) {
        t.second += d.seconds;
        t.minute += d.minutes;
        t.hour += d.hours;
        t.day += d.days;
        t.day += d.weeks * 7;
    } else {
        t.second -= d.seconds;
        t.minute -= d.minutes;
        t.hour -= d.hours;
        t.day -= d.days;
        t.day -= d.weeks * 7;
    }

    t = icaltime_normalize(t);

    return t;
}
/**
 * time_day_end_with_zone:
 * @time: A time_t value.
 * @zone: Timezone to use.
 *
 * Returns the end of the day containing the given time_t, using the given
 * timezone. (The end of the day is the start of the next day.)
 * NOTE: this function is only here to make the transition to the timezone
 * functions easier. New code should use icaltimetype values and
 * icaltime_adjust() to add or subtract days, hours, minutes & seconds.
 *
 * Return value: the end of the day.
 */
time_t
time_day_end_with_zone (time_t time, icaltimezone *zone)
{
	struct icaltimetype tt;

	/* Convert to an icaltimetype. */
	tt = icaltime_from_timet_with_zone (time, FALSE, zone);

	/* Set it to the start of the next day. */
	tt.day++;
	tt.hour   = 0;
	tt.minute = 0;
	tt.second = 0;

	/* Normalize it, to fix any overflow. */
	tt = icaltime_normalize (tt);

	/* Convert back to a time_t. */
	return icaltime_as_timet_with_zone (tt, zone);
}
Ejemplo n.º 8
0
void calDateTime::FromIcalTime(icaltimetype const* icalt, calITimezone * tz)
{
    icaltimetype t = *icalt;
    mIsValid = (icaltime_is_null_time(t) ||
                icaltime_is_valid_time(t) ? PR_TRUE : PR_FALSE);

    mIsDate = t.is_date ? PR_TRUE : PR_FALSE;
    if (mIsDate) {
        t.hour = 0;
        t.minute = 0;
        t.second = 0;
    }

    if (mIsValid) {
        t = icaltime_normalize(t);
    }

    mYear = static_cast<PRInt16>(t.year);
    mMonth = static_cast<PRInt16>(t.month - 1);
    mDay = static_cast<PRInt16>(t.day);
    mHour = static_cast<PRInt16>(t.hour);
    mMinute = static_cast<PRInt16>(t.minute);
    mSecond = static_cast<PRInt16>(t.second);

    if (tz) {
        mTimezone = tz;
    } else {
        mTimezone = cal::detectTimezone(t, nsnull);
    }
#if defined(DEBUG)
    if (mTimezone) {
        if (t.is_utc) {
#if 1
            nsCOMPtr<calITimezone> utc_tz;
            nsCOMPtr<calITimezoneService> tzSvc =
              do_GetService(CAL_TIMEZONESERVICE_CONTRACTID);
            tzSvc->GetUTC(getter_AddRefs(utc_tz));
            NS_ASSERTION(SameCOMIdentity(mTimezone, utc_tz), "UTC mismatch!");
#else
            NS_ASSERTION(SameCOMIdentity(mTimezone, cal::UTC()), "UTC mismatch!");
#endif
        } else if (!t.zone) {
#if 1
            nsCOMPtr<calITimezone> float_tz;
            nsCOMPtr<calITimezoneService> tzSvc =
              do_GetService(CAL_TIMEZONESERVICE_CONTRACTID);
            tzSvc->GetFloating(getter_AddRefs(float_tz));
            NS_ASSERTION(SameCOMIdentity(mTimezone, float_tz), "floating mismatch!");
#else
            NS_ASSERTION(SameCOMIdentity(mTimezone, cal::floating()), "floating mismatch!");
#endif
        } else {
            nsCAutoString tzid;
            mTimezone->GetTzid(tzid);
            NS_ASSERTION(tzid.Equals(icaltimezone_get_tzid(const_cast<icaltimezone *>(t.zone))),
                         "tzid mismatch!");
        }
    }
#endif

    mWeekday = static_cast<PRInt16>(icaltime_day_of_week(t) - 1);
    mYearday = static_cast<PRInt16>(icaltime_day_of_year(t));

    // mNativeTime: not moving the existing date to UTC,
    // but merely representing it a UTC-based way.
    t.is_date = 0;
    mNativeTime = IcaltimeToPRTime(&t, icaltimezone_get_utc_timezone());
}