diff --git a/api/@ohos.systemTime.d.ts b/api/@ohos.systemTime.d.ts index ef8856074dcafb4a0be901e19ee73cccc5492e30..19cc598d7b8aaf5c0501dead57506a9895b84da3 100755 --- a/api/@ohos.systemTime.d.ts +++ b/api/@ohos.systemTime.d.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import { AsyncCallback, ErrorCallback } from './basic'; +import {AsyncCallback, ErrorCallback} from './basic'; /** * System time and timezone. @@ -24,67 +24,193 @@ import { AsyncCallback, ErrorCallback } from './basic'; declare namespace systemTime { /** * Sets the system time. + * * @permission ohos.permission.SET_TIME - * @param time Target time stamp (ms) + * @param {number} time - Target time stamp (ms) + * @param {AsyncCallback} callback - The callback function. + * @throws {BusinessError} 201 - if forbidden by permission: ohos.permission.SET_TIME. + * @throws {BusinessError} 401 - if the parameter type is incorrect. * @since 7 */ - function setTime(time : number, callback : AsyncCallback) : void; - function setTime(time : number) : Promise; + function setTime(time: number, callback: AsyncCallback): void; + + /** + * Sets the system time. + * + * @permission ohos.permission.SET_TIME + * @param {number} time - Target time stamp (ms) + * @returns {Promise} the promise object. + * @throws {BusinessError} 201 - if forbidden by permission: ohos.permission.SET_TIME. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @since 7 + */ + function setTime(time: number): Promise; /** * Obtains the number of milliseconds that have elapsed since the Unix epoch. + * + * @param {boolean} isNano - return in nanoseconds if true, otherwise in milliseconds + * @param {AsyncCallback} callback - the number of time. + * @throws {BusinessError} 401 - if the parameter type is incorrect. * @since 8 */ function getCurrentTime(isNano: boolean, callback: AsyncCallback): void; + + /** + * Obtains the number of milliseconds that have elapsed since the Unix epoch. + * + * @param {AsyncCallback} callback - the number of milliseconds. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @since 8 + */ function getCurrentTime(callback: AsyncCallback): void; + + /** + * Obtains the number of milliseconds that have elapsed since the Unix epoch. + * + * @param {boolean} isNano - return in nanoseconds if true, otherwise in milliseconds + * @returns {Promise} the number of time. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @since 8 + */ function getCurrentTime(isNano?: boolean): Promise; /** * Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * + * @param {boolean} isNano - return in nanoseconds if true, otherwise in milliseconds + * @param {AsyncCallback} callback - the number of time. + * @throws {BusinessError} 401 - if the parameter type is incorrect. * @since 8 */ function getRealActiveTime(isNano: boolean, callback: AsyncCallback): void; + + /** + * Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * + * @param {AsyncCallback} callback - the number of milliseconds. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @since 8 + */ function getRealActiveTime(callback: AsyncCallback): void; + + /** + * Obtains the number of milliseconds elapsed since the system was booted, not including deep sleep time. + * + * @param {boolean} isNano - return in nanoseconds if true, otherwise in milliseconds. + * @returns {Promise} the number of time. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @since 8 + */ function getRealActiveTime(isNano?: boolean): Promise; /** * Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time. + * + * @param {boolean} isNano - return in nanoseconds if true, otherwise in milliseconds + * @param {AsyncCallback} callback - the number of time. + * @throws {BusinessError} 401 - if the parameter type is incorrect. * @since 8 */ function getRealTime(isNano: boolean, callback: AsyncCallback): void; + + /** + * Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time. + * + * @param {AsyncCallback} callback - the number of milliseconds. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @since 8 + */ function getRealTime(callback: AsyncCallback): void; + + /** + * Obtains the number of milliseconds elapsed since the system was booted, including deep sleep time. + * + * @param {boolean} isNano - return in nanoseconds if true, otherwise in milliseconds + * @returns {Promise} the number of time. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @since 8 + */ function getRealTime(isNano?: boolean): Promise; /** * Sets the system time. + * * @permission ohos.permission.SET_TIME - * @param date The target date + * @param {Date} date - The target date. + * @param {AsyncCallback} callback - the callback function. + * @throws {BusinessError} 201 - if forbidden by permission: ohos.permission.SET_TIME. + * @throws {BusinessError} 401 - if the parameter type is incorrect. * @since 7 */ function setDate(date: Date, callback: AsyncCallback): void; + + /** + * Sets the system time. + * + * @permission ohos.permission.SET_TIME + * @param {Date} date - The target date. + * @returns {Promise} the promise object. + * @throws {BusinessError} 201 - if forbidden by permission: ohos.permission.SET_TIME. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @since 7 + */ function setDate(date: Date): Promise; /** * Obtains the system date. + * + * @param {AsyncCallback} callback - the system date. * @since 8 */ function getDate(callback: AsyncCallback): void; + + /** + * Obtains the system date. + * + * @returns {Promise} the system date. + * @since 8 + */ function getDate(): Promise; /** * Sets the system time zone. + * * @permission ohos.permission.SET_TIME_ZONE - * @param timezone The system time zone + * @param {string} timezone - The system time zone. + * @param {AsyncCallback} callback - the callback function. + * @throws {BusinessError} 201 - if forbidden by permission: ohos.permission.SET_TIME_ZONE. + * @throws {BusinessError} 401 - if the parameter type is incorrect. * @since 7 */ function setTimezone(timezone: string, callback: AsyncCallback): void; + + /** + * Sets the system time zone. + * + * @permission ohos.permission.SET_TIME_ZONE + * @param {string} timezone - The system time zone. + * @returns {Promise} the promise object. + * @throws {BusinessError} 201 - if forbidden by permission: ohos.permission.SET_TIME_ZONE. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @since 7 + */ function setTimezone(timezone: string): Promise; - /** + /** * Obtains the system time zone. + * + * @param {AsyncCallback} callback - the system time zone. * @since 8 - */ + */ function getTimezone(callback: AsyncCallback): void; + + /** + * Obtains the system time zone. + * + * @returns {Promise} the system time zone. + * @since 8 + */ function getTimezone(): Promise; } diff --git a/api/@ohos.systemTimer.d.ts b/api/@ohos.systemTimer.d.ts index 023a3f26442f2feb2affe150f08cab29fb9b2cde..3a844fb3f054885380ac8f0c36c904788c03ed5f 100644 --- a/api/@ohos.systemTimer.d.ts +++ b/api/@ohos.systemTimer.d.ts @@ -13,102 +13,213 @@ * limitations under the License. */ -import { AsyncCallback, ErrorCallback } from './basic'; -import { WantAgent } from './@ohos.wantAgent'; +import {AsyncCallback, ErrorCallback} from './basic'; +import {WantAgent} from './@ohos.wantAgent'; /** * Provides js api for systemTimer * - * @since 7 * @syscap SystemCapability.MiscServices.Time * @systemapi Hide this for inner system use. + * @since 7 */ declare namespace systemTimer { - /** - * Indicates the timing policy the timer use, which can be REALTIME or UTC. - */ - const TIMER_TYPE_REALTIME: number; - - /** - * Describes whether a timer will wake the device up. - */ - const TIMER_TYPE_WAKEUP: number; - - /** - * Describes whether a timer will be delivered precisely at a scheduled time. - */ - const TIMER_TYPE_EXACT: number; - - /** - * Indicates whether the timer waking up the system is supported in low-power mode. - */ - const TIMER_TYPE_IDLE: number; - - /** - * Creates a timer. - * @Param options Indicates the timer options. - * @Return timer ID. - */ - function createTimer(options: TimerOptions, callback: AsyncCallback): void; - function createTimer(options: TimerOptions): Promise; - - /** - * Starts a timer. - * - * @Param timer The timer ID. - * @Param triggerTime Indicates the time at which the timer is triggered for the first time, in milliseconds. - * The time will be automatically set to 5000 milliseconds after the current time if the passed - * value is smaller than the current time plus 5000 milliseconds. - */ - function startTimer(timer: number, triggerTime: number, callback: AsyncCallback): void; - function startTimer(timer: number, triggerTime: number): Promise; - - /** - * Stops a timer. - * @Param timer The timer ID. - */ - function stopTimer(timer: number, callback: AsyncCallback): void; - function stopTimer(timer: number): Promise; - - /** - * Destroy a timer. - * @Param timer The timer ID. - */ - function destroyTimer(timer: number, callback: AsyncCallback): void; - function destroyTimer(timer: number): Promise; + /** + * Indicates the timing policy the timer use, which can be REALTIME or UTC. + * + * @syscap SystemCapability.MiscServices.Time + * @systemapi Hide this for inner system use. + * @since 7 + */ + const TIMER_TYPE_REALTIME: number; /** - * When the repeat is false,the interval is not needed, choose one of wantAgent and callback. - * When the repeat is true,the interval is required, the wantAgent is required, and the callback can be left blank. + * Describes whether a timer will wake the device up. + * + * @syscap SystemCapability.MiscServices.Time + * @systemapi Hide this for inner system use. + * @since 7 + */ + const TIMER_TYPE_WAKEUP: number; + + /** + * Describes whether a timer will be delivered precisely at a scheduled time. * + * @syscap SystemCapability.MiscServices.Time + * @systemapi Hide this for inner system use. + * @since 7 */ - interface TimerOptions { + const TIMER_TYPE_EXACT: number; + /** - * timer type. + * Indicates whether the timer waking up the system is supported in low-power mode. + * + * @syscap SystemCapability.MiscServices.Time + * @systemapi Hide this for inner system use. + * @since 7 */ - type: number; + const TIMER_TYPE_IDLE: number; /** - * Indicates a repeating timer + * Creates a timer. + * + * @syscap SystemCapability.MiscServices.Time + * @Param options Indicates the timer options. + * @param {TimerOptions} options - The necessary configuration information. + * @param {AsyncCallback} callback - {number} is the timer ID. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @systemapi Hide this for inner system use. + * @since 7 */ - repeat: boolean; + function createTimer(options: TimerOptions, callback: AsyncCallback): void; /** - * Indicates the interval between two consecutive triggers, in milliseconds. - * The interval will be set to 5000 milliseconds automatically if the passed value is smaller than 5000. + * Creates a timer. + * + * @syscap SystemCapability.MiscServices.Time + * @Param options Indicates the timer options. + * @Return timer ID. + * @param {TimerOptions} options - The necessary configuration information. + * @returns {Promise} the timer ID. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @systemapi Hide this for inner system use. + * @since 7 */ - interval?: number; + function createTimer(options: TimerOptions): Promise; /** - * Indicates the intent to send when the timer goes off. + * Starts a timer. + * + * @syscap SystemCapability.MiscServices.Time + * @Param {number} timer - The timer ID. + * @Param {number} triggerTime - Indicates the time at which the timer is triggered for the first time, in milliseconds. + * The time will be automatically set to 5000 milliseconds after the current time if the passed + * value is smaller than the current time plus 5000 milliseconds. + * @Param {AsyncCallback} callback - The callback function. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @systemapi Hide this for inner system use. + * @since 7 */ - wantAgent?: WantAgent; + function startTimer(timer: number, triggerTime: number, callback: AsyncCallback): void; /** - * Called back when the timer goes off. + * Starts a timer. + * + * @syscap SystemCapability.MiscServices.Time + * @Param {number} timer - The timer ID. + * @Param {number} triggerTime - Indicates the time at which the timer is triggered for the first time, in milliseconds. + * The time will be automatically set to 5000 milliseconds after the current time if the passed + * value is smaller than the current time plus 5000 milliseconds. + * @returns {Promise} return a promise object. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @systemapi Hide this for inner system use. + * @since 7 */ - callback?: () => void; - } + function startTimer(timer: number, triggerTime: number): Promise; + + /** + * Stops a timer. + * + * @syscap SystemCapability.MiscServices.Time + * @Param {number} timer - The timer ID. + * @Param {AsyncCallback} callback - The callback function. + * @throws throws {BusinessError} 401 - if the parameter type is incorrect. + * @systemapi Hide this for inner system use. + * @since 7 + */ + function stopTimer(timer: number, callback: AsyncCallback): void; + + /** + * Stops a timer. + * + * @syscap SystemCapability.MiscServices.Time + * @Param {number} timer - The timer ID. + * @returns {Promise} return a promise object. + * @throws throws {BusinessError} 401 - if the parameter type is incorrect. + * @systemapi Hide this for inner system use. + * @since 7 + */ + function stopTimer(timer: number): Promise; + + /** + * Destroy a timer. + * + * @syscap SystemCapability.MiscServices.Time + * @Param {number} timer - The timer ID. + * @Param {AsyncCallback} callback - The callback function. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @systemapi Hide this for inner system use. + * @since 7 + */ + function destroyTimer(timer: number, callback: AsyncCallback): void; + + /** + * Destroy a timer. + * + * @syscap SystemCapability.MiscServices.Time + * @Param {number} timer - The timer ID. + * @returns {Promise} return a promise object. + * @throws {BusinessError} 401 - if the parameter type is incorrect. + * @systemapi Hide this for inner system use. + * @since 7 + */ + function destroyTimer(timer: number): Promise; + + /** + * When the repeat is false,the interval is not needed, choose one of wantAgent and callback. + * When the repeat is true,the interval is required, the wantAgent is required, and the callback can be left blank. + * + * @syscap SystemCapability.MiscServices.Time + * @systemapi Hide this for inner system use. + * @since 7 + */ + interface TimerOptions { + /** + * The timer type. + * + * @syscap SystemCapability.MiscServices.Time + * @systemapi Hide this for inner system use. + * @since 7 + */ + type: number; + + /** + * Indicates a repeating timer + * + * @syscap SystemCapability.MiscServices.Time + * @systemapi Hide this for inner system use. + * @since 7 + */ + repeat: boolean; + + /** + * Indicates the interval between two consecutive triggers, in milliseconds. + * The interval will be set to 5000 milliseconds automatically if the passed value is smaller than 5000. + * + * @syscap SystemCapability.MiscServices.Time + * @systemapi Hide this for inner system use. + * @since 7 + */ + interval?: number; + + /** + * Indicates the intent to send when the timer goes off. + * + * @syscap SystemCapability.MiscServices.Time + * @systemapi Hide this for inner system use. + * @since 7 + */ + wantAgent?: WantAgent; + + /** + * Called back when the timer goes off. + * + * @syscap SystemCapability.MiscServices.Time + * @systemapi Hide this for inner system use. + * @since 7 + */ + callback?: () => void; + } } export default systemTimer; \ No newline at end of file