private (Transaction transacion, bool haslookedhead) ParseTransaction(IEnumerator <string> enumerator) { var pattern = @"^\s*(\d{2}\.\d{2}\.\d{2})\s*([^\s].*[^\s])\s*(\d{2})\.(\d{2})\s*\d{2}\.\d{2}\.\d{2}\s([\d\s]+\,\d\d)\s*$"; var currencyPattern = @"^\s*([^\s]+)\s+([^\s]+)\s+Kurs\s+([^\s]+)\s*$"; var match = Regex.Match(enumerator.Current, pattern); if (match.Success) { var recordDate = DatePattern.Parse(match.Groups[1].Value).Value; var transactionDate = new LocalDate( recordDate.Year, int.Parse(match.Groups[4].Value), int.Parse(match.Groups[3].Value)); // If they are in different years. if (transactionDate > recordDate) { transactionDate = new LocalDate( recordDate.PlusMonths(-1).Year, transactionDate.Month, transactionDate.Day); } var trans = new Transaction { RecordDate = recordDate, TransactionDate = transactionDate, Description = match.Groups[2].Value, Amount = -decimal.Parse( match.Groups[5].Value, _trumfNumberFormat) }; var lookahead = false; trans.Currency = DefaultCurrency; trans.CurAmount = trans.Amount; // Lookahead for currency if (enumerator.MoveNext()) { match = Regex.Match(enumerator.Current, currencyPattern); if (match.Success) { trans.Currency = match.Groups[1].Value; trans.CurAmount = -decimal.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture.NumberFormat); } else { lookahead = true; } } return(trans, lookahead); } return(null, false); }
private LocalDate ParseDateWithPattern(string input) { LocalDate cPeriod = default; if (_pattern.Parse(input).Success) { cPeriod = _pattern.Parse(input).Value; } else { throw new Exception("DateTime Pattern Error"); } return(cPeriod); }
private static List <(LocalDateTime start, LocalDateTime end)> GetSessions(string s) { var list = new List <(LocalDateTime start, LocalDateTime end)>(); if (string.IsNullOrEmpty(s)) { return(list); } var days = s.Split(';'); foreach (var day in days) { var parts = day.Split(':'); Debug.Assert(parts.Count() == 2); var date = DatePattern.Parse(parts[0]).Value; var sessions = parts[1].Split(',').Distinct(); // the sessions may be repeated(?) foreach (var session in sessions.Where(x => x != "CLOSED")) { var times = GetSessionTime(session); var start = date.At(times.start); var end = date.At(times.end); if (end < start) { start = start.PlusDays(-1); //end = end.PlusDays(1); ?? } if (list.Any() && (start <= list.Last().end || end <= start)) // ensure consecutive, non-overlapping periods { throw new InvalidDataException("Invalid period."); } list.Add((start, end)); } } return(list);
private Transaction ReadTransaction(string line) { var match = Regex.Match(line, @"^(\d{2}\.\d{2}\.\d{4})\s+(.*\D)\s*((\s\-?\d{1,3})*,\d{2})$"); return(match.Success ? new Transaction { TransactionDate = DatePattern.Parse(match.Groups[1].Value).Value, RecordDate = DatePattern.Parse(match.Groups[1].Value).Value, Amount = -decimal.Parse(match.Groups[3].Value), Description = match.Groups[2].Value.Trim(), Currency = DefaultCurrency, CurAmount = -decimal.Parse(match.Groups[3].Value) } : null); }
internal static Instant ToInstant(this string dateStr, LocalTime time, DateTimeZone tz) { var result = DatePattern.Parse(dateStr); var date = result.Success ? result.Value : throw new Exception($"Could not convert '{dateStr}' to LocalDate.", result.Exception); return(date.At(time).InZoneStrictly(tz).ToInstant()); }
/// <summary> /// Constructor /// Sets up the default serialization for some basic types, which can /// be overwritten by the user. /// </summary> public TypeConverterSetup() { /* * Default type conversions */ this.RegisterTypeConverter <int, string>(x => x.ToString()); this.RegisterTypeConverter <string, int>(x => Convert.ToInt32(x)); this.RegisterTypeConverter <long, string>(x => x.ToString()); this.RegisterTypeConverter <string, long>(x => Convert.ToInt64(x)); this.RegisterTypeConverter <float, string>(x => x.ToString()); this.RegisterTypeConverter <string, float>(x => Convert.ToSingle(x)); this.RegisterTypeConverter <double, string>(x => x.ToString()); this.RegisterTypeConverter <string, double>(x => Convert.ToDouble(x)); this.RegisterTypeConverter <decimal, string>(x => x.ToString()); this.RegisterTypeConverter <string, decimal>(x => Convert.ToDecimal(x)); this.RegisterTypeConverter <LocalDate, string>(x => datePattern.Format(x)); this.RegisterTypeConverter <string, LocalDate>(x => datePattern.Parse(x).Value); this.RegisterTypeConverter <LocalDateTime, string>((x) => { return(dtPattern.Format(x)); }); this.RegisterTypeConverter <string, LocalDateTime>((x) => { return(dtPattern.Parse(x).Value); }); }
public static LocalDate?GetNullableDate(string input) { if (input == null) { return(null); } ParseResult <LocalDate> res = DatePattern.Parse(input); if (res.Success) { return(res.Value); } else { return(null); } }
private Transaction ParseInputTransaction(string line) { var pattern = @"^(\d{2}\.\d{2}\.\d{4})\s+(.*)\s-\s(?<amount>-?\d{1,3}(\.\d{3})*\,\d{2})$"; var match = Regex.Match(line, pattern); return(match.Success ? new Transaction { TransactionDate = DatePattern.Parse(match.Groups[1].Value).Value, RecordDate = DatePattern.Parse(match.Groups[1].Value).Value, Amount = -decimal.Parse(match.Groups["amount"].Value, _norNumberFormat), Description = match.Groups[2].Value, CurAmount = -decimal.Parse(match.Groups["amount"].Value, _norNumberFormat), Currency = DefaultCurrency } : null); }
public static LocalDate?ToDate(string dateString) { if (string.IsNullOrEmpty(dateString)) { return(null); } return(Pattern.Parse(dateString).GetValueOrThrow()); }
internal static LocalDate ToDate(this string str) { ParseResult <LocalDate> result = DatePattern.Parse(str); if (result.Success) { return(result.Value); } throw new InvalidDataException($"Could not convert '{str}' to LocalDate.", result.Exception); }
internal static IEnumerable <BillDocument> findBillDocuments(IHtmlDocument billDocumentIndex) { var baseUri = new Uri(billDocumentIndex.BaseUri); return(billDocumentIndex.QuerySelectorAll("a[href *= 'ViewBillDisplay']").Select(aEl => { var href = new Uri(baseUri, aEl.GetAttribute("href")); return new BillDocument { accountId = long.Parse(HttpUtility.ParseQueryString(href.Query)["acct_no"]), publishingDate = BILL_DATE_PATTERN.Parse(aEl.TextContent.Trim()).Value }; })); }
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) { if (bindingContext.ModelType != typeof(LocalDate)) { return(false); } var val = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if (val == null) { return(false); } var rawValue = val.RawValue as string; var result = _localDatePattern.Parse(rawValue); if (result.Success) { bindingContext.Model = result.Value; } return(result.Success); }
public override object ConvertFromString(string text, IReaderRow row, MemberMapData memberMapData) { if (string.IsNullOrEmpty(text) || text == "NULL") { return(null); } var parsed = DatePatternDash.Parse(text); if (!parsed.Success) { parsed = DatePatternSlash.Parse(text); } if (!parsed.Success) { throw new Exception($"Error parsing DateTime? on row {row.Context.Row} - {parsed.Exception}", parsed.Exception); } return(parsed.Value.ToDateTimeUnspecified()); }
public static Option <LocalDate> GetLocalDate(string key) { return(GetString(key) .Select(value => LocalDatePattern.Parse(value).ToOption()) .Flatten()); }
public static LocalDate LocalDate(string value) => LocalDatePattern.Parse(value).Value;
public override object FromStringValue(string xml) { return(_datePattern.Parse(xml).Value); }
private bool DateIsValid(string cprValue) { return(_datePattern.Parse(cprValue.Substring(0, 6)).Success); }
public LocalDate PatternParse() { var parseResult = Pattern.Parse("26/12/2009"); return(parseResult.Value); }
public bool IsValid(string literal) { return(_pattern.Parse(literal).Success); }
public void PatternParse() { var parseResult = Pattern.Parse("26/12/2009"); parseResult.Value.Consume(); }
public static LocalDate ToLocalDate(this string dateString) { var result = OurLocalDatePattern.Parse(dateString).Value; return(result); }