protected override bool TryParseUtc(TimeConverterContext context, Match match, out TimeConverterResult result) { result = null; var hours = match.Groups["hours"].Value; var ampm = match.Groups["ampm"].Value; var timezone = match.Groups["timezone"].Value; var tzz = context.TimeZones.FirstOrDefault(tz => tz.IsMatch(timezone)); if (tzz != null && DateTime.TryParseExact($"{hours}{ampm}", $"htt", CultureInfo.InvariantCulture, DateTimeStyles.None, out var time)) { var offset = tzz.TimeZoneInfo.GetUtcOffset(time); result = new TimeConverterResult() { Expression = context.Expression, ResultUtc = new DateTimeOffset(time.Subtract(offset), TimeSpan.Zero), Rule = this, TimeZone = tzz }; return(true); } return(false); }
public bool TryParse(TimeConverterContext context, out TimeConverterResult result) { result = null; var match = Regex.Match(context.Expression); if (!match.Success) { return(false); } return(TryParseUtc(context, match, out result)); }
protected abstract bool TryParseUtc(TimeConverterContext context, Match match, out TimeConverterResult result);