当前位置: 首页>>代码示例>>Java>>正文


Java TimeFormatException类代码示例

本文整理汇总了Java中android.util.TimeFormatException的典型用法代码示例。如果您正苦于以下问题:Java TimeFormatException类的具体用法?Java TimeFormatException怎么用?Java TimeFormatException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TimeFormatException类属于android.util包,在下文中一共展示了TimeFormatException类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parsePart

import android.util.TimeFormatException; //导入依赖的package包/类
@Override
public int parsePart(String value, EventRecurrence er) {
    if (VALIDATE_UNTIL) {
        try {
            // Parse the time to validate it.  The result isn't retained.
            Time until = new Time();
            until.parse(value);
        } catch (TimeFormatException tfe) {
            throw new InvalidFormatException("Invalid UNTIL value: " + value);
        }
    }
    er.until = value;
    return PARSED_UNTIL;
}
 
开发者ID:andela-kogunde,项目名称:CheckSmarter,代码行数:15,代码来源:EventRecurrence.java

示例2: timeFrom3339

import android.util.TimeFormatException; //导入依赖的package包/类
public static Time timeFrom3339(String s3339) {
    final Time time = new Time();
    if (TextUtils.isEmpty(s3339)) {
        return time;
    }
    try {
        time.parse3339(s3339);
    } catch (TimeFormatException e) {
        return time;
    }
    time.switchTimezone(Time.getCurrentTimezone());
    return time;
}
 
开发者ID:avast,项目名称:sms-ticket,代码行数:14,代码来源:FormatUtil.java

示例3: timeFrom3339

import android.util.TimeFormatException; //导入依赖的package包/类
public static Time timeFrom3339(String s3339) {
    final android.text.format.Time time = new Time();
    if (TextUtils.isEmpty(s3339)) {
        return time;
    }
    try {
        time.parse3339(s3339);
    } catch (TimeFormatException e) {
        return time;
    }
    time.switchTimezone(android.text.format.Time.getCurrentTimezone());
    return time;
}
 
开发者ID:avast,项目名称:sms-ticket,代码行数:14,代码来源:FormatUtil.java

示例4: parseRecurrenceDates

import android.util.TimeFormatException; //导入依赖的package包/类
/**
 * Parses the provided RDATE or EXDATE string into an array of longs
 * representing each date/time in the recurrence.
 * @param recurrence The recurrence to be parsed.
 * @return The list of date/times.
 */
public static long[] parseRecurrenceDates(String recurrence)
        throws EventRecurrence.InvalidFormatException{
    // TODO: use "local" time as the default.  will need to handle times
    // that end in "z" (UTC time) explicitly at that point.
    String tz = Time.TIMEZONE_UTC;
    int tzidx = recurrence.indexOf(";");
    if (tzidx != -1) {
        tz = recurrence.substring(0, tzidx);
        recurrence = recurrence.substring(tzidx + 1);
    }
    Time time = new Time(tz);
    String[] rawDates = recurrence.split(",");
    int n = rawDates.length;
    long[] dates = new long[n];
    for (int i = 0; i<n; ++i) {
        // The timezone is updated to UTC if the time string specified 'Z'.
        try {
            time.parse(rawDates[i]);
        } catch (TimeFormatException e) {
            throw new EventRecurrence.InvalidFormatException(
                    "TimeFormatException thrown when parsing time " + rawDates[i]
                            + " in recurrence " + recurrence);

        }
        dates[i] = time.toMillis(false /* use isDst */);
        time.timezone = tz;
    }
    return dates;
}
 
开发者ID:x7hub,项目名称:Calendar_lunar,代码行数:36,代码来源:RecurrenceSet.java

示例5: parsePart

import android.util.TimeFormatException; //导入依赖的package包/类
@Override public int parsePart(String value, EventRecurrence er) {
    if (VALIDATE_UNTIL) {
        try {
            // Parse the time to validate it.  The result isn't retained.
            Time until = new Time();
            until.parse(value);
        } catch (TimeFormatException tfe) {
            throw new InvalidFormatException("Invalid UNTIL value: " + value);
        }
    }
    er.until = value;
    return PARSED_UNTIL;
}
 
开发者ID:x7hub,项目名称:Calendar_lunar,代码行数:14,代码来源:EventRecurrence.java

示例6: parseCrashReportTimestamp

import android.util.TimeFormatException; //导入依赖的package包/类
protected Time parseCrashReportTimestamp(String crashTime) {
    Time parsedTime = new Time();

    try {
        parsedTime.parse3339(crashTime);
    } catch (TimeFormatException e) {
        ACRA.log.w(getTag(), String.format("Failed to decode timestamp %s", crashTime), e);
    }

    return parsedTime;
}
 
开发者ID:KoljaTM,项目名称:Yarrn,代码行数:12,代码来源:Report.java

示例7: throwTimeFormatException

