1
0
mirror of https://github.com/bspeice/dtparse synced 2024-11-14 09:58: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

@ -679,26 +679,26 @@ 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.mstridx.is_some() {
month = Some(self._ymd[self.mstridx.unwrap()]);
let other = self._ymd[1 - self.mstridx.unwrap()];
if other > 31 {
year = Some(other);
} else {
day = Some(other);
}
} else {
if self._ymd[0] > 31 { if self._ymd[0] > 31 {
dmy!(None, Some(self._ymd[1]), Some(self._ymd[0])); dmy!(None, Some(self._ymd[1]), Some(self._ymd[0]));
} else if self._ymd[1] > 31 { } else if self._ymd[1] > 31 {
@ -708,6 +708,7 @@ impl YMD {
} else { } else {
dmy!(Some(self._ymd[1]), Some(self._ymd[0]), None); 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) {
if self._ymd[1] > 31 { if self._ymd[1] > 31 {