mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
refactor to use exception helper factories
This commit is contained in:
@@ -166,7 +166,7 @@ impl CalendarParsedRXingResult {
|
||||
*/
|
||||
fn parseDate(when: String) -> Result<i64, Exceptions> {
|
||||
if !DATE_TIME.is_match(&when) {
|
||||
return Err(Exceptions::ParseException(Some(when)));
|
||||
return Err(Exceptions::parse(when));
|
||||
}
|
||||
if when.len() == 8 {
|
||||
// Show only year/month/day
|
||||
@@ -177,7 +177,7 @@ impl CalendarParsedRXingResult {
|
||||
// http://code.google.com/p/android/issues/detail?id=8330
|
||||
return match Utc.datetime_from_str(&format!("{}T000000Z", &when,), date_format_string) {
|
||||
Ok(dtm) => Ok(dtm.timestamp()),
|
||||
Err(e) => Err(Exceptions::ParseException(Some(e.to_string()))),
|
||||
Err(e) => Err(Exceptions::parse(e.to_string())),
|
||||
};
|
||||
}
|
||||
// The when string can be local time, or UTC if it ends with a Z
|
||||
@@ -185,14 +185,12 @@ impl CalendarParsedRXingResult {
|
||||
&& when
|
||||
.chars()
|
||||
.nth(15)
|
||||
.ok_or(Exceptions::IndexOutOfBoundsException(None))?
|
||||
.ok_or(Exceptions::indexOutOfBoundsEmpty())?
|
||||
== 'Z'
|
||||
{
|
||||
return match Utc.datetime_from_str(&when, "%Y%m%dT%H%M%SZ") {
|
||||
Ok(dtm) => Ok(dtm.with_timezone(&Utc).timestamp()),
|
||||
Err(e) => Err(Exceptions::ParseException(Some(format!(
|
||||
"couldn't parse string: {e}"
|
||||
)))),
|
||||
Err(e) => Err(Exceptions::parse(format!("couldn't parse string: {e}"))),
|
||||
};
|
||||
}
|
||||
// Try once more, with weird tz formatting
|
||||
@@ -202,16 +200,14 @@ impl CalendarParsedRXingResult {
|
||||
let tz_parsed: Tz = match tz_part.parse() {
|
||||
Ok(time_zone) => time_zone,
|
||||
Err(e) => {
|
||||
return Err(Exceptions::ParseException(Some(format!(
|
||||
return Err(Exceptions::parse(format!(
|
||||
"couldn't parse timezone '{tz_part}': {e}"
|
||||
))))
|
||||
)))
|
||||
}
|
||||
};
|
||||
return match Utc.datetime_from_str(time_part, "%Y%m%dT%H%M%S") {
|
||||
Ok(dtm) => Ok(dtm.with_timezone(&tz_parsed).timestamp()),
|
||||
Err(e) => Err(Exceptions::ParseException(Some(format!(
|
||||
"couldn't parse string: {e}"
|
||||
)))),
|
||||
Err(e) => Err(Exceptions::parse(format!("couldn't parse string: {e}"))),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -219,9 +215,7 @@ impl CalendarParsedRXingResult {
|
||||
if when.len() == 15 {
|
||||
return match Utc.datetime_from_str(&when, "%Y%m%dT%H%M%S") {
|
||||
Ok(dtm) => Ok(dtm.timestamp()),
|
||||
Err(e) => Err(Exceptions::ParseException(Some(format!(
|
||||
"couldn't parse local time: {e}"
|
||||
)))),
|
||||
Err(e) => Err(Exceptions::parse(format!("couldn't parse local time: {e}"))),
|
||||
};
|
||||
}
|
||||
Self::parseDateTimeString(&when)
|
||||
@@ -258,7 +252,7 @@ impl CalendarParsedRXingResult {
|
||||
let z = parseable
|
||||
.as_str()
|
||||
.parse::<i64>()
|
||||
.map_err(|e| Exceptions::ParseException(Some(e.to_string())))?;
|
||||
.map_err(|e| Exceptions::parse(e.to_string()))?;
|
||||
durationMS += unit * z;
|
||||
}
|
||||
}
|
||||
@@ -283,9 +277,9 @@ impl CalendarParsedRXingResult {
|
||||
if let Ok(dtm) = DateTime::parse_from_str(dateTimeString, "%Y%m%dT%H%M%S") {
|
||||
Ok(dtm.timestamp())
|
||||
} else {
|
||||
Err(Exceptions::ParseException(Some(format!(
|
||||
Err(Exceptions::parse(format!(
|
||||
"Couldn't parse {dateTimeString}"
|
||||
))))
|
||||
)))
|
||||
}
|
||||
// DateFormat format = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH);
|
||||
// return format.parse(dateTimeString).getTime();
|
||||
|
||||
Reference in New Issue
Block a user