Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 346be8db

Přidáno uživatelem Alex Konig před více než 3 roky(ů)

re #8934 Testing JsonParser

Zobrazit rozdíly:

Server/ServerApp/WeatherPredictionParser/JsonParser.cs
29 29
        /// <summary> Sunset time of currently parsed day </summary>
30 30
        DateTime sunsetTime;
31 31

  
32

  
33 32
        /// <summary>
34 33
        /// Constructor
35 34
        /// </summary>
......
39 38
            this.loader = loader;
40 39
        }
41 40

  
41
        /// <summary>
42
        /// Get predictions from Predictions that are within specified time span
43
        /// From-to including
44
        /// If from == DateTime.Min then all until to
45
        /// If to  == DateTime.Max then all starting from from
46
        /// </summary>
47
        /// <param name="from">DateTime from</param>
48
        /// <param name="to">DateTime to</param>
49
        /// <returns>List of predictions that fit specified criteria or null if incorrect input</returns>
50
        public override List<WeatherInfo> GetPredictionForTime(DateTime from, DateTime to)
51
        {
52
            if (Predictions == null)
53
                return null;
54

  
55
            List<WeatherInfo> res = new List<WeatherInfo>();
56

  
57
            if (from == DateTime.MinValue)
58
                from = Predictions[0].startTime;
59

  
60
            if (to == DateTime.MaxValue) {
61
                DateTime dt = Predictions[Predictions.Count - 1].startTime;
62
                int hour = dt.Hour + Predictions[Predictions.Count - 1].intervalLength;
63
                bool addDay = false;
64
                if (hour >= 24)
65
                {
66
                    hour -= 24;
67
                    addDay = true;
68
                }
69
                to = new DateTime(dt.Year, dt.Month, dt.Day, hour, dt.Minute, dt.Second);
70
                if (addDay)
71
                    to = to.AddDays(1);
72
            }
73

  
74
            if (from > to)
75
                return null;
76

  
77
            // for all parsed weather info
78
            foreach (WeatherInfo pred in Predictions)
79
            {
80
                int hour = pred.startTime.Hour + pred.intervalLength;
81
                bool addDay = false;
82
                if (hour >= 24)
83
                {
84
                    hour -= 24;
85
                    addDay = true;
86
                }
87
                DateTime endTime = new DateTime(pred.startTime.Year, pred.startTime.Month, pred.startTime.Day, hour, pred.startTime.Minute, pred.startTime.Second);
88
                if (addDay)
89
                    endTime = endTime.AddDays(1);
90

  
91
                // if both end and start not outside of interval
92
                if (!((pred.startTime < from && endTime <= from) || (pred.startTime > to && endTime > to)))
93
                    res.Add(pred);
94
            }
95

  
96
            return res;
97
        }
98

  
99

  
42 100
        /// <summary>
43 101
        /// Parse weather prediction
44 102
        /// Results is in attributes current for current weather and pred for weather prediction for today, tommorrow and day after tommorrow

Také k dispozici: Unified diff