Java Code Examples for android.text.format.Time#TIMEZONE_UTC

The following examples show how to use android.text.format.Time#TIMEZONE_UTC . 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: TimeFieldAdapter.java    From opentasks with Apache License 2.0 6 votes vote down vote up
@Override
public Time getDefault(ContentSet values)
{
    // create a new Time for the given time zone, falling back to the default time zone if none is given
    String timezone = mTzField == null ? Time.TIMEZONE_UTC : values.getAsString(mTzField);
    Time value = new Time(timezone == null ? TimeZone.getDefault().getID() : timezone);

    value.setToNow();

    Integer allDayInt = mAllDayField == null ? null : values.getAsInteger(mAllDayField);
    if ((allDayInt != null && allDayInt != 0) || (mAllDayField == null && mAllDayDefault))
    {
        // make it an allday value
        value.set(value.monthDay, value.month, value.year);
        value.timezone = Time.TIMEZONE_UTC; // all-day values are saved in UTC
    }

    return value;
}
 
Example 2
Source File: TimeFieldEditor.java    From opentasks with Apache License 2.0 6 votes vote down vote up
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
    if (ALLDAY.get(mValues))
    {
        mDateTime.timezone = Time.TIMEZONE_UTC;
        mDateTime.set(dayOfMonth, monthOfYear, year);
    }
    else
    {
        mDateTime.year = year;
        mDateTime.month = monthOfYear;
        mDateTime.monthDay = dayOfMonth;
        mDateTime.normalize(true);
    }
    mUpdated = true;
    mAdapter.validateAndSet(mValues, mDateTime);
}
 
Example 3
Source File: HttpDateTime.java    From QtAndroidTools with MIT License 5 votes vote down vote up
public static long parse(String timeString)
        throws IllegalArgumentException {

    int date = 1;
    int month = Calendar.JANUARY;
    int year = 1970;
    TimeOfDay timeOfDay;

    Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString);
    if (rfcMatcher.find()) {
        date = getDate(rfcMatcher.group(1));
        month = getMonth(rfcMatcher.group(2));
        year = getYear(rfcMatcher.group(3));
        timeOfDay = getTime(rfcMatcher.group(4));
    } else {
        Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString);
        if (ansicMatcher.find()) {
            month = getMonth(ansicMatcher.group(1));
            date = getDate(ansicMatcher.group(2));
            timeOfDay = getTime(ansicMatcher.group(3));
            year = getYear(ansicMatcher.group(4));
        } else {
            throw new IllegalArgumentException();
        }
    }

    // FIXME: Y2038 BUG!
    if (year >= 2038) {
        year = 2038;
        month = Calendar.JANUARY;
        date = 1;
    }

    Time time = new Time(Time.TIMEZONE_UTC);
    time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date,
            month, year);
    return time.toMillis(false /* use isDst */);
}
 
Example 4
Source File: HttpDateTime.java    From play-apk-expansion with Apache License 2.0 5 votes vote down vote up
public static long parse(String timeString)
        throws IllegalArgumentException {

    int date = 1;
    int month = Calendar.JANUARY;
    int year = 1970;
    TimeOfDay timeOfDay;

    Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString);
    if (rfcMatcher.find()) {
        date = getDate(rfcMatcher.group(1));
        month = getMonth(rfcMatcher.group(2));
        year = getYear(rfcMatcher.group(3));
        timeOfDay = getTime(rfcMatcher.group(4));
    } else {
        Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString);
        if (ansicMatcher.find()) {
            month = getMonth(ansicMatcher.group(1));
            date = getDate(ansicMatcher.group(2));
            timeOfDay = getTime(ansicMatcher.group(3));
            year = getYear(ansicMatcher.group(4));
        } else {
            throw new IllegalArgumentException();
        }
    }

    // FIXME: Y2038 BUG!
    if (year >= 2038) {
        year = 2038;
        month = Calendar.JANUARY;
        date = 1;
    }

    Time time = new Time(Time.TIMEZONE_UTC);
    time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date,
            month, year);
    return time.toMillis(false /* use isDst */);
}
 
Example 5
Source File: HttpDateTime.java    From travelguide with Apache License 2.0 5 votes vote down vote up
public static long parse(String timeString)
        throws IllegalArgumentException {

    int date = 1;
    int month = Calendar.JANUARY;
    int year = 1970;
    TimeOfDay timeOfDay;

    Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString);
    if (rfcMatcher.find()) {
        date = getDate(rfcMatcher.group(1));
        month = getMonth(rfcMatcher.group(2));
        year = getYear(rfcMatcher.group(3));
        timeOfDay = getTime(rfcMatcher.group(4));
    } else {
        Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString);
        if (ansicMatcher.find()) {
            month = getMonth(ansicMatcher.group(1));
            date = getDate(ansicMatcher.group(2));
            timeOfDay = getTime(ansicMatcher.group(3));
            year = getYear(ansicMatcher.group(4));
        } else {
            throw new IllegalArgumentException();
        }
    }

    // FIXME: Y2038 BUG!
    if (year >= 2038) {
        year = 2038;
        month = Calendar.JANUARY;
        date = 1;
    }

    Time time = new Time(Time.TIMEZONE_UTC);
    time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date,
            month, year);
    return time.toMillis(false /* use isDst */);
}
 
