• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

microsoft / botbuilder-dotnet / 333699

15 Dec 2022 07:53PM UTC coverage: 79.128% (+0.07%) from 79.062%
333699

Pull #6572

CI-PR build

GitHub
Merge cd7fc8620 into a908ca355
Pull Request #6572: [#6563] Expired JWT token exception not being handled

25742 of 32532 relevant lines covered (79.13%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/libraries/AdaptiveExpressions/BuiltinFunctions/GetNextViableTime.cs
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
// Licensed under the MIT License.
3

4
using System;
5
using System.Collections.Generic;
6
using System.Text.RegularExpressions;
7
using AdaptiveExpressions.Memory;
8
using Microsoft.Recognizers.Text.DataTypes.TimexExpression;
9

10
namespace AdaptiveExpressions.BuiltinFunctions
11
{
12
    /// <summary>
13
    /// Return the next viable time of a timex expression based on the current time and user's timezone.
14
    /// </summary>
15
    internal class GetNextViableTime : ExpressionEvaluator
16
    {
17
        /// <summary>
18
        /// Initializes a new instance of the <see cref="GetNextViableTime"/> class.
19
        /// </summary>
20
        public GetNextViableTime()
21
            : base(ExpressionType.GetNextViableTime, Evaluator, ReturnType.String, FunctionUtils.ValidateUnaryOrBinaryString)
1✔
22
        {
23
        }
1✔
24

25
        private static (object value, string error) Evaluator(Expression expression, IMemory state, Options options)
26
        {
27
                        TimexProperty parsed = null;
1✔
28
                        string result = null;
1✔
29
                        string error = null;
1✔
30
                        var (validHour, validMinute, validSecond) = (0, 0, 0);
1✔
31
                        var formatRegex = new Regex("TXX:[0-5][0-9]:[0-5][0-9]");
1✔
32
                        var currentUtcTime = DateTime.UtcNow;
1✔
33
                        var convertedDateTime = currentUtcTime;
1✔
34
                        IReadOnlyList<object> args;
35
                        (args, error) = FunctionUtils.EvaluateChildren(expression, state, options);
1✔
36
                        if (error == null)
1✔
37
                        {
38
                            if (!formatRegex.IsMatch(args[0] as string))
1✔
39
                            {
40
                                error = $"{args[0]}  must be a timex string which only contains minutes and seconds, for example: 'TXX:15:28'";
1✔
41
                            }
42
                        }
43

44
                        if (error == null)
1✔
45
                        {
46
                            if (args.Count == 2 && args[1] is string timezone)
1✔
47
                            {
48
                                object convertedTimeZone = null;
1✔
49
                                (convertedTimeZone, error) = FunctionUtils.ConvertTimeZoneFormat(timezone);
1✔
50
                                if (error == null)
1✔
51
                                {
52
                                    convertedDateTime = TimeZoneInfo.ConvertTimeFromUtc(currentUtcTime, (TimeZoneInfo)convertedTimeZone);
1✔
53
                                }
54
                            }
55
                            else
56
                            {
57
                                convertedDateTime = currentUtcTime.ToLocalTime();
1✔
58
                            }
59
                        }
60

61
                        if (error == null)
1✔
62
                        {
63
                            (parsed, error) = FunctionUtils.ParseTimexProperty((args[0] as string).Replace("XX", "00"));
1✔
64
                        }
65

66
                        if (error == null)
1✔
67
                        {
68
                            var (hour, minute, second) = (convertedDateTime.Hour, convertedDateTime.Minute, convertedDateTime.Second);
1✔
69
                            if (parsed.Minute > minute || (parsed.Minute == minute && parsed.Second >= second))
×
70
                            {
71
                                validHour = hour;
×
72
                            }
73
                            else
74
                            {
75
                                validHour = hour + 1;
1✔
76
                            }
77

78
                            if (validHour >= 24)
1✔
79
                            {
80
                                validHour -= 24;
×
81
                            }
82

83
                            validMinute = parsed.Minute ?? 0;
1✔
84
                            validSecond = parsed.Second ?? 0;
1✔
85
                            result = TimexProperty.FromTime(new Time(validHour, validMinute, validSecond)).TimexValue;
1✔
86
                        }
87

88
                        return (result, error);
1✔
89
                    }
90
    }
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc