1
0
mirror of https://github.com/bspeice/dtparse synced 2024-12-22 04:18:09 -05:00

Refactor if logic for resolve_ymd.

This commit is contained in:
Mark H. Colburn 2018-06-25 10:49:30 -07:00
parent d7031ee279
commit f819ec8e40

View File

@ -651,7 +651,7 @@ impl YMD {
($d:expr, $m:expr, $y:expr) => { ($d:expr, $m:expr, $y:expr) => {
{ {
day = $d; day = $d;
month = $m; month = $m;
year = $y; year = $y;
} }
}; };
@ -679,34 +679,35 @@ impl YMD {
"More than three YMD values".to_owned(), "More than three YMD values".to_owned(),
)); ));
} }
if len_ymd == 1 || (self.mstridx.is_some() && len_ymd == 2) { if len_ymd == 1 {
if self.mstridx.is_some() { if self.mstridx.is_some() {
month = Some(self._ymd[self.mstridx.unwrap()]); month = Some(self._ymd[self.mstridx.unwrap()]);
other = if len_ymd == 1 { let other = self._ymd[0];
Some(self._ymd[0]) if other > 31 {
year = Some(other);
} else { } else {
Some(self._ymd[1 - self.mstridx.unwrap()]) day = Some(other);
};
} else {
other = Some(self._ymd[0]);
}
if len_ymd > 1 || self.mstridx.is_some() {
if other.unwrap_or(0) > 31 {
year = other;
} else {
day = other;
} }
} }
} else if len_ymd == 2 { } else if len_ymd == 2 {
if self._ymd[0] > 31 { if self.mstridx.is_some() {
dmy!(None, Some(self._ymd[1]), Some(self._ymd[0])); month = Some(self._ymd[self.mstridx.unwrap()]);
} else if self._ymd[1] > 31 { let other = self._ymd[1 - self.mstridx.unwrap()];
dmy!(None, Some(self._ymd[0]), Some(self._ymd[1])); if other > 31 {
} else if dayfirst && self._ymd[1] <= 12 { year = Some(other);
dmy!(Some(self._ymd[0]), Some(self._ymd[1]), None); } else {
day = Some(other);
}
} else { } else {
dmy!(Some(self._ymd[1]), Some(self._ymd[0]), None); if self._ymd[0] > 31 {
dmy!(None, Some(self._ymd[1]), Some(self._ymd[0]));
} else if self._ymd[1] > 31 {
dmy!(None, Some(self._ymd[0]), Some(self._ymd[1]));
} else if dayfirst && self._ymd[1] <= 12 {
dmy!(Some(self._ymd[0]), Some(self._ymd[1]), None);
} else {
dmy!(Some(self._ymd[1]), Some(self._ymd[0]), None);
}
} }
} else if len_ymd == 3 { } else if len_ymd == 3 {
if self.mstridx == Some(0) { if self.mstridx == Some(0) {