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

microsoft / botbuilder-dotnet / 336829

13 Jan 2023 07:50PM UTC coverage: 73.28% (-0.02%) from 73.295%
336829

Pull #6575

CI-PR build

GitHub
Merge 56cd27f8e into 74a86129b
Pull Request #6575: Fix cast issue in SendHandoffActivity action

23920 of 32642 relevant lines covered (73.28%)

0.73 hits per line

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

90.91
/libraries/AdaptiveExpressions/BuiltinFunctions/GetPreviousViableTime.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 previous viable time of a timex expression based on the current time and user's timezone.
14
    /// </summary>
15
    internal class GetPreviousViableTime : ExpressionEvaluator
16
    {
17
        /// <summary>
18
        /// Initializes a new instance of the <see cref="GetPreviousViableTime"/> class.
19
        /// </summary>
20
        public GetPreviousViableTime()
21
            : base(ExpressionType.GetPreviousViableTime, 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
            IReadOnlyList<object> args;
32
            var formatRegex = new Regex("TXX:[0-5][0-9]:[0-5][0-9]");
1✔
33
            var currentUtcTime = DateTime.UtcNow;
1✔
34
            var convertedDateTime = currentUtcTime;
1✔
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;
1✔
72
                }
73
                else
74
                {
75
                    validHour = hour - 1;
×
76
                }
77

78
                if (validHour < 0)
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