Title: | 'hms' Based Timer |
---|---|
Description: | Tracks elapsed clock time using a `hms::hms()` scalar, which if running has an attribute named start that specifies the system time when the timer was started. The elapsed time is the value of the scalar plus the difference between the current system time and the system time when the timer was started. |
Authors: | Joe Thorley [aut, cre]
|
Maintainer: | Joe Thorley <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.1 |
Built: | 2024-06-20 04:30:20 UTC |
Source: | https://github.com/cran/hmstimer |
A hms Timer is a hms::hms()
scalar which if
running has an attribute named start
that specifies the system time when the timer was started.
The elapsed time is the value of the scalar plus the difference between the current system time and the system time when the timer was started.
str(tmr_timer()) str(tmr_timer(1.5, start = TRUE)) x <- tmr_timer(1, start = TRUE) print(x) Sys.sleep(0.1) print(x) print(tmr_elapsed(x)) print(x)
str(tmr_timer()) str(tmr_timer(1.5, start = TRUE)) x <- tmr_timer(1, start = TRUE) print(x) Sys.sleep(0.1) print(x) print(tmr_elapsed(x)) print(x)
Rounds a hms_timer()
up to the nearest second.
tmr_ceiling(x)
tmr_ceiling(x)
x |
A |
A hms_timer()
.
Other round:
tmr_floor()
,
tmr_format()
,
tmr_round()
tmr_ceiling(tmr_timer(18.9)) tmr_ceiling(tmr_timer(122.1))
tmr_ceiling(tmr_timer(18.9)) tmr_ceiling(tmr_timer(122.1))
Returns the elapsed time for a hms_timer()
as a hms_timer()
.
tmr_elapsed(x)
tmr_elapsed(x)
x |
A |
The elapsed time is the value of the scalar plus the difference between the current system time and the system time when the timer was started.
If the original hms_timer()
was running then the new hms_timer()
is assigned an attribute named start of the current system time.
A hms_timer()
of the elapsed time.
Other start_stop:
tmr_is_started()
,
tmr_is_stopped()
,
tmr_print()
,
tmr_reset()
,
tmr_start()
,
tmr_stop()
,
tmr_timer()
tmr <- tmr_start(tmr_timer()) print(tmr_elapsed(tmr)) Sys.sleep(0.01) print(tmr_elapsed(tmr)) tmr <- tmr_stop(tmr) print(tmr_elapsed(tmr)) Sys.sleep(0.01) print(tmr_elapsed(tmr))
tmr <- tmr_start(tmr_timer()) print(tmr_elapsed(tmr)) Sys.sleep(0.01) print(tmr_elapsed(tmr)) tmr <- tmr_stop(tmr) print(tmr_elapsed(tmr)) Sys.sleep(0.01) print(tmr_elapsed(tmr))
Rounds a hms_timer()
down to the nearest second.
tmr_floor(x)
tmr_floor(x)
x |
A |
A hms_timer()
.
Other round:
tmr_ceiling()
,
tmr_format()
,
tmr_round()
tmr_floor(tmr_timer(18.9)) tmr_floor(tmr_timer(122.1))
tmr_floor(tmr_timer(18.9)) tmr_floor(tmr_timer(122.1))
Converts a hms_timer()
to a string of the clock time
after rounding it to the number of digits.
tmr_format(x, digits = 3)
tmr_format(x, digits = 3)
x |
A |
digits |
A whole number of the number of decimal places. |
Negative values of digit are not permitted.
A character string.
Other round:
tmr_ceiling()
,
tmr_floor()
,
tmr_round()
tmr_format(tmr_timer(61.66)) tmr_format(tmr_timer(61.66), digits = 0)
tmr_format(tmr_timer(61.66)) tmr_format(tmr_timer(61.66), digits = 0)
Tests if a hms_timer()
is started (as indicated by the
presence of an attribute named start).
tmr_is_started(x)
tmr_is_started(x)
x |
A |
A flag (TRUE or FALSE).
Other start_stop:
tmr_elapsed()
,
tmr_is_stopped()
,
tmr_print()
,
tmr_reset()
,
tmr_start()
,
tmr_stop()
,
tmr_timer()
tmr <- tmr_timer(start = TRUE) print(tmr_is_started(tmr)) tmr <- tmr_stop(tmr) print(tmr_is_started(tmr))
tmr <- tmr_timer(start = TRUE) print(tmr_is_started(tmr)) tmr <- tmr_stop(tmr) print(tmr_is_started(tmr))
Tests if a hms_timer()
is stopped (as indicated by the
absence of an attribute named start).
tmr_is_stopped(x)
tmr_is_stopped(x)
x |
A |
A flag.
Other start_stop:
tmr_elapsed()
,
tmr_is_started()
,
tmr_print()
,
tmr_reset()
,
tmr_start()
,
tmr_stop()
,
tmr_timer()
tmr <- tmr_timer(start = TRUE) print(tmr_is_stopped(tmr)) tmr <- tmr_stop(tmr) print(tmr_is_stopped(tmr))
tmr <- tmr_timer(start = TRUE) print(tmr_is_stopped(tmr)) tmr <- tmr_stop(tmr) print(tmr_is_stopped(tmr))
Returns the elapsed time for a hms_timer()
from the system time when the
timer was started and the current system time as an hms time.
tmr_print(x)
tmr_print(x)
x |
A |
The elapsed time is the value of the scalar plus the difference between the current system time and the system time when the timer was started.
A character string.
Other start_stop:
tmr_elapsed()
,
tmr_is_started()
,
tmr_is_stopped()
,
tmr_reset()
,
tmr_start()
,
tmr_stop()
,
tmr_timer()
x <- tmr_start(tmr_timer()) tmr_print(x)
x <- tmr_start(tmr_timer()) tmr_print(x)
Resets a hms_timer()
by creating a new one.
tmr_reset(x, seconds = 0)
tmr_reset(x, seconds = 0)
x |
A |
seconds |
A non-negative numeric scalar of the initial number of seconds. |
A hms_timer()
.
Other start_stop:
tmr_elapsed()
,
tmr_is_started()
,
tmr_is_stopped()
,
tmr_print()
,
tmr_start()
,
tmr_stop()
,
tmr_timer()
tmr <- tmr_timer(10) print(tmr) tmr_reset(tmr)
tmr <- tmr_timer(10) print(tmr) tmr_reset(tmr)
Rounds a hms_timer()
after updating it to the elapsed time.
tmr_round(x, digits = 0)
tmr_round(x, digits = 0)
x |
A |
digits |
A whole number of the number of decimal places. |
Negative values of digit are permitted.
A hms_timer()
.
Other round:
tmr_ceiling()
,
tmr_floor()
,
tmr_format()
tmr_round(tmr_timer(18.9)) tmr_round(tmr_timer(18.9), 1) tmr_round(tmr_timer(18.9), -1) tmr_round(tmr_timer(121), -2) # 121 is rounded to 100 seconds
tmr_round(tmr_timer(18.9)) tmr_round(tmr_timer(18.9), 1) tmr_round(tmr_timer(18.9), -1) tmr_round(tmr_timer(121), -2) # 121 is rounded to 100 seconds
Starts a hms_timer()
by adding an attribute named
start of the current system time.
tmr_start(x)
tmr_start(x)
x |
A |
If the hms_timer()
is already started, the function
simply issues a warning and returns the original object.
A started hms_timer()
.
Other start_stop:
tmr_elapsed()
,
tmr_is_started()
,
tmr_is_stopped()
,
tmr_print()
,
tmr_reset()
,
tmr_stop()
,
tmr_timer()
tmr <- tmr_start(tmr_timer()) print(tmr_elapsed(tmr)) Sys.sleep(0.01) print(tmr_elapsed(tmr))
tmr <- tmr_start(tmr_timer()) print(tmr_elapsed(tmr)) Sys.sleep(0.01) print(tmr_elapsed(tmr))
Stops a hms_timer()
after updating it to the elapsed time.
tmr_stop(x)
tmr_stop(x)
x |
A |
If the hms_timer()
is already stopped, the function
simply issues a warning and returns the original object.
A stopped hms_timer()
.
Other start_stop:
tmr_elapsed()
,
tmr_is_started()
,
tmr_is_stopped()
,
tmr_print()
,
tmr_reset()
,
tmr_start()
,
tmr_timer()
tmr <- tmr_stop(tmr_timer(start = TRUE)) print(tmr_elapsed(tmr)) Sys.sleep(0.01) print(tmr_elapsed(tmr))
tmr <- tmr_stop(tmr_timer(start = TRUE)) print(tmr_elapsed(tmr)) Sys.sleep(0.01) print(tmr_elapsed(tmr))
Creates a hms_timer()
.
tmr_timer(seconds = 0, start = FALSE)
tmr_timer(seconds = 0, start = FALSE)
seconds |
A non-negative numeric scalar of the initial number of seconds. |
start |
A flag indicating whether to start the timer. |
A hms_timer()
.
Other start_stop:
tmr_elapsed()
,
tmr_is_started()
,
tmr_is_stopped()
,
tmr_print()
,
tmr_reset()
,
tmr_start()
,
tmr_stop()
tmr <- tmr_timer() print(tmr) class(tmr)
tmr <- tmr_timer() print(tmr) class(tmr)