~aleteoryx/muditaos

ref: 798a2fb45afee614205ae8d8f7680dc678e251da muditaos/module-apps/application-calendar/models/MonthModel.hpp -rw-r--r-- 2.1 KiB
798a2fb4 — Mateusz Grzegorzek [BH-361] Move date to separate directory 4 years ago
                                                                                
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
79
80
81
82
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "windows/AppWindow.hpp"
#include "Application.hpp"
#include <gui/widgets/GridLayout.hpp>
#include <gui/widgets/Item.hpp>
#include <Text.hpp>
#include <date/date.h>
#include <map>
#include <string>
#include <vector>
#include <module-apps/application-calendar/data/dateCommon.hpp>
#include <module-db/Interface/EventsRecord.hpp>

class YearMonth
{
    date::year year;
    date::month month;

  public:
    YearMonth() = default;
    explicit YearMonth(date::year_month_day ymd) : year{ymd.year()}, month{ymd.month()} {};

    bool operator>(const YearMonth &other) const noexcept
    {
        if (this->year != other.year) {
            return this->year > other.year;
        }
        else {
            return this->month > other.month;
        }
    };

    bool operator==(const YearMonth &other) const noexcept
    {
        return this->month == other.month && this->year == other.year;
    };

    bool operator!=(const YearMonth &other)
    {
        return !(*this == other);
    };

    bool operator<(const YearMonth &other)
    {
        return !(*this > other) && (*this != other);
    };
};

class MonthModel
{
  private:
    YearMonth yearMonth;

    [[nodiscard]] date::year_month_day getYearMonthDayFromTimePoint(TimePoint timePoint) const;
    [[nodiscard]] uint32_t getEventDurationInDays(const EventsRecord &records) const;
    [[nodiscard]] uint32_t getDayIndex(TimePoint date) const;

  public:
    explicit MonthModel(date::year_month_day yearMonthDay);
    MonthModel()          = default;
    virtual ~MonthModel() = default;

    void markEventsInDays(const std::vector<EventsRecord> &records, std::array<bool, 31> &isDayEmpty);

    date::year getYear();
    date::month getMonth();
    uint32_t getLastDay();
    uint32_t getFirstWeekOffset();
    std::string getMonthYearText();
    std::string getMonthText();
    std::vector<std::string> split(const std::string &s, char delim);

    date::month month;
    uint32_t lastDay;
    // first week offset
    uint32_t firstWeekDayNumb;
    date::year year;
};