import android.util.TimeFormatException; //导入依赖的package包/类
private void throwTimeFormatException() {
  throw constructor().withParameterTypes(String.class).in(TimeFormatException.class)
      .newInstance("fail");
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:5,代码来源:ShadowTime.java

示例8: shouldThrowTimeFormatException

import android.util.TimeFormatException; //导入依赖的package包/类
@Test(expected = TimeFormatException.class)
public void shouldThrowTimeFormatException() throws Exception {
  Time t = new Time();
  t.parse("BLARGH");
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:6,代码来源:TimeTest.java

示例9: endElement

import android.util.TimeFormatException; //导入依赖的package包/类
@Override
public void endElement(String uri, String localName, String name)
		throws SAXException, TimeFormatException {

	if (localName.equals(TITLE)) {
		inTitleTag = false;
		note.setTitle(title.toString());
	} 
	else if (localName.equals(LAST_CHANGE_DATE)) {
		inLastChangeDateTag = false;
		note.setLastChangeDate(lastChangeDate.toString());
	}
	else if (localName.equals(NOTE_CONTENT)) {
		inNoteContentTag = false;
		note.setXmlContent(noteContent.toString());
	}
	else if (localName.equals(CREATE_DATE)) {
		inCreateDateTag = false;
		if(createDate.length() > 0)
			note.setCreateDate(createDate.toString());
	}
	else if (localName.equals(NOTE_C)) {
		inCursorTag = false;
		if(cursorPos.length() > 0)
			note.cursorPos = Integer.parseInt(cursorPos.toString());
	}
	else if (localName.equals(NOTE_W)) {
		inWidthTag = false;
		if(width.length() > 0)
			note.width = Integer.parseInt(width.toString());
	}
	else if (localName.equals(NOTE_H)) {
		inHeightTag = false;
		if(height.length() > 0)
			note.height = Integer.parseInt(height.toString());
	}
	else if (localName.equals(NOTE_X)) {
		inXTag = false;
		if(X.length() > 0)
			note.X = Integer.parseInt(X.toString());
	}
	else if (localName.equals(NOTE_Y)) {
		inYTag = false;
		if(Y.length() > 0)
			note.Y = Integer.parseInt(Y.toString());
	}
	else if (localName.equals(NOTE_TAG)) {
		inTagTag = false;
		if(tag.length() > 0)
			note.addTag(tag.toString());
	}
}
 
开发者ID:Tomdroidd,项目名称:tomdroid,代码行数:53,代码来源:NoteHandler.java

示例10: populateContentValues

import android.util.TimeFormatException; //导入依赖的package包/类
/**
 * Populates the database map of values with the appropriate RRULE, RDATE,
 * EXRULE, and EXDATE values extracted from the parsed iCalendar component.
 * @param component The iCalendar component containing the desired
 * recurrence specification.
 * @param values The db values that should be updated.
 * @return true if the component contained the necessary information
 * to specify a recurrence.  The required fields are DTSTART,
 * one of DTEND/DURATION, and one of RRULE/RDATE.  Returns false if
 * there was an error, including if the date is out of range.
 */
public static boolean populateContentValues(ICalendar.Component component,
        ContentValues values) {
    try {
        ICalendar.Property dtstartProperty =
                component.getFirstProperty("DTSTART");
        String dtstart = dtstartProperty.getValue();
        ICalendar.Parameter tzidParam =
                dtstartProperty.getFirstParameter("TZID");
        // NOTE: the timezone may be null, if this is a floating time.
        String tzid = tzidParam == null ? null : tzidParam.value;
        Time start = new Time(tzidParam == null ? Time.TIMEZONE_UTC : tzid);
        boolean inUtc = start.parse(dtstart);
        boolean allDay = start.allDay;

        // We force TimeZone to UTC for "all day recurring events" as the server is sending no
        // TimeZone in DTSTART for them
        if (inUtc || allDay) {
            tzid = Time.TIMEZONE_UTC;
        }

        String duration = computeDuration(start, component);
        String rrule = flattenProperties(component, "RRULE");
        String rdate = extractDates(component.getFirstProperty("RDATE"));
        String exrule = flattenProperties(component, "EXRULE");
        String exdate = extractDates(component.getFirstProperty("EXDATE"));

        if ((TextUtils.isEmpty(dtstart))||
                (TextUtils.isEmpty(duration))||
                ((TextUtils.isEmpty(rrule))&&
                        (TextUtils.isEmpty(rdate)))) {
                if (false) {
                    Log.d(TAG, "Recurrence missing DTSTART, DTEND/DURATION, "
                                + "or RRULE/RDATE: "
                                + component.toString());
                }
                return false;
        }

        if (allDay) {
            start.timezone = Time.TIMEZONE_UTC;
        }
        long millis = start.toMillis(false /* use isDst */);
        values.put(CalendarContract.Events.DTSTART, millis);
        if (millis == -1) {
            if (false) {
                Log.d(TAG, "DTSTART is out of range: " + component.toString());
            }
            return false;
        }

        values.put(CalendarContract.Events.RRULE, rrule);
        values.put(CalendarContract.Events.RDATE, rdate);
        values.put(CalendarContract.Events.EXRULE, exrule);
        values.put(CalendarContract.Events.EXDATE, exdate);
        values.put(CalendarContract.Events.EVENT_TIMEZONE, tzid);
        values.put(CalendarContract.Events.DURATION, duration);
        values.put(CalendarContract.Events.ALL_DAY, allDay ? 1 : 0);
        return true;
    } catch (TimeFormatException e) {
        // Something is wrong with the format of this event
        Log.i(TAG,"Failed to parse event: " + component.toString());
        return false;
    }
}
 
开发者ID:x7hub,项目名称:Calendar_lunar,代码行数:76,代码来源:RecurrenceSet.java


注:本文中的android.util.TimeFormatException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。