Example 6
Source File: HttpDateTime.java    From Alite with GNU General Public License v3.0 5 votes vote down vote up
public static long parse(String timeString)
        throws IllegalArgumentException {

    int date = 1;
    int month = Calendar.JANUARY;
    int year = 1970;
    TimeOfDay timeOfDay;

    Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString);
    if (rfcMatcher.find()) {
        date = getDate(rfcMatcher.group(1));
        month = getMonth(rfcMatcher.group(2));
        year = getYear(rfcMatcher.group(3));
        timeOfDay = getTime(rfcMatcher.group(4));
    } else {
        Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString);
        if (ansicMatcher.find()) {
            month = getMonth(ansicMatcher.group(1));
            date = getDate(ansicMatcher.group(2));
            timeOfDay = getTime(ansicMatcher.group(3));
            year = getYear(ansicMatcher.group(4));
        } else {
            throw new IllegalArgumentException();
        }
    }

    // FIXME: Y2038 BUG!
    if (year >= 2038) {
        year = 2038;
        month = Calendar.JANUARY;
        date = 1;
    }

    Time time = new Time(Time.TIMEZONE_UTC);
    time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date,
            month, year);
    return time.toMillis(false /* use isDst */);
}
 
Example 7
Source File: HttpDateTime.java    From android-download-manager with Apache License 2.0 5 votes vote down vote up
public static long parse(String timeString) throws IllegalArgumentException {

		int date = 1;
		int month = Calendar.JANUARY;
		int year = 1970;
		TimeOfDay timeOfDay;

		Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString);
		if (rfcMatcher.find()) {
			date = getDate(rfcMatcher.group(1));
			month = getMonth(rfcMatcher.group(2));
			year = getYear(rfcMatcher.group(3));
			timeOfDay = getTime(rfcMatcher.group(4));
		} else {
			Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString);
			if (ansicMatcher.find()) {
				month = getMonth(ansicMatcher.group(1));
				date = getDate(ansicMatcher.group(2));
				timeOfDay = getTime(ansicMatcher.group(3));
				year = getYear(ansicMatcher.group(4));
			} else {
				throw new IllegalArgumentException();
			}
		}

		// FIXME: Y2038 BUG!
		if (year >= 2038) {
			year = 2038;
			month = Calendar.JANUARY;
			date = 1;
		}

		Time time = new Time(Time.TIMEZONE_UTC);
		time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date,
				month, year);
		return time.toMillis(false /* use isDst */);
	}
 
Example 8
Source File: HttpDateTime.java    From UnityOBBDownloader with Apache License 2.0 5 votes vote down vote up
public static long parse(String timeString)
        throws IllegalArgumentException {

    int date = 1;
    int month = Calendar.JANUARY;
    int year = 1970;
    TimeOfDay timeOfDay;

    Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString);
    if (rfcMatcher.find()) {
        date = getDate(rfcMatcher.group(1));
        month = getMonth(rfcMatcher.group(2));
        year = getYear(rfcMatcher.group(3));
        timeOfDay = getTime(rfcMatcher.group(4));
    } else {
        Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString);
        if (ansicMatcher.find()) {
            month = getMonth(ansicMatcher.group(1));
            date = getDate(ansicMatcher.group(2));
            timeOfDay = getTime(ansicMatcher.group(3));
            year = getYear(ansicMatcher.group(4));
        } else {
            throw new IllegalArgumentException();
        }
    }

    // FIXME: Y2038 BUG!
    if (year >= 2038) {
        year = 2038;
        month = Calendar.JANUARY;
        date = 1;
    }

    Time time = new Time(Time.TIMEZONE_UTC);
    time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date,
            month, year);
    return time.toMillis(false /* use isDst */);
}
 
Example 9
Source File: TimeFieldAdapter.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public Time get(ContentSet values)
{
    Long timestamp = values.getAsLong(mTimestampField);
    if (timestamp == null)
    {
        // if the time stamp is null we return null
        return null;
    }
    // create a new Time for the given time zone, falling back to UTC if none is given
    String timezone = mTzField == null ? Time.TIMEZONE_UTC : values.getAsString(mTzField);
    Time value = new Time(timezone == null ? Time.TIMEZONE_UTC : timezone);
    // set the time stamp
    value.set(timestamp);

    // cache mAlldayField locally
    String allDayField = mAllDayField;

    // set the allday flag appropriately
    Integer allDayInt = allDayField == null ? null : values.getAsInteger(allDayField);

    if ((allDayInt != null && allDayInt != 0) || (allDayField == null && mAllDayDefault))
    {
        value.set(value.monthDay, value.month, value.year);
        value.timezone = Time.TIMEZONE_UTC;
    }

    return value;
}
 
Example 10
Source File: TimeFieldAdapter.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public Time get(Cursor cursor)
{
    int tsIdx = cursor.getColumnIndex(mTimestampField);
    int tzIdx = mTzField == null ? -1 : cursor.getColumnIndex(mTzField);
    int adIdx = mAllDayField == null ? -1 : cursor.getColumnIndex(mAllDayField);

    if (tsIdx < 0 || (mTzField != null && tzIdx < 0) || (mAllDayField != null && adIdx < 0))
    {
        throw new IllegalArgumentException("At least one column is missing in cursor.");
    }

    if (cursor.isNull(tsIdx))
    {
        // if the time stamp is null we return null
        return null;
    }

    Long timestamp = cursor.getLong(tsIdx);

    // create a new Time for the given time zone, falling back to UTC if none is given
    String timezone = mTzField == null ? Time.TIMEZONE_UTC : cursor.getString(tzIdx);
    Time value = new Time(timezone == null ? Time.TIMEZONE_UTC : timezone);
    // set the time stamp
    value.set(timestamp);

    // set the allday flag appropriately
    Integer allDayInt = adIdx < 0 ? null : cursor.getInt(adIdx);

    if ((allDayInt != null && allDayInt != 0) || (mAllDayField == null && mAllDayDefault))
    {
        value.set(value.monthDay, value.month, value.year);
    }
    return value;
}