summaryrefslogtreecommitdiffstats
path: root/weather/src/forecastdata.cpp
blob: 45e2567ba924a2ce0222a8a231373230b70b51e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "forecastdata.h"

struct ConditionTypeData
{
    const int id;
    Forecast::ForecastType type;
};

static const int ContitionTypeCount = 47;
static const ConditionTypeData ContitionType[ContitionTypeCount] = {
    {1, Forecast::Storm},
    {2, Forecast::Thunderstorm},
    {3, Forecast::Thunderstorm},
    {4, Forecast::Thunderstorm},
    {5, Forecast::Sleet},
    {6, Forecast::Rain},
    {7, Forecast::Sleet},
    {8, Forecast::Mist},
    {9, Forecast::Mist},
    {10, Forecast::Rain},
    {11, Forecast::Rain},
    {12, Forecast::Rain},
    {13, Forecast::Flurries},
    {14, Forecast::Flurries},
    {15, Forecast::Snow},
    {16, Forecast::Snow},
    {17, Forecast::Snow},
    {18, Forecast::Sleet},
    {19, Forecast::Haze},
    {20, Forecast::Fog},
    {21, Forecast::Haze},
    {22, Forecast::Fog},
    {23, Forecast::Cloudy},
    {24, Forecast::Cloudy},
    {25, Forecast::Cloudy},
    {26, Forecast::Cloudy},
    {27, Forecast::MostlyCloudy},
    {28, Forecast::MostlyCloudy},
    {29, Forecast::PartlyCloudy},
    {30, Forecast::PartlyCloudy},
    {31, Forecast::Sunny},
    {32, Forecast::Sunny},
    {33, Forecast::MostlySunny},
    {34, Forecast::MostlySunny},
    {35, Forecast::Sleet},
    {36, Forecast::Sunny},
    {37, Forecast::Thunderstorm},
    {38, Forecast::Thunderstorm},
    {39, Forecast::Thunderstorm},
    {40, Forecast::Storm},
    {41, Forecast::Snow},
    {42, Forecast::Sleet},
    {43, Forecast::Snow},
    {44, Forecast::PartlyCloudy},
    {45, Forecast::Thunderstorm},
    {46, Forecast::Sleet},
    {47, Forecast::Thunderstorm}
};


Forecast::ForecastType ForecastData::type() const
{
    if (m_data) {
        for (int i = 0; i < ContitionTypeCount; ++i)
            if (ContitionType[i].id == m_data->condition().code())
                return ContitionType[i].type;
    }
    return Forecast::UnknownForecast;
}

bool ForecastData::night() const
{
    if (!m_data)
        return false;
    return m_data->condition().date().time() < m_data->astronomy().sunrise()
        || m_data->condition().date().time() > m_data->astronomy().sunset();
}