1/**
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import common from '@ohos.app.ability.common';
17
18export class TimeUtils {
19  getFreezingTimeNm(freezingMillisecond: number, context: common.ExtensionContext): string {
20    const HOUR_NM = context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_hour').id);
21    const MINUTE_NM = context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_minutes').id);
22    const SECOND_NM = context?.resourceManager?.getStringSync($r('app.string.unified_authwidget_seconds').id);
23    const ONE_MINUTE = 60;
24    const RATE = 1000;
25    let minute = Math.floor(freezingMillisecond / (ONE_MINUTE * RATE));
26    let second = Math.round((freezingMillisecond % (ONE_MINUTE * RATE)) / RATE);
27    let timeName = '';
28    if (minute > 1) {
29      let hour = minute / ONE_MINUTE;
30      let minutes = minute % ONE_MINUTE + 1;
31      if (hour > 1) {
32        timeName += hour + HOUR_NM;
33      } else {
34        timeName += minutes + MINUTE_NM;
35      }
36    } else {
37      timeName += second + SECOND_NM;
38    }
39    return timeName;
40  }
41}
42
43let mTimeUtils = new TimeUtils();
44
45export default mTimeUtils as TimeUtils;
46