private void AdjustDmyForShortenedRange(Tuple <string, string> input, ArchiveDate date, DateMonthStyle monthStyle) { if (date.A != null || date.B?.ValueType != DateValueType.Year || date.B.Month == 0) { return; } int i = (int)(monthStyle == 0 ? 0 : monthStyle - 1); Match match = _shortenedDmyRegexes[i].Match(input.Item1); if (match.Success) { // copy YM from Max date.A = new ArchiveDatePoint { ValueType = DateValueType.Year, Value = date.B.Value, IsYearInferred = date.B.IsYearInferred, Month = date.B.Month, IsMonthInferred = date.B.IsMonthInferred }; // style N has groups d/m or md if (i == 0) { if (match.Groups["md"].Length > 0) { if (date.B.Day > 0) { date.A.Day = short.Parse(match.Groups["md"].Value, CultureInfo.InvariantCulture); } else { date.A.Month = short.Parse(match.Groups["md"].Value, CultureInfo.InvariantCulture); } } else { date.A.Month = short.Parse(match.Groups["m"].Value, CultureInfo.InvariantCulture); date.A.Day = short.Parse(match.Groups["d"].Value, CultureInfo.InvariantCulture); } } // N else { // styles S/F have groups m/d if (match.Groups["m"].Length > 0) { YmdToken m = YmdToken.Parse(match.Groups["m"].Value, 'm'); date.A.Month = m.Value; } if (match.Groups["d"].Length > 0) { YmdToken d = YmdToken.Parse(match.Groups["d"].Value, 'd'); date.A.Day = d.Value; } } // !N } }
private ArchiveDatePoint ParsePoint(string text, bool dmy, DateMonthStyle monthStyle) { // senza data or s.d. if (_sineDataRegex.IsMatch(text)) { return(null); } // century if (text.IndexOf("secolo", StringComparison.OrdinalIgnoreCase) > -1 || text.IndexOf("sec.", StringComparison.CurrentCultureIgnoreCase) > -1) { return(ParseCenturyPoint(text)); } // decade Match match = _decadeRegex.Match(text); if (match.Success) { return(ParseDecade(match.Groups[1].Value)); } // DMY/YMD ArchiveDatePoint point = new ArchiveDatePoint(); // about if (_aboutRegex.IsMatch(text)) { point.Approximation = ApproximationType.About; } int i = (int)(monthStyle == 0 ? 0 : monthStyle - 1); Regex r = dmy ? _dmyRegexes[i] : _ymdRegexes[i]; match = r.Match(text); if (!match.Success) { return(null); } YmdToken y = YmdToken.Parse(match.Groups["y"].Value, 'y'); YmdToken m = YmdToken.Parse(match.Groups["m"].Value, 'm'); YmdToken d = YmdToken.Parse(match.Groups["d"].Value, 'd'); // take square brackets into account: this depends on the DMY/YMD order MarkInferred(dmy ? new[] { d, m, y } : new[] { y, m, d }); point.Value = y.Value; point.IsYearInferred = y.IsInferred; if (m != null) { point.Month = m.Value; point.IsMonthInferred = m.IsInferred; } if (d != null) { point.Day = d.Value; point.IsDayInferred = d.IsInferred; } return(point); }