~aleteoryx/muditaos

cfe88321a8ecc1959e0f2c85b44eb6934ecc2f83 — Lukasz Mastalerz 2 years ago eaedd79
[MOS-192] Time should not include 0 at the beginning

Fix for displaying an additional 0 at the begging of the clock.
It affects the clock in the status bar and messages and calls time.
M module-utils/time/test/unittest_time.cpp => module-utils/time/test/unittest_time.cpp +4 -4
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <cstring>


@@ 34,9 34,9 @@ class TimeSettings : public TimeSettingsInterface
    }
};

const std::regex reg12h("^(0[0-9]|1[0-2]):[0-5][0-9] (A|P)M$");
const std::regex reg12hShort("^(0[0-9]|1[0-2]):[0-5][0-9]$");
const std::regex reg24h("^([0-1][0-9]|2[0-4]):[0-5][0-9]$");
const std::regex reg12h("^(00|[1-9]|1[0-2]):[0-5][0-9] (A|P)M$");
const std::regex reg12hShort("^(00|[1-9]|1[0-2]):[0-5][0-9]$");
const std::regex reg24h("^(00|[1-9]|1[0-9]|2[0-4]):[0-5][0-9]$");
const std::regex regexDDMMYYYY("^([0-2]\\d|3[0-1])\\.(0[1-9]|1[0-2])\\.\\d{4}$");
const std::regex regexDDMM("^([0-2]\\d|3[0-1])\\.(0[1-9]|1[0-2])$");
const std::regex regexMMDDYYYY("^(0[1-9]|1[0-2])\\.([0-2]\\d|3[0-1])\\.\\d{4}$");

M module-utils/time/time/time_conversion.cpp => module-utils/time/time/time_conversion.cpp +15 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "time_conversion.hpp"


@@ 14,6 14,7 @@
#include <ctime>
#include <iomanip>
#include <locale>
#include <charconv>
#include "i18n/i18n.hpp"

#include "time_locale.hpp"


@@ 52,6 53,18 @@ namespace utils::time
            {Duration::DisplayedFormat::FixedH0M0S, {durationFormatH0M0S, durationFormatH0M0S}},
            {Duration::DisplayedFormat::AutoM, {durationFormatM0S, durationFormatH0M0S}},
            {Duration::DisplayedFormat::Auto0M, {durationFormat0M0S, durationFormatH0M0S}}};

        std::string removeLeadingZeroFromHoursIfNeeded(const char *time)
        {
            auto hours_colon_position = std::string(time).find(":");
            if (hours_colon_position == std::string::npos) {
                return std::string(time);
            }
            uint32_t hour            = 99;
            uint32_t max_hour_length = 2;
            std::from_chars(time + hours_colon_position - max_hour_length, time + hours_colon_position, hour);
            return (hour != 0 and hour <= 9) ? std::string(time + 1) : std::string(time);
        };
    } // namespace

    Locale tlocale;


@@ 95,7 108,7 @@ namespace utils::time
        utils::findAndReplaceAll(fmt, specifiers_replacement, replaceFunc);
        auto data = std::unique_ptr<char[]>(new char[datasize]);
        if (std::strftime(data.get(), datasize, fmt.c_str(), timeInfo) != 0) {
            datetimestr = UTF8(data.get());
            datetimestr = UTF8(removeLeadingZeroFromHoursIfNeeded(data.get()));
        }
        return datetimestr;
    }

M pure_changelog.md => pure_changelog.md +1 -0
@@ 58,6 58,7 @@
* Fixed inability to import contacts from Orange SIM cards
* Fixed improper asterisk button behavior when adding new contact
* Fixed for contacts removed and imported from SIM card once again were added to database without names 
* Fixed (removed) redundant leading zero from time representation unless exactly midnight

## [1.5.0 2022-12-20]