1e9297d28Sopenharmony_ci/*
2e9297d28Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3e9297d28Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e9297d28Sopenharmony_ci * you may not use this file except in compliance with the License.
5e9297d28Sopenharmony_ci * You may obtain a copy of the License at
6e9297d28Sopenharmony_ci *
7e9297d28Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e9297d28Sopenharmony_ci *
9e9297d28Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e9297d28Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e9297d28Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e9297d28Sopenharmony_ci * See the License for the specific language governing permissions and
13e9297d28Sopenharmony_ci * limitations under the License.
14e9297d28Sopenharmony_ci */
15e9297d28Sopenharmony_ci
16e9297d28Sopenharmony_ci#include "texgine/utils/exlog.h"
17e9297d28Sopenharmony_ci
18e9297d28Sopenharmony_ci#include <chrono>
19e9297d28Sopenharmony_ci#include <ctime>
20e9297d28Sopenharmony_ci#include <iomanip>
21e9297d28Sopenharmony_ci
22e9297d28Sopenharmony_cinamespace OHOS {
23e9297d28Sopenharmony_cinamespace Rosen {
24e9297d28Sopenharmony_cinamespace TextEngine {
25e9297d28Sopenharmony_civoid ExTime(Logger &algnlogger, enum Logger::LOG_PHASE phase)
26e9297d28Sopenharmony_ci{
27e9297d28Sopenharmony_ci    if (phase == Logger::LOG_PHASE::BEGIN) {
28e9297d28Sopenharmony_ci        auto timer = time(nullptr);
29e9297d28Sopenharmony_ci        auto now = localtime(&timer);
30e9297d28Sopenharmony_ci        if (now == nullptr) {
31e9297d28Sopenharmony_ci            return;
32e9297d28Sopenharmony_ci        }
33e9297d28Sopenharmony_ci        int64_t nowMs = std::chrono::duration_cast<std::chrono::milliseconds>(
34e9297d28Sopenharmony_ci                std::chrono::system_clock::now().time_since_epoch()).count() + (8 * 1000LL * 60 * 60);
35e9297d28Sopenharmony_ci        int year = static_cast<int>(now->tm_year) + 1900;
36e9297d28Sopenharmony_ci        int month = now->tm_mon + 1;
37e9297d28Sopenharmony_ci        int day = now->tm_mday;
38e9297d28Sopenharmony_ci        int hour = nowMs / (1000LL * 60 * 60) % 24;
39e9297d28Sopenharmony_ci        int minute = nowMs / (1000LL * 60) % 60;
40e9297d28Sopenharmony_ci        int second = nowMs / (1000LL) % 60;
41e9297d28Sopenharmony_ci        int milliseconds = nowMs % 1000;
42e9297d28Sopenharmony_ci        int longWidth = 4;
43e9297d28Sopenharmony_ci        int middleWidth = 3;
44e9297d28Sopenharmony_ci        int minWidth = 2;
45e9297d28Sopenharmony_ci        char fill = '0';
46e9297d28Sopenharmony_ci        algnlogger << std::setw(longWidth) << std::setfill(fill) << year
47e9297d28Sopenharmony_ci            << "/" << std::setw(minWidth) << std::setfill(fill) << month
48e9297d28Sopenharmony_ci            << "/" << std::setw(minWidth) << std::setfill(fill) << day
49e9297d28Sopenharmony_ci            << " " << std::setw(minWidth) << std::setfill(fill) << hour
50e9297d28Sopenharmony_ci            << ":" << std::setw(minWidth) << std::setfill(fill) << minute
51e9297d28Sopenharmony_ci            << ":" << std::setw(minWidth) << std::setfill(fill) << second
52e9297d28Sopenharmony_ci            << "." << std::setw(middleWidth) << std::setfill(fill) << milliseconds;
53e9297d28Sopenharmony_ci    }
54e9297d28Sopenharmony_ci
55e9297d28Sopenharmony_ci    if (algnlogger.GetLevel() != Logger::LOG_LEVEL::DEBUG) {
56e9297d28Sopenharmony_ci        Logger::OutputByStdout(algnlogger, phase);
57e9297d28Sopenharmony_ci    }
58e9297d28Sopenharmony_ci}
59e9297d28Sopenharmony_ci} // namespace TextEngine
60e9297d28Sopenharmony_ci} // namespace Rosen
61e9297d28Sopenharmony_ci} // namespace OHOS
62