• 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

93.94
/libraries/AdaptiveExpressions/BuiltinFunctions/GetNextViableDate.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 AdaptiveExpressions.Memory;
7
using Microsoft.Recognizers.Text.DataTypes.TimexExpression;
8

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

24
        private static (object value, string error) Evaluator(Expression expression, IMemory state, Options options)
25
        {
26
            TimexProperty parsed = null;
1✔
27
            string result = null;
1✔
28
            string error = null;
1✔
29
            var (validYear, validMonth, validDay) = (0, 0, 0);
1✔
30
            var currentUtcTime = DateTime.UtcNow;
1✔
31
            var convertedDateTime = currentUtcTime;
1✔
32
            IReadOnlyList<object> args;
33
            (args, error) = FunctionUtils.EvaluateChildren(expression, state, options);
1✔
34
            if (error == null)
1✔
35
            {
36
                (parsed, error) = FunctionUtils.ParseTimexProperty(args[0]);
1✔
37
            }
38

39
            if (error == null)
1✔
40
            {
41
                if (parsed.Year != null || parsed.Month == null || parsed.DayOfMonth == null)
1✔
42
                {
43
                    error = $"{args[0]} must be a timex string which only contains month and day-of-month, for example: 'XXXX-10-31'.";
1✔
44
                }
45
            }
46

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

64
            if (error == null)
1✔
65
            {
66
                var (year, month, day) = (convertedDateTime.Year, convertedDateTime.Month, convertedDateTime.Day);
1✔
67
                if (parsed.Month > month || (parsed.Month == month && parsed.DayOfMonth >= day))
×
68
                {
69
                    validYear = year;
1✔
70
                }
71
                else
72
                {
73
                    validYear = year + 1;
×
74
                }
75

76
                validMonth = parsed.Month ?? 0;
1✔
77
                validDay = parsed.DayOfMonth ?? 0;
1✔
78

79
                if (validMonth == 2 && validDay == 29)
1✔
80
                {
81
                    while (!DateTime.IsLeapYear(validYear))
1✔
82
                    {
83
                        validYear += 1;
1✔
84
                    }
85
                }
86

87
                result = TimexProperty.FromDate(new DateTime(validYear, validMonth, validDay)).TimexValue;
1✔
88
            }
89

90
            return (result, error);
1✔
91
        }
92
    }
93
}
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