コード例 #1
0
        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);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
 protected abstract bool TryParseUtc(TimeConverterContext context, Match match, out TimeConverterResult result);