~aleteoryx/muditaos

ref: 8c2b5aa7b08f1bbd6d8497e0df3860cfba790d86 muditaos/module-utils/time/test/unittest_dateCommon.cpp -rw-r--r-- 2.0 KiB
8c2b5aa7 — Dawid Wojtas [BH-1624] Fix shutdown procedure 2 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <catch2/catch.hpp>

#include <time/dateCommon.hpp>

TEST_CASE("Get date after given time")
{
    auto givenTime   = TimePointFromString("2022-11-11 11:00:00");
    auto timeBefore1 = TimePointFromString("2022-11-11 10:59:01");
    auto timeBefore2 = TimePointFromString("2022-11-05 10:59:01");
    auto timeBefore3 = TimePointFromString("2022-11-05 15:59:01");
    auto timeBefore4 = TimePointFromString("1999-01-05 10:59:01");

    auto timeAfter1 = TimePointFromString("2022-11-11 11:00:01");
    auto timeAfter2 = TimePointFromString("2022-11-12 11:00:01");
    auto timeAfter3 = TimePointFromString("2022-11-12 10:59:01");
    auto timeAfter4 = TimePointFromString("2222-11-12 11:59:01");

    SECTION("Time Before")
    {
        auto result = GetFollowingDayTime(givenTime, givenTime);
        REQUIRE(result == TimePointFromString("2022-11-12 11:00:00"));
        result = GetFollowingDayTime(timeBefore1, givenTime);
        REQUIRE(result == TimePointFromString("2022-11-12 10:59:01"));
        result = GetFollowingDayTime(timeBefore2, givenTime);
        REQUIRE(result == TimePointFromString("2022-11-12 10:59:01"));
        result = GetFollowingDayTime(timeBefore3, givenTime);
        REQUIRE(result == TimePointFromString("2022-11-11 15:59:01"));
        result = GetFollowingDayTime(timeBefore4, givenTime);
        REQUIRE(result == TimePointFromString("2022-11-12 10:59:01"));
    }

    SECTION("Time After")
    {
        auto result = GetFollowingDayTime(timeAfter1, givenTime);
        REQUIRE(result == timeAfter1);
        result = GetFollowingDayTime(timeAfter2, givenTime);
        REQUIRE(result == TimePointFromString("2022-11-11 11:00:01"));
        result = GetFollowingDayTime(timeAfter3, givenTime);
        REQUIRE(result == timeAfter3);
        result = GetFollowingDayTime(timeAfter4, givenTime);
        REQUIRE(result == TimePointFromString("2022-11-11 11:59:01"));
    }
}