Java Code Examples for org.dmfs.rfc5545.DateTime#getTimeZone()

The following examples show how to use org.dmfs.rfc5545.DateTime#getTimeZone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateTimeFieldAdapter.java    From opentasks with Apache License 2.0 6 votes vote down vote up
@Override
public void setIn(ContentValues values, DateTime value)
{
    if (value != null)
    {
        // just store all three parts separately
        values.put(mTimestampField, value.getTimestamp());

        if (mTzField != null)
        {
            TimeZone timezone = value.getTimeZone();
            values.put(mTzField, timezone == null ? null : timezone.getID());
        }
        if (mAllDayField != null)
        {
            values.put(mAllDayField, value.isAllDay() ? 1 : 0);
        }
    }
    else
    {
        // write timestamp only, other fields may still use allday and timezone
        values.put(mTimestampField, (Long) null);
    }
}
 
Example 2
Source File: DateFormatter.java    From opentasks with Apache License 2.0 6 votes vote down vote up
/**
 * {@link Time} will eventually be replaced with {@link DateTime} in the project.
 * This conversion function is only needed in the transition period.
 */
@VisibleForTesting
Time toTime(DateTime dateTime)
{
    if (dateTime.isFloating() && !dateTime.isAllDay())
    {
        throw new IllegalArgumentException("Cannot support floating DateTime that is not all-day, can't represent it with Time");
    }

    // Time always needs a TimeZone (default ctor falls back to TimeZone.getDefault())
    String timeZoneId = dateTime.getTimeZone() == null ? "UTC" : dateTime.getTimeZone().getID();
    Time time = new Time(timeZoneId);

    time.set(dateTime.getTimestamp());

    // TODO Would using time.set(monthDay, month, year) be better?
    if (dateTime.isAllDay())
    {
        time.allDay = true;
        // This is needed as per time.allDay docs:
        time.hour = 0;
        time.minute = 0;
        time.second = 0;
    }
    return time;
}
 
Example 3
Source File: DateTimeFieldAdapter.java    From opentasks-provider with Apache License 2.0 6 votes vote down vote up
@Override
public void setIn(ContentValues values, DateTime value)
{
	if (value != null)
	{
		// just store all three parts separately
		values.put(mTimestampField, value.getTimestamp());

		if (mTzField != null)
		{
			TimeZone timezone = value.getTimeZone();
			values.put(mTzField, timezone == null ? null : timezone.getID());
		}
		if (mAllDayField != null)
		{
			values.put(mAllDayField, value.isAllDay() ? 1 : 0);
		}
	}
	else
	{
		// write timestamp only, other fields may still use allday and timezone
		values.put(mTimestampField, (Long) null);
	}
}
 
Example 4
Source File: RecurrenceRuleIterator.java    From lib-recur with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link RecurrenceRuleIterator} that gets its input from <code>ruleIterator</code>.
 *
 * @param ruleIterator
 *         The last {@link RuleIterator} in the chain of iterators.
 * @param start
 *         The first instance to iterate.
 */
RecurrenceRuleIterator(RuleIterator ruleIterator, DateTime start, CalendarMetrics calendarMetrics)
{
    mRuleIterator = ruleIterator;
    mAllDay = start.isAllDay();
    mCalendarMetrics = calendarMetrics;
    mTimeZone = start.isFloating() ? null : start.getTimeZone();
    fetchNextInstance();
}
 
Example 5
Source File: DateTimeToTimeConversionTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Contains the definition/requirement of when a {@link DateTime} and {@link Time} is considered equivalent in this project.
 */
private boolean isEquivalentDateTimeAndTime(DateTime dateTime, Time time)
{
    // android.text.Time doesn't seem to store in millis precision, there is a 1000 multiplier used there internally
    // when calculating millis, so we can only compare in this precision:
    boolean millisMatch =
            dateTime.getTimestamp() / 1000
                    ==
                    time.toMillis(false) / 1000;

    boolean yearMatch = dateTime.getYear() == time.year;
    boolean monthMatch = dateTime.getMonth() == time.month;
    boolean dayMatch = dateTime.getDayOfMonth() == time.monthDay;
    boolean hourMatch = dateTime.getHours() == time.hour;
    boolean minuteMatch = dateTime.getMinutes() == time.minute;
    boolean secondsMatch = dateTime.getSeconds() == time.second;

    boolean allDaysMatch = time.allDay == dateTime.isAllDay();

    boolean timeZoneMatch =
            (dateTime.isFloating() && dateTime.isAllDay() && time.timezone.equals("UTC"))
                    ||
                    // This is the regular case with non-floating DateTime
                    (dateTime.getTimeZone() != null && time.timezone.equals(dateTime.getTimeZone().getID()));

    return millisMatch
            && yearMatch
            && monthMatch
            && dayMatch
            && hourMatch
            && minuteMatch
            && secondsMatch
            && allDaysMatch
            && timeZoneMatch;
}