Example #1
0
/*
Function:
GetJapaneseEraInfo

Gets the starting Gregorian date of the specified Japanese Era.
*/
extern "C" int32_t GetJapaneseEraStartDate(
	int32_t era,
	int32_t* startYear,
	int32_t* startMonth,
	int32_t* startDay)
{
	*startYear = -1;
	*startMonth = -1;
	*startDay = -1;

	UErrorCode err = U_ZERO_ERROR;
	Locale japaneseLocale(JAPANESE_LOCALE_AND_CALENDAR);
	LocalPointer<Calendar> calendar(Calendar::createInstance(japaneseLocale, err));
	if (U_FAILURE(err))
		return false;

	calendar->set(UCAL_ERA, era);
	calendar->set(UCAL_YEAR, 1);

	// UCAL_EXTENDED_YEAR is the gregorian year for the JapaneseCalendar
	*startYear = calendar->get(UCAL_EXTENDED_YEAR, err);
	if (U_FAILURE(err))
		return false;

	// set the date to Jan 1
	calendar->set(UCAL_MONTH, 0);
	calendar->set(UCAL_DATE, 1);

	int32_t currentEra;
	for (int i = 0; i <= 12; i++)
	{
		currentEra = calendar->get(UCAL_ERA, err);
		if (U_FAILURE(err))
			return false;

		if (currentEra == era)
		{
			for (int i = 0; i < 31; i++)
			{
				// subtract 1 day at a time until we get out of the specified Era
				calendar->add(Calendar::DATE, -1, err);
				if (U_FAILURE(err))
					return false;

				currentEra = calendar->get(UCAL_ERA, err);
				if (U_FAILURE(err))
					return false;

				if (currentEra != era)
				{
					// add back 1 day to get back into the specified Era
					calendar->add(UCAL_DATE, 1, err);
					if (U_FAILURE(err))
						return false;

					*startMonth = calendar->get(UCAL_MONTH, err) + 1;  // ICU Calendar months are 0-based, but .NET is 1-based
					if (U_FAILURE(err))
						return false;

					*startDay = calendar->get(UCAL_DATE, err);
					if (U_FAILURE(err))
						return false;

					return true;
				}
			}
		}

		// add 1 month at a time until we get into the specified Era
		calendar->add(UCAL_MONTH, 1, err);
		if (U_FAILURE(err))
			return false;
	}

	return false;
}
Example #2
0
/******************************************************************************
*  Undo the item, i.e. restore an alarm which was deleted.
*  Create a redo item to delete the alarm again.
*  Reply = redo item.
*/
UndoItem *UndoDelete::restore()
{
    kdDebug(5950) << "UndoDelete::restore(" << mEvent->id() << ")\n";
    // Restore the original event
    switch(calendar())
    {
        case KAEvent::ACTIVE:
            if(mEvent->toBeArchived())
            {
                // It was archived when it was deleted
                mEvent->setUid(KAEvent::EXPIRED);
                switch(KAlarm::reactivateEvent(*mEvent, 0, true))
                {
                    case KAlarm::UPDATE_KORG_ERR:
                        mRestoreWarning = WARN_KORG_ADD;
                        ++mRestoreWarningCount;
                        break;
                    case KAlarm::UPDATE_ERROR:
                    case KAlarm::UPDATE_FAILED:
                    case KAlarm::SAVE_FAILED:
                        mRestoreError = ERR_EXPIRED;
                        return 0;
                    case KAlarm::UPDATE_OK:
                        break;
                }
            }
            else
            {
                switch(KAlarm::addEvent(*mEvent, 0, 0, true))
                {
                    case KAlarm::UPDATE_KORG_ERR:
                        mRestoreWarning = WARN_KORG_ADD;
                        ++mRestoreWarningCount;
                        break;
                    case KAlarm::UPDATE_ERROR:
                    case KAlarm::UPDATE_FAILED:
                    case KAlarm::SAVE_FAILED:
                        mRestoreError = ERR_CREATE;
                        return 0;
                    case KAlarm::UPDATE_OK:
                        break;
                }
            }
            break;
        case KAEvent::TEMPLATE:
            if(KAlarm::addTemplate(*mEvent, 0) != KAlarm::UPDATE_OK)
            {
                mRestoreError = ERR_CREATE;
                return 0;
            }
            break;
        case KAEvent::EXPIRED:
            if(!KAlarm::addExpiredEvent(*mEvent))
            {
                mRestoreError = ERR_CREATE;
                return 0;
            }
            break;
        default:
            mRestoreError = ERR_PROG;
            return 0;
    }

    // Create a redo item to delete the alarm again
    return createRedo(*mEvent);
}
Example #3
0
calendar calendar::operator +(int rhs) const
{
    return calendar(*this) += rhs;
}
Example #4
0
/******************************************************************************
*  Return the action description of the Undo item for displaying.
*/
QString UndoAdd::actionText() const
{
    return addDeleteActionText(calendar(), (type() == Undo::UNDO));
}
Example #5
0
calendar calendar::operator -(const calendar &rhs) const
{
    return calendar(*this) -= rhs;
}