Skip to content

Commit 09bf65e

Browse files
author
adrianbartyczak
committed
Add bash utility functions secondsToMicrosecondsDecimal and secondsToMicroseconds
1 parent 532721f commit 09bf65e

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

functions_scripts/scripting/bash/dateandtimeutils.bash

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,37 @@
99

1010
# Conversion
1111
# --------------------------------------------
12-
# Convert a time in seconds (using either an integer or decimal) to
13-
# millseconds as a decimal.
12+
# Convert seconds to milliseconds with decimal precision.
1413
# Usage:
1514
# secondsToMillisecondsDecimal <seconds>
1615
secondsToMillisecondsDecimal() {
1716
printf '%.4f' "$(bc <<< "${1}*1000")"
1817
}
1918

20-
# Convert a time in seconds (using either an integer or decimal) to
21-
# millseconds as an integer rounded to the nearest tenths place (using round
22-
# half towards zero mode).
19+
# Convert seconds to milliseconds.
2320
# Usage:
2421
# secondsToMilliseconds <seconds>
22+
# Notes:
23+
# The number is rounded to the nearest tenths place using half toward zero
24+
# rounding mode.
2525
secondsToMilliseconds() {
2626
printf '%.0f' "$(secondsToMillisecondsDecimal "${1}")"
2727
}
2828

29+
# Convert seconds to microseconds with decimal precision.
30+
# Usage:
31+
# secondsToMicrosecondsDecimal <seconds>
32+
secondsToMicrosecondsDecimal() {
33+
printf '%.4f' "$(bc <<< "${1}*1000000")"
34+
}
35+
36+
# Convert seconds to microseconds.
37+
# Usage:
38+
# secondsToMicroseconds <seconds>
39+
# Notes:
40+
# The number is rounded to the nearest tenths place using half toward zero
41+
# rounding mode.
42+
secondsToMicroseconds() {
43+
printf '%.0f' "$(secondsToMicrosecondsDecimal "${1}")"
44+
}
45+

0 commit comments

Comments
 (0)