• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 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 { AsyncCallback } from './basic';
17
18/**
19 * System time and timezone.
20 * @since 9
21 * @syscap SystemCapability.MiscServices.Time
22 */
23declare namespace systemDateTime {
24    /**
25     * Sets the system time.
26     * @param { number } time - Indicates the target timestamp(in milliseconds)
27     * @param { AsyncCallback<void> } callback - The callback of setTime
28     * @throws { BusinessError } 202 - Permission denied, Non system application use system APIs
29     * @throws { BusinessError } 401 - Invalid parameters
30     * @since 9
31     * @systemapi Hide this for inner system use
32     */
33    function setTime(time : number, callback : AsyncCallback<void>) : void;
34    /**
35     * Sets the system time.
36     * @param { number } time - Indicates the target timestamp(in milliseconds)
37     * @returns { Promise<void> } The promise returned by the function
38     * @throws { BusinessError } 202 - Permission denied, Non system application use system APIs
39     * @throws { BusinessError } 401 - Invalid parameters
40     * @since 9
41     * @systemapi Hide this for inner system use
42     */
43    function setTime(time : number) : Promise<void>;
44
45    /**
46     * Obtains the number of milliseconds that have elapsed since the Unix epoch.
47     * @param { boolean } isNano - True if the result is in nanoseconds. Otherswise in milliseconds
48     * @param { AsyncCallback<number> } callback - The callback of getCurrentTime
49     * @throws { BusinessError } 401 - Invalid parameters
50     * @since 9
51     */
52    function getCurrentTime(isNano: boolean, callback: AsyncCallback<number>): void;
53
54    /**
55     * Obtains the number of milliseconds that have elapsed since the Unix epoch.
56     * @param { AsyncCallback<number> } callback - The callback of getCurrentTime
57     * @throws { BusinessError } 401 - Invalid parameters
58     * @since 9
59     */
60    function getCurrentTime(callback: AsyncCallback<number>): void;
61
62    /**
63     * Obtains the number of milliseconds that have elapsed since the Unix epoch.
64     * @param { boolean } isNano - True if the result is in nanoseconds. Otherswise in milliseconds
65     * @throws { BusinessError } 401 - Invalid parameters
66     * @returns { Promise<number> } The promise returned by the function
67     * @since 9
68     */
69    function getCurrentTime(isNano?: boolean): Promise<number>;
70
71    /**
72     * Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
73     * @param { boolean } isNano - True if the result is in nanoseconds. Otherswise in milliseconds
74     * @param { AsyncCallback<number> } callback - The callback of getRealActiveTime
75     * @throws { BusinessError } 401 - Invalid parameters
76     * @since 9
77     */
78    function getRealActiveTime(isNano: boolean, callback: AsyncCallback<number>): void;
79
80    /**
81     * Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
82     * @param { AsyncCallback<number> } callback - The callback of getRealActiveTime
83     * @throws { BusinessError } 401 - Invalid parameters
84     * @since 9
85     */
86    function getRealActiveTime(callback: AsyncCallback<number>): void;
87
88    /**
89     * Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time.
90     * @param { boolean } [isNano] - True if the result is in nanoseconds. Otherswise in milliseconds
91     * @returns { Promise<number> } The promise returned by the function
92     * @throws { BusinessError } 401 - Invalid parameters
93     * @since 9
94     */
95    function getRealActiveTime(isNano?: boolean): Promise<number>;
96
97    /**
98     * Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time.
99     * @param { boolean } isNano - True if the result is in nanoseconds. Otherswise in milliseconds
100     * @param { AsyncCallback<number> } callback - The callback of getRealTime
101     * @throws { BusinessError } 401 - Invalid parameters
102     * @since 9
103     */
104    function getRealTime(isNano: boolean, callback: AsyncCallback<number>): void;
105
106    /**
107     * Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time.
108     * @param { AsyncCallback<number> } callback - The callback of getRealTime
109     * @throws { BusinessError } 401 - Invalid parameters
110     * @since 9
111     */
112    function getRealTime(callback: AsyncCallback<number>): void;
113
114    /**
115     * Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time.
116     * @param { boolean } [isNano] - True if the result is in nanoseconds. Otherswise in milliseconds
117     * @returns { Promise<number> } The promise returned by the function
118     * @throws { BusinessError } 401 - Invalid parameters
119     * @since 9
120     */
121    function getRealTime(isNano?: boolean): Promise<number>;
122
123    /**
124     * Sets the system time.
125     * @param { Date } date - The target date
126     * @param { AsyncCallback<void> } callback - The callback of setDate
127     * @throws { BusinessError } 202 - Permission denied, Non system application use system APIs
128     * @throws { BusinessError } 401 - Invalid parameters
129     * @since 9
130     * @systemapi Hide this for inner system use
131     */
132    function setDate(date: Date, callback: AsyncCallback<void>): void;
133
134    /**
135     * Sets the system time.
136     * @param { Date } date - The target date
137     * @returns { Promise<void> } The promise returned by the function
138     * @throws { BusinessError } 202 - Permission denied, Non system application use system APIs
139     * @throws { BusinessError } 401 - Invalid parameters
140     * @since 9
141     * @systemapi Hide this for inner system use
142     */
143    function setDate(date: Date): Promise<void>;
144
145    /**
146     * Obtains the system date.
147     * @param { AsyncCallback<Date> } callback - The callback of getDate
148     * @throws { BusinessError } 401 - Invalid parameters
149     * @since 9
150     */
151    function getDate(callback: AsyncCallback<Date>): void;
152
153    /**
154     * Obtains the system date.
155     * @returns { Promise<Date> } The promise returned by the function
156     * @throws { BusinessError } 401 - Invalid parameters
157     * @since 9
158     */
159    function getDate(): Promise<Date>;
160
161    /**
162     * Sets the system time zone.
163     * @param { string } timezone - The system time zone
164     * @param { AsyncCallback<void> } callback - The callback of setTimezone
165     * @throws { BusinessError } 202 - Permission denied, Non system application use system APIs
166     * @throws { BusinessError } 401 - Invalid parameters
167     * @since 9
168     * @systemapi Hide this for inner system use
169     */
170    function setTimezone(timezone: string, callback: AsyncCallback<void>): void;
171
172    /**
173     * Sets the system time zone.
174     * @param { string } timezone -  The system time zone
175     * @returns { Promise<void> } The promise returned by the function
176     * @throws { BusinessError } 202 - Permission denied, Non system application use system APIs
177     * @throws { BusinessError } 401 - Invalid parameters
178     * @since 9
179     * @systemapi Hide this for inner system use
180     */
181    function setTimezone(timezone: string): Promise<void>;
182
183    /**
184     * Obtains the system time zone.
185     * @param { AsyncCallback<string> } callback - The callback of getTimezone
186     * @throws { BusinessError } 401 - Invalid parameters
187     * @since 9
188     */
189    function getTimezone(callback: AsyncCallback<string>): void;
190
191    /**
192     * Obtains the system time zone.
193     * @returns { Promise<string> } The promise returned by the function
194     * @throws { BusinessError } 401 - Invalid parameters
195     * @since 9
196     */
197    function getTimezone(): Promise<string>;
198}
199
200export default systemDateTime;